diff options
Diffstat (limited to 'common/object/src/path.rs')
| -rw-r--r-- | common/object/src/path.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/common/object/src/path.rs b/common/object/src/path.rs index 0751ff0..4779cd5 100644 --- a/common/object/src/path.rs +++ b/common/object/src/path.rs @@ -5,7 +5,7 @@ */ use crate::{Object, Tag, TypedTag}; -use std::{fmt::Display, marker::PhantomData}; +use std::{fmt::Display, marker::PhantomData, str::FromStr}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Path(pub Vec<Tag>); @@ -48,3 +48,19 @@ impl Display for Path { Ok(()) } } +impl FromStr for Path { + type Err = &'static str; + fn from_str(s: &str) -> Result<Self, Self::Err> { + Ok(Self( + s.split(".") + .map(|e| { + e.as_bytes() + .try_into() + .map_err(|_| "path component not 4 bytes") + .map(Tag::new) + }) + .collect::<Result<Vec<Tag>, &'static str>>()?, + )) + } +} + |