Struct ockam::Route

source ·
pub struct Route { /* private fields */ }
Expand description

A full route to a peer.

Implementations§

source§

impl Route

source

pub fn new() -> RouteBuilder<'static>

Create an empty RouteBuilder.

Examples
// ["1#alice", "0#bob"]
let route: Route = Route::new()
    .append_t(TCP, "alice")
    .append("bob")
    .into();
source

pub fn create<T>(vt: Vec<T>) -> Route
where T: Into<Address>,

Create a route from a Vec of Address.

Examples
// ["1#alice", "0#bob"]
let route = route![
    Address::new(TCP, "alice"),
    "bob",
];
source

pub fn parse<S>(s: S) -> Option<Route>
where S: Into<String>,

Parse a route from a string.

Examples
if let Some(route) = Route::parse("1#alice => bob") {
    // ["1#alice", "0#bob"]
    route
}
source

pub fn modify(&mut self) -> RouteBuilder<'_>

Create a new RouteBuilder from the current Route.

Examples
let mut route: Route = route!["1#alice", "bob"];

// ["1#alice", "0#bob", "0#carol"]
let route: Route = route.modify()
    .append("carol")
    .into();
source

pub fn step(&mut self) -> Result<Address, Error>

Return the next Address and remove it from this route.

Examples
let mut route: Route = route!["1#alice", "bob"];

// "1#alice"
let next_hop: Address = route.step()?;

// ["0#bob"]
route
source

pub fn next(&self) -> Result<&Address, Error>

Return the next Address from this route without removing it.

Examples
let route: Route = route!["1#alice", "bob"];

// "1#alice"
let next_hop: &Address = route.next()?;

// ["1#alice", "0#bob"]
route
source

pub fn recipient(&self) -> Result<Address, Error>

Return the final recipient address.

Examples
let route: Route = route!["1#alice", "bob"];

// "0#bob"
let final_hop: Address = route.recipient()?;

// ["1#alice", "0#bob"]
route
source

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

Iterate over all addresses of this route.

source

pub fn len(&self) -> usize

Number of hops.

source

pub fn is_empty(&self) -> bool

Returns true if the route is empty.

source

pub fn contains_route(&self, needle: &Route) -> Result<bool, Error>

Returns true if route contains needle.

Returns Err(_) if needle is an empty route.

Examples
let r: Route = route!["a", "b", "c", "d"];

// true
let res = r.contains_route(&route!["b", "c"])?;

// false
let res = r.contains_route(&route!["a", "c"])?;

// false
let res = r.contains_route(&route!["a", "b", "c", "d", "e"])?;
source

pub fn is_local(&self) -> bool

Return true if all the addresses composing that route are local addresses

Trait Implementations§

source§

impl Clone for Route

source§

fn clone(&self) -> Route

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Route

source§

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

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

impl<'bytes, Ctx> Decode<'bytes, Ctx> for Route

source§

fn decode( __d777: &mut Decoder<'bytes>, __ctx777: &mut Ctx ) -> Result<Route, Error>

Decode a value using the given Decoder. Read more
source§

fn nil() -> Option<Self>

If possible, return a nil value of Self. Read more
source§

impl<'de> Deserialize<'de> for Route

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<Route, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Route

source§

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

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

impl<Ctx> Encode<Ctx> for Route

source§

fn encode<__W777>( &self, __e777: &mut Encoder<__W777>, __ctx777: &mut Ctx ) -> Result<(), Error<<__W777 as Write>::Error>>
where __W777: Write,

Encode a value of this type using the given Encoder. Read more
source§

fn is_nil(&self) -> bool

Is this value of Self a nil value? Read more
source§

impl From<RouteBuilder<'_>> for Route

Convert a RouteBuilder into a Route.

source§

fn from(_: RouteBuilder<'_>) -> Route

Converts to this type from the input type.
source§

impl From<SenderAddress> for Route

source§

fn from(addr: SenderAddress) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Route
where T: Into<Address>,

Convert an Address into a Route.

A single address can represent a valid route.

source§

fn from(addr: T) -> Route

Converts to this type from the input type.
source§

impl Hash for Route

source§

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

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 Ord for Route

source§

fn cmp(&self, other: &Route) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Route

source§

fn eq(&self, other: &Route) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Route

source§

fn partial_cmp(&self, other: &Route) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Route

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Route

source§

impl StructuralEq for Route

source§

impl StructuralPartialEq for Route

Auto Trait Implementations§

§

impl RefUnwindSafe for Route

§

impl Send for Route

§

impl Sync for Route

§

impl Unpin for Route

§

impl UnwindSafe for Route

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<D> AsyncTryClone for D
where D: Clone + Sync,

source§

fn async_try_clone<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<D, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, D: 'async_trait,

Try cloning a object and return an Err in case of failure.
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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<T> Decodable for T

source§

fn decode(encoded: &[u8]) -> Result<T, Error>

Decode a slice.
source§

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

source§

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

source§

impl<T> Encodable for T
where T: Serialize,

source§

fn encode(&self) -> Result<Vec<u8>, Error>

Encode the type into an Encoded type.
§

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
§

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.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,