#[non_exhaustive]pub struct Event<'a> {
pub kind: EventKind,
pub id: RequestId,
pub route: Option<&'a str>,
pub status: u16,
pub code: &'static str,
pub source: Option<&'a (dyn Error + 'static)>,
}Expand description
One event.
use std::sync::{Arc, Mutex};
use web_net::{App, Event, Events, get};
#[derive(Default)]
struct Codes(Mutex<Vec<(u16, &'static str)>>);
impl Events for Codes {
fn event(&self, e: &Event<'_>) {
self.0.lock().unwrap().push((e.status, e.code));
}
}
let codes = Arc::new(Codes::default());
let app = App::builder().events(Arc::clone(&codes)).route(get("/", |cx| cx.text(200, "hi"))).build()?;
serve_net::testing::respond(&app, b"GET /missing HTTP/1.1\r\nHost: localhost\r\n\r\n");
assert_eq!(*codes.0.lock().unwrap(), [(404, "route.none")]);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.kind: EventKindWhat happened.
id: RequestIdThe request’s reference.
route: Option<&'a str>The matched route’s pattern, if routing got that far.
status: u16The status answered.
code: &'static strA stable code ("url.encoded_slash", a gate’s code, a handler’s).
source: Option<&'a (dyn Error + 'static)>The underlying error, for the logs only.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Event<'a>
impl<'a> !Send for Event<'a>
impl<'a> !Sync for Event<'a>
impl<'a> !UnwindSafe for Event<'a>
impl<'a> Forget for Event<'a>
impl<'a> Freeze for Event<'a>
impl<'a> Move for Event<'a>
impl<'a> Unpin for Event<'a>
impl<'a> UnsafeUnpin for Event<'a>
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