From 71d4cb012880b091779a6d39ee073d8d7ea3eff3 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 8 Mar 2024 16:01:50 +0000 Subject: [PATCH] radicle: TypedId improvements - Add `Serialize` implementation - Add `is_identity` method Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle/src/cob.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/radicle/src/cob.rs b/radicle/src/cob.rs index c41497b4..97817664 100644 --- a/radicle/src/cob.rs +++ b/radicle/src/cob.rs @@ -21,7 +21,7 @@ pub use radicle_cob::{ pub use radicle_cob::{create, get, git, list, remove, update}; /// 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 { /// The identifier of the COB in the store. pub id: ObjectId, @@ -51,6 +51,12 @@ impl TypedId { 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`]. /// /// All namespaces are stripped before parsing the suffix for the