diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-02-19 23:11:18 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-02-19 23:11:18 +0100 |
| commit | 2b57e045de6f4a588f1aea58a5d616199dec4cfb (patch) | |
| tree | 9171e1b80004ea68bf4b06b5bac31f0c5a87c935 /common/object/src/path.rs | |
| parent | 768688e34073e7430d92293fb0a995c7dc24cdf5 (diff) | |
| download | jellything-2b57e045de6f4a588f1aea58a5d616199dec4cfb.tar jellything-2b57e045de6f4a588f1aea58a5d616199dec4cfb.tar.bz2 jellything-2b57e045de6f4a588f1aea58a5d616199dec4cfb.tar.zst | |
query parser
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>>()?, + )) + } +} + |