radicle-cob: Component conversions
`TypeName` and `ObjectId` are expected to be used in reference names. Add `From` conversions to `Component` for both of these types to make it easier for using them with `git-ref-format`. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
c829045b8d
commit
6b303bdc97
|
|
@ -6,6 +6,7 @@
|
||||||
use std::{convert::TryFrom as _, fmt, str::FromStr};
|
use std::{convert::TryFrom as _, fmt, str::FromStr};
|
||||||
|
|
||||||
use git_ext::Oid;
|
use git_ext::Oid;
|
||||||
|
use git_ref_format::{Component, RefString};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
@ -83,3 +84,12 @@ impl<'de> Deserialize<'de> for ObjectId {
|
||||||
Ok(ObjectId(oid))
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
use std::{fmt, str::FromStr};
|
use std::{fmt, str::FromStr};
|
||||||
|
|
||||||
|
use git_ref_format::{Component, RefString};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::str::FromStr as _;
|
use std::str::FromStr as _;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue