into_string, into_bytestring, into_symbol

This commit is contained in:
Tony Garnock-Jones 2021-10-04 14:28:56 +02:00
parent 602cfb8800
commit 77c305a4cf
1 changed files with 24 additions and 0 deletions

View File

@ -734,6 +734,14 @@ impl<N: NestedValue> Value<N> {
}
}
#[inline(always)]
pub fn into_string(self) -> Option<String> {
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<N: NestedValue> Value<N> {
}
}
#[inline(always)]
pub fn into_bytestring(self) -> Option<Vec<u8>> {
match self {
Value::ByteString(bs) => Some(bs),
_ => None,
}
}
#[inline(always)]
pub fn to_bytestring(&self) -> Result<&Vec<u8>, Error> {
self.as_bytestring().ok_or_else(|| self.expected(ExpectedKind::ByteString))
@ -800,6 +816,14 @@ impl<N: NestedValue> Value<N> {
}
}
#[inline(always)]
pub fn into_symbol(self) -> Option<String> {
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))