pub struct SplitChannelOptions { /* private fields */ }

Implementations§

source§

impl SplitChannelOptions

source

pub fn connect(&self) -> Result<(RecvChannel, SendChannel), Error>

Examples found in repository?
examples/split_channel-benchmark-client.rs (line 35)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() {
    std::thread::spawn(|| {
        let mut collector = Collector::new();
        split_channel::register_biometrics(&mut collector);
        let fout = File::create("/dev/stdout").unwrap();
        let mut emit = PlainTextEmitter::new(fout);
        loop {
            let now = SystemTime::now()
                .duration_since(SystemTime::UNIX_EPOCH)
                .expect("clock should never fail")
                .as_millis()
                .try_into()
                .expect("millis since epoch should fit u64");
            if let Err(e) = collector.emit(&mut emit, now) {
                eprintln!("collector error: {}", e);
            }
            std::thread::sleep(std::time::Duration::from_millis(249));
        }
    });
    let (options, free) = SplitChannelOptions::from_command_line_relaxed(
        "Usage: split_channel-benchmark-client [OPTIONS]",
    );
    if !free.is_empty() {
        eprintln!("command ignores positional arguments");
    }
    let (mut recv_chan, mut send_chan) = match options.connect() {
        Ok((recv_chan, send_chan)) => (recv_chan, send_chan),
        Err(e) => {
            panic!("err: {}", e);
        }
    };
    let mut counter = 0u64;
    loop {
        let msg = format!("ping {}", counter);
        let buf = msg.as_bytes();
        counter += 1;
        send_chan.send(buf).expect("send");
        let _ = recv_chan.recv().expect("recv");
    }
}
source

pub fn bind_to(&self) -> Result<Listener, Error>

Examples found in repository?
examples/split_channel-benchmark-server.rs (line 36)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
fn main() {
    std::thread::spawn(|| {
        let mut collector = Collector::new();
        split_channel::register_biometrics(&mut collector);
        let fout = File::create("/dev/stdout").unwrap();
        let mut emit = PlainTextEmitter::new(fout);
        loop {
            let now = SystemTime::now()
                .duration_since(SystemTime::UNIX_EPOCH)
                .expect("clock should never fail")
                .as_millis()
                .try_into()
                .expect("millis since epoch should fit u64");
            if let Err(e) = collector.emit(&mut emit, now) {
                eprintln!("collector error: {}", e);
            }
            std::thread::sleep(std::time::Duration::from_millis(249));
        }
    });

    let (options, free) = SplitChannelOptions::from_command_line_relaxed(
        "Usage: split_channel-benchmark-server [OPTIONS]",
    );
    if !free.is_empty() {
        eprintln!("command ignores positional arguments");
    }
    let listener = options.bind_to().expect("bind-to");

    let handle_client = |mut recv_chan: RecvChannel, mut send_chan: SendChannel| loop {
        let buf = recv_chan.recv().expect("recv");
        send_chan.send(&buf).expect("send");
    };
    let mut threads = Vec::new();
    for stream in listener {
        match stream {
            Ok((recv_chan, send_chan)) => {
                threads.push(std::thread::spawn(move || {
                    handle_client(recv_chan, send_chan);
                }));
            }
            Err(e) => {
                eprintln!("failure: {}", e);
            }
        }
    }
    for thread in threads.into_iter() {
        thread.join().expect("join");
    }
}

Trait Implementations§

source§

impl Clone for SplitChannelOptions

source§

fn clone(&self) -> SplitChannelOptions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl CommandLine for SplitChannelOptions

source§

fn add_opts(&self, prefix: Option<&str>, opts: &mut Options)

Add options to the getopts parser.
source§

fn matches(&mut self, prefix: Option<&str>, matches: &Matches)

Assign values to self using the provided getopts matches.
source§

fn canonical_command_line(&self, prefix: Option<&str>) -> Vec<String>

Return the canonical command line for this CommandLine.
source§

fn from_command_line(usage: &str) -> (Self, Vec<String>)

Parse from the command line. This function will panic if a non-canonical command line is provided.
source§

fn from_command_line_relaxed(usage: &str) -> (Self, Vec<String>)

Parse from the command line. This function will allow a non-canonical command line to execute.
source§

fn from_arguments(usage: &str, args: &[&str]) -> (Self, Vec<String>)

Parse from the provided arguments. This function will panic if a non-canonical command line is provided.
source§

fn from_arguments_relaxed(usage: &str, args: &[&str]) -> (Self, Vec<String>)

Parse from the provided arguments. This function will allow a non-canonical command line to execute.
source§

fn usage(&mut self, opts: Options, brief: &str) -> !

Display the usage and exit 1.
source§

impl Debug for SplitChannelOptions

source§

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

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

impl Default for SplitChannelOptions

source§

fn default() -> SplitChannelOptions

Returns the “default value” for a type. Read more
source§

impl PartialEq for SplitChannelOptions

source§

fn eq(&self, other: &SplitChannelOptions) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for SplitChannelOptions

source§

impl StructuralPartialEq for SplitChannelOptions

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.