From 654f430ac2da6435c3cbf0014cf0f681211865ee Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 26 Nov 2025 19:06:15 -0800 Subject: Rust code is coming along. Do not use yet. I think there are going to be some big changes coming soon, including some big API changes. --- rust/src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index c54b694..a96454e 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -213,6 +213,36 @@ impl Value { matches!(self, Value::Null) } + pub fn get(&self, key: &str) -> Option<&Value> { + if let Value::Dictionary(d) = self { + d.get( key ) + } else { + None + } + } + + pub fn as_bool( &self ) -> Result { + if let Value::Boolean(d) = self { + Ok(*d) + } else { + Err(Error::new( + ErrorKind::InvalidData, + "as_bool called on non boolean value.", + )) + } + } + + pub fn as_byte_string( &self ) -> Result<&Vec,Error> { + if let Value::ByteString(d) = self { + Ok(&d) + } else { + Err(Error::new( + ErrorKind::InvalidData, + "as_byte_string called on non ByteString value.", + )) + } + } + pub fn write(&self, w: &mut W) -> Result<(), Error> { match self { Self::Integer(x) => { @@ -579,6 +609,12 @@ impl From> for Value { } } +impl From<&[u8]> for Value { + fn from(v: &[u8]) -> Self { + Value::ByteString( Vec::from(v) ) + } +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3