Struct ockam_core::Any
source · [−]pub struct Any;
Expand description
A passthrough marker message type.
This is a special message type which will enable your worker to accept any typed message, by ignoring the type information in the payload.
This is especially useful for implementing middleware workers which need access to the route information of a message, without understanding its payload.
Examples
ⓘ
use ockam::{hex, Any, Context, Result, Routed, Worker};
pub struct Logger;
#[ockam::worker]
impl Worker for Logger {
type Context = Context;
type Message = Any;
/// This Worker will take any incoming message, print out the payload
/// and then forward it to the next hop in its onward route.
async fn handle_message(&mut self, ctx: &mut Context, msg: Routed<Any>) -> Result<()> {
let mut local_msg = msg.into_local_message();
let transport_msg = local_msg.transport_mut();
transport_msg.onward_route.step()?;
transport_msg.return_route.modify().prepend(ctx.address());
let payload = transport_msg.payload.clone();
if let Ok(str) = String::from_utf8(payload.clone()) {
println!("Address: {}, Received string: {}", ctx.address(), str);
} else {
println!("Address: {}, Received binary: {}", ctx.address(), hex::encode(&payload));
}
ctx.forward(local_msg).await
}
}
Trait Implementations
impl Eq for Any
impl Message for Any
impl StructuralEq for Any
impl StructuralPartialEq for Any
Auto Trait Implementations
impl RefUnwindSafe for Any
impl Send for Any
impl Sync for Any
impl Unpin for Any
impl UnwindSafe for Any
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