forked from syndicate-lang/preserves
into_string, into_bytestring, into_symbol
This commit is contained in:
parent
602cfb8800
commit
77c305a4cf
|
@ -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)]
|
#[inline(always)]
|
||||||
pub fn to_string(&self) -> Result<&String, Error> {
|
pub fn to_string(&self) -> Result<&String, Error> {
|
||||||
self.as_string().ok_or_else(|| self.expected(ExpectedKind::String))
|
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)]
|
#[inline(always)]
|
||||||
pub fn to_bytestring(&self) -> Result<&Vec<u8>, Error> {
|
pub fn to_bytestring(&self) -> Result<&Vec<u8>, Error> {
|
||||||
self.as_bytestring().ok_or_else(|| self.expected(ExpectedKind::ByteString))
|
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)]
|
#[inline(always)]
|
||||||
pub fn to_symbol(&self) -> Result<&String, Error> {
|
pub fn to_symbol(&self) -> Result<&String, Error> {
|
||||||
self.as_symbol().ok_or_else(|| self.expected(ExpectedKind::Symbol))
|
self.as_symbol().ok_or_else(|| self.expected(ExpectedKind::Symbol))
|
||||||
|
|
Loading…
Reference in New Issue