Enum Sexpr

Source
pub enum Sexpr<'src> {
    List(Sexprs<'src>),
    Group(Sexprs<'src>),
    String(Cow<'src, [u8]>),
    Atom(&'src [u8]),
    Comment(&'src [u8]),
}
Expand description

A single node of the tree. The Atom and String variants reference the input slice. For an owned version have a look at OwnedSexpr.

§Display

Sexpr implements the Display trait for serializing to strings. By default, the output will try to minimize the amount of spaces used and the resulting output will be on one line. Enabling the formatter’s alternate flag using #, causes the output to be human-friendly / pretty-printed. Setting the precision with . additionally allows to specify the number of spaces used for indentation (2 by default).

For example:

let sexpr = rsexpr::from_slice(b"[ a b c ]").unwrap();
assert_eq!(format!("{sexpr}"), "[a b c]");
assert_eq!(format!("{sexpr:#}"), "[
  a
  b
  c
]");
assert_eq!(format!("{sexpr:#.4}"), "[
    a
    b
    c
]");

Variants§

§

List(Sexprs<'src>)

A list of Sexprs surrounded by parentheses (, )

§

Group(Sexprs<'src>)

A list of Sexprs surrounded by brackets [, ]

§

String(Cow<'src, [u8]>)

A sequence of bytes surrounded by quotes "

§

Atom(&'src [u8])

A sequence of bytes not including whitespace, parens, and quotes

§

Comment(&'src [u8])

Available on crate feature comments only.

A line comment, including the leading ;

Implementations§

Source§

impl<'src> Sexpr<'src>

Source

pub fn unwrap_list(self) -> Sexprs<'src>

Returns the contained List value, consuming self.

§Panics

Panics if self is not List.

Source

pub fn unwrap_list_ref(&self) -> &Sexprs<'src>

Returns the contained List value by reference.

§Panics

Panics if self is not List.

Source

pub fn unwrap_group(self) -> Sexprs<'src>

Returns the contained Group value, consuming self.

§Panics

Panics if self is not Group.

Source

pub fn unwrap_group_ref(&self) -> &Sexprs<'src>

Returns the contained Group value by reference.

§Panics

Panics if self is not Group.

Source

pub fn unwrap_string(self) -> Cow<'src, [u8]>

Returns the contained String value, consuming self.

§Panics

Panics if self is not String.

Source

pub fn unwrap_string_ref(&self) -> &Cow<'src, [u8]>

Returns the contained String value by reference.

§Panics

Panics if self is not String.

Source

pub fn unwrap_atom(self) -> &'src [u8]

Returns the contained Atom value, consuming self.

§Panics

Panics if self is not Atom.

Source

pub fn unwrap_atom_ref(&self) -> &&'src [u8]

Returns the contained Atom value by reference.

§Panics

Panics if self is not Atom.

Trait Implementations§

Source§

impl<'src> Clone for Sexpr<'src>

Source§

fn clone(&self) -> Sexpr<'src>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'src> Debug for Sexpr<'src>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Sexpr<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a OwnedSexpr> for Sexpr<'a>

Source§

fn from(value: &'a OwnedSexpr) -> Self

Converts to this type from the input type.
Source§

impl From<Sexpr<'_>> for OwnedSexpr

Source§

fn from(value: Sexpr<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'src> FromIterator<Sexpr<'src>> for Sexprs<'src>

Source§

fn from_iter<T: IntoIterator<Item = Sexpr<'src>>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'src> Hash for Sexpr<'src>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'src> PartialEq for Sexpr<'src>

Source§

fn eq(&self, other: &Sexpr<'src>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'src> Eq for Sexpr<'src>

Source§

impl<'src> StructuralPartialEq for Sexpr<'src>

Auto Trait Implementations§

§

impl<'src> Freeze for Sexpr<'src>

§

impl<'src> RefUnwindSafe for Sexpr<'src>

§

impl<'src> Send for Sexpr<'src>

§

impl<'src> Sync for Sexpr<'src>

§

impl<'src> Unpin for Sexpr<'src>

§

impl<'src> UnwindSafe for Sexpr<'src>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.