Struct linux_ipc::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 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);
        }
    }
}
source

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());
    }
}
source

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());
    }
}
source

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

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>,

§

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>,

§

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.