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 11)
10fn main() {
11 let mut channel = IpcChannel::new("/tmp/example.sock").expect("Failed to create channel");
12
13 loop {
14 let (response, reply) = channel.receive::<Test, Test>().expect("Failed to receive post");
15 println!("Received: {:#?}", response);
16
17 let to_send = Test {
18 name: response.content,
19 content: response.name,
20 };
21
22 println!("Sending: {:#?}", to_send);
23
24 reply(to_send).expect("Failed to reply to client");
25 }
26}
Sourcepub fn connect(path: &str) -> Result<Self>
pub fn connect(path: &str) -> Result<Self>
Examples found in repository?
examples/client.rs (line 13)
11fn main() {
12 let arg = &env::args().collect::<Vec<String>>()[1..].join(" ");
13 let mut channel = IpcChannel::connect("/tmp/example.sock").expect("Failed to create channel");
14
15 for _ in 0..2 {
16 let test = Test {
17 name: "test".to_string(),
18 content: arg.to_string(),
19 };
20
21 println!("Sending: {:#?}", test);
22
23 let response = channel.send::<_, Test>(test).expect("Failed to send message");
24
25 if let Some(response) = response {
26 println!("Received: {:#?}", response);
27 }
28 }
29}
Sourcepub fn send<T: Serialize, R: DeserializeOwned + Debug>(
&mut self,
value: T,
) -> Result<Option<R>>
pub fn send<T: Serialize, R: DeserializeOwned + Debug>( &mut self, value: T, ) -> Result<Option<R>>
Examples found in repository?
examples/client.rs (line 23)
11fn main() {
12 let arg = &env::args().collect::<Vec<String>>()[1..].join(" ");
13 let mut channel = IpcChannel::connect("/tmp/example.sock").expect("Failed to create channel");
14
15 for _ in 0..2 {
16 let test = Test {
17 name: "test".to_string(),
18 content: arg.to_string(),
19 };
20
21 println!("Sending: {:#?}", test);
22
23 let response = channel.send::<_, Test>(test).expect("Failed to send message");
24
25 if let Some(response) = response {
26 println!("Received: {:#?}", response);
27 }
28 }
29}
Sourcepub fn receive<T: DeserializeOwned + Debug, R: Serialize>(
&mut self,
) -> Result<(T, Box<dyn FnOnce(R) -> Result<()>>)>
pub fn receive<T: DeserializeOwned + Debug, R: Serialize>( &mut self, ) -> Result<(T, Box<dyn FnOnce(R) -> Result<()>>)>
Examples found in repository?
examples/server.rs (line 14)
10fn main() {
11 let mut channel = IpcChannel::new("/tmp/example.sock").expect("Failed to create channel");
12
13 loop {
14 let (response, reply) = channel.receive::<Test, Test>().expect("Failed to receive post");
15 println!("Received: {:#?}", response);
16
17 let to_send = Test {
18 name: response.content,
19 content: response.name,
20 };
21
22 println!("Sending: {:#?}", to_send);
23
24 reply(to_send).expect("Failed to reply to client");
25 }
26}
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