Struct ockam_core::Route
source · [−]pub struct Route { /* private fields */ }
Expand description
A full route to a peer.
Implementations
sourceimpl Route
impl Route
sourcepub fn new() -> RouteBuilder<'static>
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();
sourcepub fn parse<S: Into<String>>(s: S) -> Option<Route>
pub fn parse<S: Into<String>>(s: S) -> Option<Route>
Parse a route from a string.
Examples
if let Some(route) = Route::parse("1#alice => bob") {
// ["1#alice", "0#bob"]
route
}
sourcepub fn modify(&mut self) -> RouteBuilder<'_>
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();
sourcepub fn step(&mut self) -> Result<Address>
pub fn step(&mut self) -> Result<Address>
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
sourcepub fn next(&self) -> Result<&Address>
pub fn next(&self) -> Result<&Address>
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
sourcepub fn recipient(&self) -> Address
pub fn recipient(&self) -> Address
Return the final recipient address.
Panics
This function will panic if passed an empty route.
Examples
let route: Route = route!["1#alice", "bob"];
// "0#bob"
let final_hop: Address = route.recipient();
// ["1#alice", "0#bob"]
route
TODO
For consistency we should not panic and return a
Result<&Address> instead of an Address.clone().
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Route
impl<'de> Deserialize<'de> for Route
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<RouteBuilder<'_>> for Route
impl From<RouteBuilder<'_>> for Route
sourcefn from(_: RouteBuilder<'_>) -> Self
fn from(_: RouteBuilder<'_>) -> Self
Converts to this type from the input type.
sourceimpl<T: Into<Address>> From<Vec<T, Global>> for Route
impl<T: Into<Address>> From<Vec<T, Global>> for Route
Convert a A Vec
of Address
es into a Route
.
A vector of addresses can represent a valid route.
Note that this only holds if the vector index order is in the same order as the expected route.
sourceimpl Ord for Route
impl Ord for Route
sourceimpl PartialOrd<Route> for Route
impl PartialOrd<Route> for Route
sourcefn partial_cmp(&self, other: &Route) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
impl Eq for Route
impl StructuralEq for Route
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
sourceimpl<D> AsyncTryClone for D where
D: Clone + Sync,
impl<D> AsyncTryClone for D where
D: Clone + Sync,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more