pub fn from_slice(input: &(impl AsRef<[u8]> + ?Sized)) -> Result<Sexpr<'_>>
Expand description
Parse a Sexpr
from bytes. This fails if there is more than one S-expression in the
input. To allow an arbitrary amount of S-expressions, have a look at from_slice_multi
.
§Example
let sexpr = rsexpr::from_slice(b"((\"foo bar\")(baz [1 2 3]))").unwrap();
println!("{sexpr:#}");
if let rsexpr::Sexpr::List(list) = sexpr {
assert_eq!(list.len(), 2);
}
§Errors
If the parsing failed, a list of Error
s is returned.
Additionally, the function will fail if the input does not contain exactly one S-expression
(see Error::EmptyInput
and Error::ExtraSexprs
).