diff options
| author | Mike Buland <mike@xagasoft.com> | 2025-11-26 19:06:15 -0800 |
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2025-11-26 19:06:15 -0800 |
| commit | 654f430ac2da6435c3cbf0014cf0f681211865ee (patch) | |
| tree | 41e3156ea41f4314a052bbdc5eaeb2c20fb92dea /rust/src | |
| parent | 96d34cc09da69d7443fa05e3245f8b042f3cf24a (diff) | |
| download | libgats-654f430ac2da6435c3cbf0014cf0f681211865ee.tar.gz libgats-654f430ac2da6435c3cbf0014cf0f681211865ee.tar.bz2 libgats-654f430ac2da6435c3cbf0014cf0f681211865ee.tar.xz libgats-654f430ac2da6435c3cbf0014cf0f681211865ee.zip | |
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.
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/lib.rs | 36 |
1 files changed, 36 insertions, 0 deletions
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 { | |||
| 213 | matches!(self, Value::Null) | 213 | matches!(self, Value::Null) |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | pub fn get(&self, key: &str) -> Option<&Value> { | ||
| 217 | if let Value::Dictionary(d) = self { | ||
| 218 | d.get( key ) | ||
| 219 | } else { | ||
| 220 | None | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | pub fn as_bool( &self ) -> Result<bool,Error> { | ||
| 225 | if let Value::Boolean(d) = self { | ||
| 226 | Ok(*d) | ||
| 227 | } else { | ||
| 228 | Err(Error::new( | ||
| 229 | ErrorKind::InvalidData, | ||
| 230 | "as_bool called on non boolean value.", | ||
| 231 | )) | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | pub fn as_byte_string( &self ) -> Result<&Vec<u8>,Error> { | ||
| 236 | if let Value::ByteString(d) = self { | ||
| 237 | Ok(&d) | ||
| 238 | } else { | ||
| 239 | Err(Error::new( | ||
| 240 | ErrorKind::InvalidData, | ||
| 241 | "as_byte_string called on non ByteString value.", | ||
| 242 | )) | ||
| 243 | } | ||
| 244 | } | ||
| 245 | |||
| 216 | pub fn write<W: Write>(&self, w: &mut W) -> Result<(), Error> { | 246 | pub fn write<W: Write>(&self, w: &mut W) -> Result<(), Error> { |
| 217 | match self { | 247 | match self { |
| 218 | Self::Integer(x) => { | 248 | Self::Integer(x) => { |
| @@ -579,6 +609,12 @@ impl From<Vec<u8>> for Value { | |||
| 579 | } | 609 | } |
| 580 | } | 610 | } |
| 581 | 611 | ||
| 612 | impl From<&[u8]> for Value { | ||
| 613 | fn from(v: &[u8]) -> Self { | ||
| 614 | Value::ByteString( Vec::from(v) ) | ||
| 615 | } | ||
| 616 | } | ||
| 617 | |||
| 582 | #[cfg(test)] | 618 | #[cfg(test)] |
| 583 | mod tests { | 619 | mod tests { |
| 584 | use super::*; | 620 | use super::*; |
