Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle-cob: Component conversions
Fintan Halpenny committed 3 years ago
commit 6b303bdc97ee3749413885fc6c49ca9a6e14becf
parent c829045b8dd3db49fa4b2732a04cd165d6bda2e3
2 files changed +20 -0
modified radicle-cob/src/object.rs
@@ -6,6 +6,7 @@
use std::{convert::TryFrom as _, fmt, str::FromStr};

use git_ext::Oid;
+
use git_ref_format::{Component, RefString};
use serde::{Deserialize, Serialize};
use thiserror::Error;

@@ -83,3 +84,12 @@ impl<'de> Deserialize<'de> for ObjectId {
        Ok(ObjectId(oid))
    }
}
+

+
impl From<&ObjectId> for Component<'_> {
+
    fn from(id: &ObjectId) -> Self {
+
        let refstr = RefString::try_from(id.0.to_string())
+
            .expect("collaborative object id's are valid ref strings");
+
        Component::from_refstring(refstr)
+
            .expect("collaborative object id's are valid refname components")
+
    }
+
}
modified radicle-cob/src/type_name.rs
@@ -5,6 +5,7 @@

use std::{fmt, str::FromStr};

+
use git_ref_format::{Component, RefString};
use serde::{Deserialize, Serialize};
use thiserror::Error;

@@ -53,6 +54,15 @@ impl FromStr for TypeName {
    }
}

+
impl From<&TypeName> for Component<'_> {
+
    fn from(name: &TypeName) -> Self {
+
        let refstr = RefString::try_from(name.0.to_string())
+
            .expect("collaborative object type names are valid ref strings");
+
        Component::from_refstring(refstr)
+
            .expect("collaborative object type names are valid refname components")
+
    }
+
}
+

#[cfg(test)]
mod test {
    use std::str::FromStr as _;