Skip to main content

Path

Enum Path 

Source
pub enum Path<V, E> {
    Id(V),
    Seq(NonEmpty<E>),
}
Expand description

A path in a graph or category.

This definition by cases can be compared with the perhaps more obvious definition:

struct Path<V, E> {
start: V,
end: V, // Optional: more symmetric but also more redundant.
seq: Vec<E>,
}

Not only does the single struct store redundant (hence possibly inconsistent) information when the sequence of edges is nonempty, one will often need to do a case analysis on the edge sequence anyway to determine whether, say, reduce returns a non-null value. Thus, it seems better to reify the two cases in the data structure itself.

Variants§

§

Id(V)

The identity, or empty, path at a vertex.

§

Seq(NonEmpty<E>)

A nontrivial path, comprising a non-empty vector of consecutive edges.

Implementations§

Source§

impl Path<ModeApp<QualifiedName>, ModeApp<ModalOp>>

Source

pub fn ob_act(self, ob: ModalOb) -> Result<ModalOb, String>

Acts on an object in a model of a modal theory.

Source§

impl Path<ModeApp<QualifiedName>, ModeApp<ModalOp>>

Source

pub fn generator(id: QualifiedName) -> Self

Constructs the object operation for a generator.

Source

pub fn concat(list: List, arity: usize, ob_type: ModalObType) -> Self

Constructs a concatenation operation for a list modality.

Source

pub fn apply(self, m: Modality) -> Self

Applies a modality.

Source

pub fn apply_all(self, iter: impl IntoIterator<Item = Modality> + Clone) -> Self

Applies a sequence of modalities.

Source§

impl<V, E> Path<V, E>

Source

pub fn empty(v: V) -> Self

Constructs the empty or identity path.

Source

pub fn single(e: E) -> Self

Constructs a path with a single edge.

Source

pub fn pair(e: E, f: E) -> Self

Constructs a pair of consecutive edges, or path of length 2.

Source

pub fn collect<I>(iter: I) -> Option<Self>
where I: IntoIterator<Item = E>,

Constructs a path from an iterator over edges.

Returns None if the iterator is empty.

Source

pub fn from_vec(vec: Vec<E>) -> Option<Self>

Constructs a path from a vector of edges.

Returns None if the vector is empty.

Source

pub fn repeat_n(v: V, e: E, n: usize) -> Self
where E: Clone,

Constructs a path by repeating an edge n times.

The edge should have the same source and target, namely the first argument.

Source

pub fn len(&self) -> usize

Length of the path.

Source

pub fn is_empty(&self) -> bool

Is the path empty?

Source

pub fn iter(&self) -> impl Iterator<Item = &E>

Iterates over edges in the path, if any.

This method is a one-sided inverse to Path::collect.

Source

pub fn only(self) -> Option<E>

Extracts the unique edge in a path of length 1.

This method is a one-sided inverse to Path::single.

Source

pub fn insert(&mut self, index: usize, edge: E)

Inserts an edge into the path at the given index.

Source

pub fn splice(self, range: Range<usize>, replace_with: Self) -> Self

Splices a path into another path at the given range of indices.

Source

pub fn src(&self, graph: &impl Graph<V = V, E = E>) -> V
where V: Clone,

Source of the path in the given graph.

Assumes that the path is contained in the graph.

Source

pub fn tgt(&self, graph: &impl Graph<V = V, E = E>) -> V
where V: Clone,

Target of the path in the given graph.

Assumes that the path is contained in the graph.

Source

pub fn subpath( &self, graph: &impl Graph<V = V, E = E>, range: Range<usize>, ) -> Self
where V: Eq + Clone, E: Clone,

Extracts a subpath of a path in a graph.

Panics if the range is invalid or an empty subpath would be inconsistent.

Source

pub fn replace_subpath( self, graph: &impl Graph<V = V, E = E>, range: Range<usize>, f: impl FnOnce(Self) -> Self, ) -> Self
where V: Eq + Clone, E: Clone,

Replaces the subpath at the given range with a function of that subpath.

Panics under the same conditions as subpath.

Source

pub fn concat_in( self, graph: &impl Graph<V = V, E = E>, other: Self, ) -> Option<Self>
where V: Eq + Clone,

Concatenates this path with another path in the graph.

