radicle: TypedId improvements

- Add `Serialize` implementation
- Add `is_identity` method

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2024-03-08 16:01:50 +00:00 committed by cloudhead
parent 2fe0cca6d9
commit 71d4cb0128
No known key found for this signature in database
1 changed files with 7 additions and 1 deletions

View File

@ -21,7 +21,7 @@ pub use radicle_cob::{
pub use radicle_cob::{create, get, git, list, remove, update}; pub use radicle_cob::{create, get, git, list, remove, update};
/// The exact identifier for a particular COB. /// The exact identifier for a particular COB.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize)]
pub struct TypedId { pub struct TypedId {
/// The identifier of the COB in the store. /// The identifier of the COB in the store.
pub id: ObjectId, pub id: ObjectId,
@ -51,6 +51,12 @@ impl TypedId {
self.type_name == *patch::TYPENAME self.type_name == *patch::TYPENAME
} }
/// Returns `true` is the [`TypedId::type_name`] is for an
/// [`identity::Identity`].
pub fn is_identity(&self) -> bool {
self.type_name == *identity::TYPENAME
}
/// Parse a [`crate::git::Namespaced`] refname into a [`TypedId`]. /// Parse a [`crate::git::Namespaced`] refname into a [`TypedId`].
/// ///
/// All namespaces are stripped before parsing the suffix for the /// All namespaces are stripped before parsing the suffix for the