pub struct ClientBuilder { /* private fields */ }Expand description
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new() -> Self
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}Sourcepub fn settings(self, s: Settings) -> Self
pub fn settings(self, s: Settings) -> Self
settings overrides the transport-level settings for this connection.
Sourcepub fn on_notify<F: Fn(Notification) + Send + 'static>(self, f: F) -> Self
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.
Sourcepub fn connect(self, keypair: Keypair, url: &str) -> Result<Client, Error>
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§
Auto Trait Implementations§
impl Freeze for ClientBuilder
impl !RefUnwindSafe for ClientBuilder
impl Send for ClientBuilder
impl !Sync for ClientBuilder
impl Unpin for ClientBuilder
impl UnsafeUnpin for ClientBuilder
impl !UnwindSafe for ClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more