Skip to main content

Librecast

Struct Librecast 

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

Implementations§

Source§

impl Librecast

Source

pub fn new() -> Result<Self>

Create a new librecast context

Examples found in repository?
examples/sender.rs (line 8)
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 8)
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 channel_builder(&self) -> ChannelBuilder<'_>

Get a builder for creating a new channel

Examples found in repository?
examples/sender.rs (line 12)
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 12)
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 Drop for Librecast

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

impl Send for Librecast

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.