mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-30 03:21:12 +00:00
object_id: add fallible version of ObjectId::from_hex()
This commit is contained in:
parent
95d83cbfe5
commit
95ea352b0a
@ -42,8 +42,16 @@ macro_rules! impl_id_type {
|
|||||||
Self(bytes.to_vec())
|
Self(bytes.to_vec())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parses the given hex string into an ObjectId.
|
||||||
|
///
|
||||||
|
/// The given string is usually a literal, and must be valid.
|
||||||
pub fn from_hex(hex: &str) -> Self {
|
pub fn from_hex(hex: &str) -> Self {
|
||||||
Self(hex::decode(hex).unwrap())
|
Self::try_from_hex(hex).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses the given hex string into an ObjectId.
|
||||||
|
pub fn try_from_hex(hex: &str) -> Result<Self, hex::FromHexError> {
|
||||||
|
hex::decode(hex).map(Self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user