TryRamify

Trait TryRamify 

Source
pub trait TryRamify<V> {
    type Error;

    // Required methods
    fn try_ramify(
        &mut self,
        vtx: V,
    ) -> Result<impl IntoIterator<Item = V>, Self::Error>;
    fn sort_key(&self, vtx: &V) -> impl Ord;
    fn marker(&self, vtx: &V) -> char;

    // Provided methods
    fn annotate(&self, vtx: &V, buf: &mut String) { ... }
    fn is_identical(&self, vtx: &V, other: &V) -> bool { ... }
}
Expand description

Try to iterate over the children of the vertex.

This is a fallible version of Ramify where the call to Ramify::ramify might fail. This trait instead has a method TryRamify::try_ramify, which can either return an iterator over children or fail.

This trait is used by a generator to manage control flow around errors. When driven by a generator, if an error occurs, no writes are performed and the generator is put into a suspended state and yields control back to the caller.

If you wish to represent the errors directly inside the tree, you should implement Ramify with a vertex type like Result<V, E>.

The Ramify docs contain more detail. Here, we only document the differences.

§Blanket implementation

There is a blanket implementation of TryRamify<V> whenever a type is Ramify<V> with the call to try_ramify always returning Ok(_). In particular, you can use a Ramify implementation anywhere a TryRamify implementation is expected.

Required Associated Types§

Source

type Error

An error which may occur while trying to retrieve the children.

Required Methods§

Source

fn try_ramify( &mut self, vtx: V, ) -> Result<impl IntoIterator<Item = V>, Self::Error>

Try to iterate over the children of the vertex or return an error.

If an error occurs while this ramifier is driven by a generator, the error is returned in the State::Suspended variant along with the suspended generator. In order to resume iteration after an error, the error type should contain enough context to recover, for instance by moving the vertex into the error.

Source

fn sort_key(&self, vtx: &V) -> impl Ord

Get the sort key associated with a vertex.

Source

fn marker(&self, vtx: &V) -> char

The vertex marker in the branch diagram.

Provided Methods§

Source

fn annotate(&self, vtx: &V, buf: &mut String)

An annotation to write alongside a vertex.

Source

fn is_identical(&self, vtx: &V, other: &V) -> bool

Determine if two vertices are identical and should be merged.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<R: Ramify<V>, V> TryRamify<V> for R