Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder { /* private fields */ }
Expand description

ClientBuilder constructs and connects a NWEP Client.

Use new to start with defaults, configure the connection with builder methods, then call connect to establish the QUIC session.

Implementations§

Source§

impl ClientBuilder

Source

pub fn new() -> Self

new creates a ClientBuilder with default Settings and no notification handler.

Examples found in repository?
examples/client.rs (line 29)
4fn main() {
5    let url = std::env::args().nth(1).unwrap_or_else(|| {
6        eprintln!("usage: client <web://url/path>");
7        process::exit(1);
8    });
9
10    nwep::init().unwrap_or_else(|e| {
11        eprintln!("init: {e}");
12        process::exit(1);
13    });
14
15    nwep::log::set_level(nwep::log::LogLevel::Warn);
16    nwep::log::set_stderr(true);
17
18    let parsed = Url::parse(&url).unwrap_or_else(|e| {
19        eprintln!("parse url: {e}");
20        process::exit(1);
21    });
22    let path = if parsed.path.is_empty() { "/".to_string() } else { parsed.path.clone() };
23
24    let keypair = Keypair::generate().unwrap_or_else(|e| {
25        eprintln!("keygen: {e}");
26        process::exit(1);
27    });
28
29    let client = ClientBuilder::new()
30        .connect(keypair, &url)
31        .unwrap_or_else(|e| {
32            eprintln!("connect: {e}");
33            process::exit(1);
34        });
35
36    let resp = client.get(&path).unwrap_or_else(|e| {
37        eprintln!("get: {e}");
38        process::exit(1);
39    });
40
41    println!("{}", resp.status);
42    println!("{}", String::from_utf8_lossy(&resp.body));
43
44    client.close();
45}
Source

pub fn settings(self, s: Settings) -> Self

settings overrides the transport-level settings for this connection.

Source

pub fn on_notify<F: Fn(Notification) + Send + 'static>(self, f: F) -> Self

on_notify registers a callback to receive server-push Notification messages.

The callback is invoked on the event loop thread; it must not block or panic.

Source

pub fn connect(self, keypair: Keypair, url: &str) -> Result<Client, Error>

connect initiates a connection to the given web:// URL and blocks until the QUIC + NWEP mutual-authentication handshake completes.

On success returns a Client handle ready for requests. On failure the event loop and socket threads are torn down automatically.

§Errors

Returns Err if the URL is invalid, the socket cannot be bound, the C layer fails to initialise, or the handshake is rejected by the remote server.

Examples found in repository?
examples/client.rs (line 30)
4fn main() {
5    let url = std::env::args().nth(1).unwrap_or_else(|| {
6        eprintln!("usage: client <web://url/path>");
7        process::exit(1);
8    });
9
10    nwep::init().unwrap_or_else(|e| {
11        eprintln!("init: {e}");
12        process::exit(1);
13    });
14
15    nwep::log::set_level(nwep::log::LogLevel::Warn);
16    nwep::log::set_stderr(true);
17
18    let parsed = Url::parse(&url).unwrap_or_else(|e| {
19        eprintln!("parse url: {e}");
20        process::exit(1);
21    });
22    let path = if parsed.path.is_empty() { "/".to_string() } else { parsed.path.clone() };
23
24    let keypair = Keypair::generate().unwrap_or_else(|e| {
25        eprintln!("keygen: {e}");
26        process::exit(1);
27    });
28
29    let client = ClientBuilder::new()
30        .connect(keypair, &url)
31        .unwrap_or_else(|e| {
32            eprintln!("connect: {e}");
33            process::exit(1);
34        });
35
36    let resp = client.get(&path).unwrap_or_else(|e| {
37        eprintln!("get: {e}");
38        process::exit(1);
39    });
40
41    println!("{}", resp.status);
42    println!("{}", String::from_utf8_lossy(&resp.body));
43
44    client.close();
45}

Trait Implementations§

Source§

impl Default for ClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a 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.