pub struct EventLoop { /* private fields */ }Implementations§
Source§impl EventLoop
impl EventLoop
Sourcepub fn run(self) -> Result<(), Error>
pub fn run(self) -> Result<(), Error>
Examples found in repository?
examples/server.rs (line 73)
35fn main() {
36 nwep::init().unwrap_or_else(|e| {
37 eprintln!("init: {e}");
38 process::exit(1);
39 });
40
41 let key_file = std::env::var("NWEP_KEY_FILE").unwrap_or_else(|_| DEFAULT_KEY_FILE.into());
42 let keypair = load_or_generate_keypair(&key_file).unwrap_or_else(|e| {
43 eprintln!("keypair: {e}");
44 process::exit(1);
45 });
46
47 let node_id = keypair.node_id().unwrap_or_else(|e| {
48 eprintln!("node_id: {e}");
49 process::exit(1);
50 });
51 eprintln!("node id: {node_id}");
52
53 let mut router = Router::new();
54 router.handle_func("/hello", |w: &mut ResponseWriter, _r: &Request| {
55 let _ = w.respond("ok", b"hello from nwep-rust");
56 });
57
58 let addr = std::env::args().nth(1).unwrap_or_else(|| DEFAULT_ADDR.into());
59
60 let (server, event_loop) = ServerBuilder::new(&addr, keypair)
61 .on_connect(|info| eprintln!("connected: {}", info.node_id))
62 .on_disconnect(|info, code| eprintln!("disconnected: {} (code {code})", info.node_id))
63 .build(router)
64 .unwrap_or_else(|e| {
65 eprintln!("server: {e}");
66 process::exit(1);
67 });
68
69 let url = server.url("/hello");
70 eprintln!("listening on {}", server.addr());
71 println!("{url}"); // URL printed to stdout for the client to read
72
73 if let Err(e) = event_loop.run() {
74 eprintln!("server run: {e}");
75 process::exit(1);
76 }
77}Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventLoop
impl RefUnwindSafe for EventLoop
impl !Sync for EventLoop
impl Unpin for EventLoop
impl UnsafeUnpin for EventLoop
impl UnwindSafe for EventLoop
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