Struct dcc_lsystem::arena::Arena[][src]

pub struct Arena<T> { /* fields omitted */ }
Expand description

A simple arena wrapping around a Vec.

Examples

use dcc_lsystem::Arena;

let mut arena = Arena::new();

let u = arena.push(1);
let v = arena.push(2);

assert_eq!(arena.len(), 2);
assert_eq!(arena.get(u), Some(&1));

Implementations

impl<T> Arena<T>[src]

pub fn new() -> Self[src]

Creates a new empty arena.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new();

arena.push(1);
arena.push(3);

pub fn len(&self) -> usize[src]

Returns the length of this arena.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new();

for i in 0..420 {
    arena.push(i);
}

assert_eq!(arena.len(), 420);

pub fn is_empty(&self) -> bool[src]

Returns true if the arena contains no elements.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new();

assert!(arena.is_empty());

arena.push(3);

assert!(!arena.is_empty());

pub fn get(&self, id: ArenaId) -> Option<&T>[src]

Returns a reference to an entry of the arena, if the provided ArenaId is valid.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new();

let x = arena.push("x");
let y = arena.push("y");
let z = arena.push("z");

assert_eq!(arena.get(y), Some(&"y"));

pub fn get_mut(&mut self, id: ArenaId) -> Option<&mut T>[src]

Returns a mutable reference to the entry corresponding to the given index.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new();

let x = arena.push("x");

if let Some(entry) = arena.get_mut(x) {
    *entry = "y";
}

assert_eq!(arena.get(x), Some(&"y"));

pub fn iter(&self) -> Iter<'_, T>[src]

Returns an iterator over this arena.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new();
let x = arena.push(3);
let y = arena.push(5);

let mut iterator = arena.iter();

assert_eq!(iterator.next(), Some(&3));
assert_eq!(iterator.next(), Some(&5));
assert_eq!(iterator.next(), None)

pub fn iter_mut(&mut self) -> IterMut<'_, T>[src]

Returns an iterator that allows modifying each value.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new();
let x = arena.push(3);
let y = arena.push(-4);

for entry in arena.iter_mut() {
    *entry = *entry * *entry;
}

let mut iterator = arena.iter();

assert_eq!(iterator.next(), Some(&9));
assert_eq!(iterator.next(), Some(&16));

pub fn is_valid(&self, id: ArenaId) -> bool[src]

Returns true if the provided id corresponds to an element of this arena.

use dcc_lsystem::{Arena, ArenaId};

let mut arena = Arena::new();
let x = arena.push(17);
let y = arena.push(21);

assert!(arena.is_valid(x));
assert!(arena.is_valid(y));

assert!(!arena.is_valid(ArenaId(2)));

pub fn is_valid_slice(&self, slice: &[ArenaId]) -> bool[src]

Returns true if the every id in the provided slice is valid.

Example

use dcc_lsystem::{Arena, ArenaId};

let mut arena = Arena::new();
let x = arena.push(1);
let y = arena.push(3);
let z = arena.push(7);

assert!(arena.is_valid_slice(&[x,y]));
assert!(arena.is_valid_slice(&[x,y,z]));
assert!(!arena.is_valid_slice(&[x,y,ArenaId(3)]));

pub fn push(&mut self, value: T) -> ArenaId[src]

Add a new value to our arena.

Returns an ArenaId which uniquely identifies this element of the arena.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new(); let x = arena.push(11); let y = arena.push(-3);

assert_eq!(x, ArenaId(0)); assert_eq!(y, ArenaId(1));

pub fn enumerate(&self) -> EnumerableArena<'_, T>

Notable traits for EnumerableArena<'a, T>

impl<'a, T> Iterator for EnumerableArena<'a, T> type Item = (ArenaId, &'a T);
[src]

Returns an EnumerableArena.

Example

use dcc_lsystem::Arena;

let mut arena = Arena::new();
let x = arena.push(3);
let y = arena.push(5);
let z = arena.push(-7);

for (id, entry) in arena.enumerate() {
    /* do some work here */
}

impl Arena<Token>[src]

pub fn render(&self, tokens: &[ArenaId]) -> String[src]

Returns a string representation of the given slice of ArenaId’s in terms of the contents of this arena.

Trait Implementations

impl<T: Clone> Clone for Arena<T>[src]

fn clone(&self) -> Arena<T>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T: Debug> Debug for Arena<T>[src]

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

Formats the value using the given formatter. Read more

impl<T> Default for Arena<T>[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

Auto Trait Implementations

impl<T> RefUnwindSafe for Arena<T> where
    T: RefUnwindSafe

impl<T> Send for Arena<T> where
    T: Send

impl<T> Sync for Arena<T> where
    T: Sync

impl<T> Unpin for Arena<T> where
    T: Unpin

impl<T> UnwindSafe for Arena<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
    Scheme: ApproxScheme, 

type Err = NoError

The error type produced by a failed conversion.

pub fn approx_from(
    src: Src
) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
    Dst: ApproxFrom<Src, Scheme>,
    Scheme: ApproxScheme, 

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.

pub fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T, Dst> ConvAsUtil<Dst> for T

fn approx(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, DefaultApprox>, 

Approximate the subject with the default scheme.

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, Scheme>,
    Scheme: ApproxScheme, 

Approximate the subject with a specific scheme.

impl<T> ConvUtil for T

fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, DefaultApprox>, 

Approximate the subject to a given type with the default scheme.

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, Scheme>,
    Scheme: ApproxScheme, 

Approximate the subject to a given type with a specific scheme.

fn into_as<Dst>(self) -> Dst where
    Self: Into<Dst>, 

Convert the subject to a given type.

fn try_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: TryInto<Dst>, 

Attempt to convert the subject to a given type.

fn value_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: ValueInto<Dst>, 

Attempt a value conversion of the subject to a given type.

impl<T> DynClone for T where
    T: Clone
[src]

pub fn __clone_box(&self, Private) -> *mut ()[src]

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pointable for T

pub const ALIGN: usize

The alignment of pointer.

type Init = T

The type for initializers.

pub unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more

pub unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more

pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more

pub unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<Src> TryFrom<Src> for Src

type Err = NoError

The error type produced by a failed conversion.

pub fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<Src, Dst> TryInto<Dst> for Src where
    Dst: TryFrom<Src>, 

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.

pub fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V

impl<Src> ValueFrom<Src> for Src

type Err = NoError

The error type produced by a failed conversion.

pub fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.

impl<Src, Dst> ValueInto<Dst> for Src where
    Dst: ValueFrom<Src>, 

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.

pub fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.