pub struct Cell { /* private fields */ }Expand description
A pair of reference-counted nouns.
A cell can be:
- created from an array of atoms, cells, nouns, or types that can easily be converted into atoms;
- compared to other cells;
- unpacked into an array of nouns;
- pretty-printed;
- converted into a noun.
§Examples
To create a new cell, use one of the From<[T; N]> implementations:
let cell = Cell::from(["hello", "world"]);
assert_eq!(*cell.head(), Noun::from(Atom::from("hello")));
assert_eq!(*cell.tail(), Noun::from(Atom::from("world")));let cell = Cell::from([0u8, 2u8, 4u8, 8u8]);
assert_eq!(*cell.head(), Noun::from(Atom::from(0u8)));
assert_eq!(*cell.tail(), Noun::from(Cell::from([2u8, 4u8, 8u8])));Implementations§
Source§impl Cell
impl Cell
Sourcepub fn to_array<const N: usize>(&self) -> Option<[Rc<Noun>; N]>
pub fn to_array<const N: usize>(&self) -> Option<[Rc<Noun>; N]>
Unpacks this cell into an array of length N, returning None if the cell is not of the
form [a1 a2 ... aN].
§Examples
let cell = Cell::from([0u8, 1u8, 2u8, 3u8, 4u8, 5u8]);
let nouns = cell.to_array::<6>().unwrap();
assert_eq!(*nouns[0], Noun::from(Atom::from(0u8)));
assert_eq!(*nouns[1], Noun::from(Atom::from(1u8)));
assert_eq!(*nouns[2], Noun::from(Atom::from(2u8)));
assert_eq!(*nouns[3], Noun::from(Atom::from(3u8)));
assert_eq!(*nouns[4], Noun::from(Atom::from(4u8)));
assert_eq!(*nouns[5], Noun::from(Atom::from(5u8)));let cell = Cell::from([0u8, 1u8, 2u8, 3u8]);
assert_eq!(cell.to_array::<6>(), None);Sourcepub fn to_vec(&self) -> Vec<Rc<Noun>> ⓘ
pub fn to_vec(&self) -> Vec<Rc<Noun>> ⓘ
Unpacks this cell into a vector.
If the length of the cell is known at compile-time, use to_array() instead.
§Examples
let cell = Cell::from([0u8, 1u8, 2u8, 4u8, 8u8, 16u8, 32u8, 64u8, 128u8]);
let nouns = cell.to_vec();
assert_eq!(nouns.len(), 9);
assert_eq!(*nouns[0], Noun::from(Atom::from(0u8)));
assert_eq!(*nouns[1], Noun::from(Atom::from(1u8)));
assert_eq!(*nouns[2], Noun::from(Atom::from(2u8)));
assert_eq!(*nouns[3], Noun::from(Atom::from(4u8)));
assert_eq!(*nouns[4], Noun::from(Atom::from(8u8)));
assert_eq!(*nouns[5], Noun::from(Atom::from(16u8)));
assert_eq!(*nouns[6], Noun::from(Atom::from(32u8)));
assert_eq!(*nouns[7], Noun::from(Atom::from(64u8)));
assert_eq!(*nouns[8], Noun::from(Atom::from(128u8)));
Sourcepub fn into_parts(self) -> (Rc<Noun>, Rc<Noun>)
pub fn into_parts(self) -> (Rc<Noun>, Rc<Noun>)
Converts this cell into its head and tail, consuming the cell.
pub fn as_noun(&self) -> Noun
pub fn into_noun(self) -> Noun
pub fn in_rc(&self) -> Rc<Noun>
Sourcepub fn slot(&self, axis: usize) -> Option<Rc<Noun>>
pub fn slot(&self, axis: usize) -> Option<Rc<Noun>>
Returns the noun at the given axis, or None if the axis is invalid.
§Examples
use axsys_noun::{atom::Atom, cell::Cell, Noun, cell};
let cell = Cell::from([0u8, 1u8, 2u8]);
assert_eq!(cell.slot(0), None);
assert_eq!(cell.slot(1), Some(cell.in_rc()));
assert_eq!(cell.slot(2), Some(cell.head()));
assert_eq!(cell.slot(3), Some(cell.tail()));
assert_eq!(cell.slot(6), Some(cell.tail().as_cell().unwrap().head()));
assert_eq!(cell.slot(7), Some(cell.tail().as_cell().unwrap().tail()));Trait Implementations§
impl Cellish for &Cell
impl Cellish for Box<Cell>
impl Cellish for Cell
impl Eq for Cell
impl Nounish for &Cell
impl Nounish for Box<Cell>
impl Nounish for Cell
impl StructuralPartialEq for Cell
Auto Trait Implementations§
impl Freeze for Cell
impl RefUnwindSafe for Cell
impl !Send for Cell
impl !Sync for Cell
impl Unpin for Cell
impl UnwindSafe for Cell
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
Source§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
Given the context attached to a nom error, and given the original
input to the nom parser, extract more the useful context information. Read more
Source§impl<T> Indentable for Twhere
T: Display,
impl<T> Indentable for Twhere
T: Display,
Source§fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>
fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>
Source§impl<I> RecreateContext<I> for I
impl<I> RecreateContext<I> for I
Source§fn recreate_context(_original_input: I, tail: I) -> I
fn recreate_context(_original_input: I, tail: I) -> I
Given the original input, as well as the context reported by nom,
recreate a context in the original string where the error occurred. Read more