Struct fbp::fbp_node_context::SenderWrapper [−][src]
pub struct SenderWrapper(_);
Expand description
SenderWrapper
The FBP system uses std::sync::mpsc to send IIDMessages between FBP nodes. All of the items in the FBPNodeContext are only needed at runtime and are created when the FBPNodeContext is created. This means that most of the fields in the FBPNodeContext need to be #[serde(skip)] as the FBPNodeContext does need to be Serialized for at least the name field as it is the name of the “owning” FBPNode. This is used to allow for creating a network of nodes from a JSON string. Using #[serde(skip)] requires that at least the Default trait needs to be implemented. The std::sync::mpsc structs do not implement the Default trait. One cannot implement the Default trait for a type that was not defined in the module. This issue can be solved by using the New Type Idiom
The SenderWrapper type wraps a std::sync::mpsc::Sender struct so that the Derive and Clone traits can be implemented.
Methods from Deref<Target = Sender<IIDMessage>>
Attempts to send a value on this channel, returning it back if it could not be sent.
A successful send occurs when it is determined that the other end of
the channel has not hung up already. An unsuccessful send would be one
where the corresponding receiver has already been deallocated. Note
that a return value of Err
means that the data will never be
received, but a return value of Ok
does not mean that the data
will be received. It is possible for the corresponding receiver to
hang up immediately after this function returns Ok
.
This method will never block the current thread.
Examples
use std::sync::mpsc::channel;
let (tx, rx) = channel();
// This send is always successful
tx.send(1).unwrap();
// This send will fail because the receiver is gone
drop(rx);
assert_eq!(tx.send(1).unwrap_err().0, 1);
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for SenderWrapper
impl Send for SenderWrapper
impl !Sync for SenderWrapper
impl Unpin for SenderWrapper
impl !UnwindSafe for SenderWrapper
Blanket Implementations
Mutably borrows from an owned value. Read more