Skip to main content

Channel

Struct Channel 

Source
pub struct Channel<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Channel<'a>

Source

pub fn join(&self) -> Result<()>

Join this channel

Examples found in repository?
examples/sender.rs (line 19)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Create a new librecast context
8    let librecast = Librecast::new()?;
9
10    // Create a channel using the builder pattern
11    let channel = librecast
12        .channel_builder()
13        .name("example-channel")
14        .enable_raptorq()
15        .enable_loopback()
16        .build()?;
17
18    // Join the channel
19    channel.join()?;
20
21    // Rate limits the channel to 100Mbps
22    channel.rate_limit(104857600)?;
23
24    // Send a message
25    let data = b"Hello, Librecast!";
26    channel
27        .send(data)
28        .expect("Failed to send data on the channel");
29
30    // Leave the channel
31    channel.leave()?;
32
33    Ok(())
34}
More examples
Hide additional examples
examples/receiver.rs (line 18)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Create a new librecast context
8    let librecast = Librecast::new()?;
9
10    // Create a channel using the builder pattern
11    let channel = librecast
12        .channel_builder()
13        .name("example-channel")
14        .enable_raptorq()
15        .build()?;
16
17    // Join the channel
18    channel.join()?;
19
20    // Receive a message
21    let mut buffer = vec![0u8; 1024]; // Buffer to hold received data
22    match channel.receive(&mut buffer) {
23        Ok(size) => {
24            // Process the received data
25            let received_data = &buffer[..size];
26            println!(
27                "Received data: {:?}",
28                String::from_utf8_lossy(received_data)
29            );
30        }
31        Err(e) => {
32            eprintln!("Failed to receive data: {}", e);
33        }
34    }
35
36    // Leave the channel
37    channel.leave()?;
38
39    Ok(())
40}
Source

pub fn leave(&self) -> Result<()>

Leave this channel

Examples found in repository?
examples/sender.rs (line 31)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Create a new librecast context
8    let librecast = Librecast::new()?;
9
10    // Create a channel using the builder pattern
11    let channel = librecast
12        .channel_builder()
13        .name("example-channel")
14        .enable_raptorq()
15        .enable_loopback()
16        .build()?;
17
18    // Join the channel
19    channel.join()?;
20
21    // Rate limits the channel to 100Mbps
22    channel.rate_limit(104857600)?;
23
24    // Send a message
25    let data = b"Hello, Librecast!";
26    channel
27        .send(data)
28        .expect("Failed to send data on the channel");
29
30    // Leave the channel
31    channel.leave()?;
32
33    Ok(())
34}
More examples
Hide additional examples
examples/receiver.rs (line 37)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Create a new librecast context
8    let librecast = Librecast::new()?;
9
10    // Create a channel using the builder pattern
11    let channel = librecast
12        .channel_builder()
13        .name("example-channel")
14        .enable_raptorq()
15        .build()?;
16
17    // Join the channel
18    channel.join()?;
19
20    // Receive a message
21    let mut buffer = vec![0u8; 1024]; // Buffer to hold received data
22    match channel.receive(&mut buffer) {
23        Ok(size) => {
24            // Process the received data
25            let received_data = &buffer[..size];
26            println!(
27                "Received data: {:?}",
28                String::from_utf8_lossy(received_data)
29            );
30        }
31        Err(e) => {
32            eprintln!("Failed to receive data: {}", e);
33        }
34    }
35
36    // Leave the channel
37    channel.leave()?;
38
39    Ok(())
40}
Source

pub fn rate_limit(&self, limit: u32) -> Result<()>

Rate-limit sending 104857600 for 100 Mbps

Examples found in repository?
examples/sender.rs (line 22)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Create a new librecast context
8    let librecast = Librecast::new()?;
9
10    // Create a channel using the builder pattern
11    let channel = librecast
12        .channel_builder()
13        .name("example-channel")
14        .enable_raptorq()
15        .enable_loopback()
16        .build()?;
17
18    // Join the channel
19    channel.join()?;
20
21    // Rate limits the channel to 100Mbps
22    channel.rate_limit(104857600)?;
23
24    // Send a message
25    let data = b"Hello, Librecast!";
26    channel
27        .send(data)
28        .expect("Failed to send data on the channel");
29
30    // Leave the channel
31    channel.leave()?;
32
33    Ok(())
34}
Source

pub fn send(&self, data: &[u8]) -> Result<()>

Send some multicast data

Examples found in repository?
examples/sender.rs (line 27)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Create a new librecast context
8    let librecast = Librecast::new()?;
9
10    // Create a channel using the builder pattern
11    let channel = librecast
12        .channel_builder()
13        .name("example-channel")
14        .enable_raptorq()
15        .enable_loopback()
16        .build()?;
17
18    // Join the channel
19    channel.join()?;
20
21    // Rate limits the channel to 100Mbps
22    channel.rate_limit(104857600)?;
23
24    // Send a message
25    let data = b"Hello, Librecast!";
26    channel
27        .send(data)
28        .expect("Failed to send data on the channel");
29
30    // Leave the channel
31    channel.leave()?;
32
33    Ok(())
34}
Source

pub fn receive(&self, buffer: &mut [u8]) -> Result<usize>

Receive some multicast data

Examples found in repository?
examples/receiver.rs (line 22)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Create a new librecast context
8    let librecast = Librecast::new()?;
9
10    // Create a channel using the builder pattern
11    let channel = librecast
12        .channel_builder()
13        .name("example-channel")
14        .enable_raptorq()
15        .build()?;
16
17    // Join the channel
18    channel.join()?;
19
20    // Receive a message
21    let mut buffer = vec![0u8; 1024]; // Buffer to hold received data
22    match channel.receive(&mut buffer) {
23        Ok(size) => {
24            // Process the received data
25            let received_data = &buffer[..size];
26            println!(
27                "Received data: {:?}",
28                String::from_utf8_lossy(received_data)
29            );
30        }
31        Err(e) => {
32            eprintln!("Failed to receive data: {}", e);
33        }
34    }
35
36    // Leave the channel
37    channel.leave()?;
38
39    Ok(())
40}

Trait Implementations§

Source§

impl<'a> Drop for Channel<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Channel<'a>

§

impl<'a> RefUnwindSafe for Channel<'a>

§

impl<'a> !Send for Channel<'a>

§

impl<'a> !Sync for Channel<'a>

§

impl<'a> Unpin for Channel<'a>

§

impl<'a> UnsafeUnpin for Channel<'a>

§

impl<'a> UnwindSafe for Channel<'a>

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.