From 77c305a4cf507b087ce9b46cb7b3b45bb7e29480 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 4 Oct 2021 14:28:56 +0200 Subject: [PATCH] into_string, into_bytestring, into_symbol --- .../rust/preserves/src/value/repr.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/implementations/rust/preserves/src/value/repr.rs b/implementations/rust/preserves/src/value/repr.rs index f703436..b72aa71 100644 --- a/implementations/rust/preserves/src/value/repr.rs +++ b/implementations/rust/preserves/src/value/repr.rs @@ -734,6 +734,14 @@ impl Value { } } + #[inline(always)] + pub fn into_string(self) -> Option { + match self { + Value::String(s) => Some(s), + _ => None, + } + } + #[inline(always)] pub fn to_string(&self) -> Result<&String, Error> { self.as_string().ok_or_else(|| self.expected(ExpectedKind::String)) @@ -767,6 +775,14 @@ impl Value { } } + #[inline(always)] + pub fn into_bytestring(self) -> Option> { + match self { + Value::ByteString(bs) => Some(bs), + _ => None, + } + } + #[inline(always)] pub fn to_bytestring(&self) -> Result<&Vec, Error> { self.as_bytestring().ok_or_else(|| self.expected(ExpectedKind::ByteString)) @@ -800,6 +816,14 @@ impl Value { } } + #[inline(always)] + pub fn into_symbol(self) -> Option { + match self { + Value::Symbol(s) => Some(s), + _ => None, + } + } + #[inline(always)] pub fn to_symbol(&self) -> Result<&String, Error> { self.as_symbol().ok_or_else(|| self.expected(ExpectedKind::Symbol))