Struct IpcChannel

Source
pub struct IpcChannel { /* private fields */ }

Implementations§

Source§

impl IpcChannel

Source

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}
Source

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}
Source

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}
Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for IpcChannel

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.