Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

The whole model: every node, looked up by id. BTreeMap again, so iteration is in id order, which is exactly the order the spec requires for output.

Implementations§

Source§

impl Graph

Source

pub fn new() -> Self

An empty graph.

Source

pub fn insert(&mut self, node: Node) -> Result<(), Node>

Add a node. If the id is already taken the existing node is kept (“first wins”, the spec’s duplicate rule) and the rejected node is handed back in Err.

Source

pub fn get(&self, id: &str) -> Option<&Node>

Look a node up. Returns a borrowed reference, not a copy: Option<&Node>.

Source

pub fn scratch_of<'a>(&'a self, node: &'a Node) -> Option<&'a str>

The scratch plane a node sits in, if it is in one: its plane names a plane node with fields.scratch: true. A scratch is a sandbox: rules skip its nodes and nothing outside it may link to or parent them.

Source

pub fn len(&self) -> usize

The number of nodes.

Source

pub fn is_empty(&self) -> bool

True when the graph has no nodes.

Source

pub fn nodes(&self) -> impl Iterator<Item = &Node>

Every node in id order. impl Iterator means “something you can loop over”.

Trait Implementations§

Source§

impl Debug for Graph

Source§

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

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

impl Default for Graph

Source§

fn default() -> Graph

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

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

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> 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, 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.