Struct linux_ipc::IpcChannel
source · pub struct IpcChannel { /* private fields */ }Implementations§
source§impl IpcChannel
impl IpcChannel
sourcepub fn new(path: &str) -> Result<Self>
pub fn new(path: &str) -> Result<Self>
Examples found in repository?
examples/server.rs (line 13)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
println!("Creating example channel");
let mut channel = IpcChannel::new("/tmp/example.sock").expect("Failed to create channel");
loop {
println!("Receiving post in channel `init`");
let result = channel.receive::<Post>();
if result.is_err() {
eprintln!("{}", result.unwrap_err());
} else {
let result = result.unwrap();
println!("{:?}", result);
}
}
}sourcepub fn connect(path: &str) -> Result<Self>
pub fn connect(path: &str) -> Result<Self>
Examples found in repository?
examples/client.rs (line 22)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
println!("Connecting to example channel");
let mut channel = IpcChannel::connect("/tmp/example.sock").expect("Failed to create channel");
let post = Post::new(
"Hello world!",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Diam phasellus vestibulum lorem sed risus ultricies tristique nulla. Nibh sit amet commodo nulla facilisi nullam vehicula ipsum a. Eget dolor morbi non arcu risus quis varius. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius."
);
println!("Sending message in channel `example`");
let response = channel.send(post).expect("Failed to send message");
if response.is_some() {
print!("{}", response.unwrap());
}
}sourcepub fn send<T: Serialize>(&mut self, value: T) -> Result<Option<String>>
pub fn send<T: Serialize>(&mut self, value: T) -> Result<Option<String>>
Examples found in repository?
examples/client.rs (line 29)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
println!("Connecting to example channel");
let mut channel = IpcChannel::connect("/tmp/example.sock").expect("Failed to create channel");
let post = Post::new(
"Hello world!",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Diam phasellus vestibulum lorem sed risus ultricies tristique nulla. Nibh sit amet commodo nulla facilisi nullam vehicula ipsum a. Eget dolor morbi non arcu risus quis varius. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius."
);
println!("Sending message in channel `example`");
let response = channel.send(post).expect("Failed to send message");
if response.is_some() {
print!("{}", response.unwrap());
}
}sourcepub fn receive<T: DeserializeOwned + Debug>(&mut self) -> Result<T>
pub fn receive<T: DeserializeOwned + Debug>(&mut self) -> Result<T>
Examples found in repository?
examples/server.rs (line 17)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
println!("Creating example channel");
let mut channel = IpcChannel::new("/tmp/example.sock").expect("Failed to create channel");
loop {
println!("Receiving post in channel `init`");
let result = channel.receive::<Post>();
if result.is_err() {
eprintln!("{}", result.unwrap_err());
} else {
let result = result.unwrap();
println!("{:?}", result);
}
}
}Trait Implementations§
source§impl Debug for IpcChannel
impl Debug for IpcChannel
Auto Trait Implementations§
impl Freeze for IpcChannel
impl RefUnwindSafe for IpcChannel
impl Send for IpcChannel
impl Sync for IpcChannel
impl Unpin for IpcChannel
impl UnwindSafe for IpcChannel
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