s2n_quic/provider/event/
mod.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Allows endpoints to subscribe to connection-level and endpoint-level events
5
6use cfg_if::cfg_if;
7pub use s2n_quic_core::{
8    endpoint::Location,
9    event::{
10        api as events,
11        api::{ConnectionInfo, ConnectionMeta},
12        supervisor, Event, Meta, Subscriber, Timestamp,
13    },
14    query,
15};
16
17/// Provides event handling support for an endpoint
18pub trait Provider {
19    type Subscriber: 'static + Subscriber;
20    type Error: 'static + core::fmt::Display + Send + Sync;
21
22    fn start(self) -> Result<Self::Subscriber, Self::Error>;
23}
24
25/// Provides an implementation to disable all events
26pub mod disabled;
27
28/// This module contains event integration with [`tracing`](https://docs.rs/tracing)
29#[cfg(any(feature = "provider-event-tracing", test))]
30pub mod tracing;
31
32/// Provides an implementation to emit perf metrics to the console
33#[cfg(feature = "provider-event-console-perf")]
34pub mod console_perf;
35
36cfg_if! {
37    if #[cfg(any(feature = "provider-event-tracing", test))] {
38        pub use self::tracing as default;
39    } else {
40        // Events are disabled by default.
41        pub use self::disabled as default;
42    }
43}
44
45pub use default::Provider as Default;
46
47impl<S> Provider for S
48where
49    S: 'static + Subscriber,
50{
51    type Subscriber = S;
52    type Error = core::convert::Infallible;
53
54    fn start(self) -> Result<S, Self::Error> {
55        Ok(self)
56    }
57}
58
59impl_provider_utils!();