Struct ockam_core::Route
source · pub struct Route { /* private fields */ }
Expand description
A full route to a peer.
Implementations§
source§impl 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) -> Result<Address>
pub fn recipient(&self) -> Result<Address>
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
sourcepub fn contains_route(&self, needle: &Route) -> Result<bool>
pub fn contains_route(&self, needle: &Route) -> Result<bool>
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"])?;
Trait Implementations§
source§impl<'de> Deserialize<'de> for Route
impl<'de> Deserialize<'de> for Route
source§fn 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
source§impl From<RouteBuilder<'_>> for Route
impl From<RouteBuilder<'_>> for Route
Convert a RouteBuilder
into a Route
.
source§fn from(_: RouteBuilder<'_>) -> Self
fn from(_: RouteBuilder<'_>) -> Self
Converts to this type from the input type.
source§impl<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.
source§impl Ord for Route
impl Ord for Route
source§impl PartialEq for Route
impl PartialEq for Route
source§impl PartialOrd for Route
impl PartialOrd for Route
1.0.0 · source§fn 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§
source§impl<D> AsyncTryClone for D
impl<D> AsyncTryClone for D
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more