Struct ipc_channel::ipc::IpcReceiverSet
source · pub struct IpcReceiverSet {
os_receiver_set: OsIpcReceiverSet,
}
Expand description
Collection of IpcReceivers moved into the set; thus creating a common (and exclusive) endpoint for receiving messages on any of the added channels.
§Examples
let data = vec![0x52, 0x75, 0x73, 0x74, 0x00];
let (tx, rx) = ipc::channel().unwrap();
let mut rx_set = IpcReceiverSet::new().unwrap();
// Add the receiver to the receiver set and send the data
// from the sender
let rx_id = rx_set.add(rx).unwrap();
tx.send(data.clone()).unwrap();
// Poll the receiver set for any readable events
for event in rx_set.select().unwrap() {
match event {
IpcSelectionResult::MessageReceived(id, message) => {
let rx_data: Vec<u8> = message.to().unwrap();
assert_eq!(id, rx_id);
assert_eq!(data, rx_data);
println!("Received: {:?} from {}...", data, id);
},
IpcSelectionResult::ChannelClosed(id) => {
assert_eq!(id, rx_id);
println!("No more data from {}...", id);
}
}
}
Fields§
§os_receiver_set: OsIpcReceiverSet
Implementations§
source§impl IpcReceiverSet
impl IpcReceiverSet
sourcepub fn new() -> Result<IpcReceiverSet, Error>
pub fn new() -> Result<IpcReceiverSet, Error>
Create a new empty IpcReceiverSet.
Receivers may then be added to the set with the add method.
sourcepub fn add<T>(&mut self, receiver: IpcReceiver<T>) -> Result<u64, Error>where
T: for<'de> Deserialize<'de> + Serialize,
pub fn add<T>(&mut self, receiver: IpcReceiver<T>) -> Result<u64, Error>where
T: for<'de> Deserialize<'de> + Serialize,
Add and consume the IpcReceiver to the set of receivers to be polled. IpcReceiver: struct.IpcReceiver.html
sourcepub fn add_opaque(&mut self, receiver: OpaqueIpcReceiver) -> Result<u64, Error>
pub fn add_opaque(&mut self, receiver: OpaqueIpcReceiver) -> Result<u64, Error>
Add an OpaqueIpcReceiver to the set of receivers to be polled. OpaqueIpcReceiver: struct.OpaqueIpcReceiver.html
Auto Trait Implementations§
impl Freeze for IpcReceiverSet
impl RefUnwindSafe for IpcReceiverSet
impl Send for IpcReceiverSet
impl Sync for IpcReceiverSet
impl Unpin for IpcReceiverSet
impl UnwindSafe for IpcReceiverSet
Blanket Implementations§
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