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§
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
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
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.