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
Convert a RouteBuilder
into a Route
.
sourcefn from(_: RouteBuilder<'_>) -> Self
fn from(_: RouteBuilder<'_>) -> Self
Converts to this type from the input type.
sourceimpl<T: Into<Address>> From<T> for Route
impl<T: Into<Address>> From<T> for Route
Convert an Address
into a Route
.
A single address can represent a valid route.
sourceimpl Ord for Route
impl Ord for Route
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
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>
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 moreimpl 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 Dwhere
D: Clone + Sync,
impl<D> AsyncTryClone for Dwhere
D: Clone + Sync,
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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