This methods checks that the two paths are compatible (the target of this path equals the source of the other path) and it assumes that both paths are contained in the graph, which should be checked with contained_in if in doubt. Thus, when returned, the concatenated path is also a valid path.

Source

pub fn contained_in(&self, graph: &impl Graph<V = V, E = E>) -> bool
where V: Eq,

Is the path contained in the given graph?

Source

pub fn is_simple(&self) -> bool
where E: Eq + Hash,

Returns whether the path is simple.

On our definition, a path is simple if it has no repeated edges.

Source

pub fn reduce(self, fv: impl FnOnce(V) -> E, fe: impl FnMut(E, E) -> E) -> E

Reduces a path using functions on vertices and edges.

Source

pub fn map<CodV, CodE>( self, fv: impl FnOnce(V) -> CodV, fe: impl FnMut(E) -> CodE, ) -> Path<CodV, CodE>

Maps a path over functions on vertices and edges.

Source

pub fn map_reduce<T>( self, fv: impl FnOnce(V) -> T, fe: impl FnMut(E) -> T, f: impl FnMut(T, T) -> T, ) -> T

Maps and then reduces over a path.

This equivalent to calling map and then reduce but avoids allocating the intermediate path.

Source

pub fn partial_map<CodV, CodE>( self, fv: impl FnOnce(V) -> Option<CodV>, fe: impl FnMut(E) -> Option<CodE>, ) -> Option<Path<CodV, CodE>>

Maps a path over partial functions on vertices and edges.

Source

pub fn try_map<CodV, CodE, Err>( self, fv: impl FnOnce(V) -> Result<CodV, Err>, fe: impl FnMut(E) -> Result<CodE, Err>, ) -> Result<Path<CodV, CodE>, Err>

Maps a path over fallible functions on vertices and edges.

Source§

impl<V, E> Path<V, Path<V, E>>

Source

pub fn flatten(self) -> Path<V, E>

Flattens a path of paths into a single path.

Unlike flatten_in, this method does not check that the composite is well typed before computing it.

Source

pub fn flatten_in(self, graph: &impl Graph<V = V, E = E>) -> Option<Path<V, E>>
where V: Eq + Clone,

Flattens a path of paths in a graph into a single path.

Returns the flattened path just when the original paths have compatible start and end points.

Trait Implementations§

Source§

impl<V: Clone, E: Clone> Clone for Path<V, E>

Source§

fn clone(&self) -> Path<V, E>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Debug, E: Debug> Debug for Path<V, E>

Source§

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

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

impl<V, E> From<E> for Path<V, E>

Converts an edge into a path of length one.

Source§

fn from(e: E) -> Self

Converts to this type from the input type.
Source§

impl From<Path<QualifiedName, QualifiedName>> for MorType

Source§

fn from(value: QualifiedPath) -> Self

Converts to this type from the input type.
Source§

impl<V, E> From<ShortPath<V, E>> for Path<V, E>

Source§

fn from(path: ShortPath<V, E>) -> Self

Converts to this type from the input type.
Source§

impl<V: Hash, E: Hash> Hash for Path<V, E>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<V, E> IntoIterator for Path<V, E>

Converts the path into an iterater over its edges.

Source§

type Item = E

The type of the elements being iterated over.
Source§

type IntoIter = Either<Empty<E>, <NonEmpty<E> as IntoIterator>::IntoIter>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<V: PartialEq, E: PartialEq> PartialEq for Path<V, E>

Source§

fn eq(&self, other: &Path<V, E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V, E> TryFrom<Path<V, E>> for ShortPath<V, E>

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(path: Path<V, E>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<V: Eq, E: Eq> Eq for Path<V, E>

Source§

impl<V, E> StructuralPartialEq for Path<V, E>

Auto Trait Implementations§

§

impl<V, E> Freeze for Path<V, E>
where V: Freeze, E: Freeze,

§

impl<V, E> RefUnwindSafe for Path<V, E>

§

impl<V, E> Send for Path<V, E>
where V: Send, E: Send,

§

impl<V, E> Sync for Path<V, E>
where V: Sync, E: Sync,

§

impl<V, E> Unpin for Path<V, E>
where V: Unpin, E: Unpin,

§

impl<V, E> UnsafeUnpin for Path<V, E>
where V: UnsafeUnpin, E: UnsafeUnpin,

§

impl<V, E> UnwindSafe for Path<V, E>
where V: UnwindSafe, E: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,