pub struct AtomArena<'a> { /* private fields */ }Expand description
A context that allocates Atoms in an Arena.
All construction methods are immutable from the caller’s perspective; mutation happens through the arena’s interior mutability. Identical sub-expressions are hash-consed so that structural equality implies pointer equality.
§Example
use ocas_atom::AtomArena;
use ocas_core::arena::Arena;
let arena = Arena::new();
let ctx = AtomArena::new(&arena);
let x = ctx.var("x");
let y = ctx.var("y");
let sum = ctx.add(&[x, y]);
assert_eq!(sum.to_string(), "x + y");Implementations§
Source§impl<'a> AtomArena<'a>
impl<'a> AtomArena<'a>
Sourcepub fn new(arena: &'a Arena) -> Self
pub fn new(arena: &'a Arena) -> Self
Create an AtomArena backed by the given arena.
§Example
use ocas_atom::AtomArena;
use ocas_core::arena::Arena;
let arena = Arena::new();
let ctx = AtomArena::new(&arena);
let n = ctx.num(42);
assert_eq!(n.to_string(), "42");Sourcepub fn num(&self, value: i64) -> Atom<'a>
pub fn num(&self, value: i64) -> Atom<'a>
Create an integer literal atom.
§Example
use ocas_atom::AtomArena;
use ocas_core::arena::Arena;
let arena = Arena::new();
let ctx = AtomArena::new(&arena);
let n = ctx.num(7);
assert_eq!(n.to_string(), "7");Sourcepub fn var(&self, name: &str) -> Atom<'a>
pub fn var(&self, name: &str) -> Atom<'a>
Create a variable atom from a name.
§Example
use ocas_atom::AtomArena;
use ocas_core::arena::Arena;
let arena = Arena::new();
let ctx = AtomArena::new(&arena);
let x = ctx.var("x");
assert_eq!(x.to_string(), "x");Sourcepub fn add(&self, args: &[Atom<'a>]) -> Atom<'a>
pub fn add(&self, args: &[Atom<'a>]) -> Atom<'a>
Create an addition atom.
§Panics
Panics in debug mode if args is empty.
§Example
use ocas_atom::AtomArena;
use ocas_core::arena::Arena;
let arena = Arena::new();
let ctx = AtomArena::new(&arena);
let x = ctx.var("x");
let y = ctx.var("y");
let sum = ctx.add(&[x, y]);
assert_eq!(sum.to_string(), "x + y");Sourcepub fn mul(&self, args: &[Atom<'a>]) -> Atom<'a>
pub fn mul(&self, args: &[Atom<'a>]) -> Atom<'a>
Create a multiplication atom.
§Panics
Panics in debug mode if args is empty.
§Example
use ocas_atom::AtomArena;
use ocas_core::arena::Arena;
let arena = Arena::new();
let ctx = AtomArena::new(&arena);
let x = ctx.var("x");
let y = ctx.var("y");
let product = ctx.mul(&[x, y]);
assert_eq!(product.to_string(), "x*y");Auto Trait Implementations§
impl<'a> !Freeze for AtomArena<'a>
impl<'a> !RefUnwindSafe for AtomArena<'a>
impl<'a> !Send for AtomArena<'a>
impl<'a> !Sync for AtomArena<'a>
impl<'a> !UnwindSafe for AtomArena<'a>
impl<'a> Unpin for AtomArena<'a>
impl<'a> UnsafeUnpin for AtomArena<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more