### Layer Trait: on_register_dispatch Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Performs late initialization when this layer is installed as a Subscriber. This is part of the Layer trait implementation. ```rust fn on_register_dispatch(&self, subscriber: &Dispatch) ``` -------------------------------- ### Any Trait: type_id Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Gets the TypeId of the implementing type. This is part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### PolicyExt::or - Combine Policies Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Creates a new Policy that returns Action::Follow if either self or other policies return Action::Follow. Requires both policies to be compatible with the same context. ```rust fn or(self, other: P) -> Or where T: Policy, P: Policy, ``` -------------------------------- ### PolicyExt::and - Combine Policies Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Creates a new Policy that returns Action::Follow only if both self and other policies return Action::Follow. Requires both policies to be compatible with the same context. ```rust fn and(self, other: P) -> And where T: Policy, P: Policy, ``` -------------------------------- ### TryFrom and TryInto for Conversions Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Enables fallible conversions between types using `try_from` and `try_into`. ```APIDOC ## TryFrom for T Trait ### Description Enables fallible conversion from type `U` into type `T`. ### Methods #### fn try_from(value: U) -> Result>::Error> Performs the conversion from `U` to `T`. ### Associated Types #### type Error = Infallible The type returned in the event of a conversion error. ## TryInto for T Trait ### Description Enables fallible conversion from type `T` into type `U`. ### Methods #### fn try_into(self) -> Result>::Error> Performs the conversion from `T` to `U`. ### Associated Types #### type Error = >::Error The type returned in the event of a conversion error. ``` -------------------------------- ### AuditLayer New Function Source: https://docs.rs/audit-layer/latest/src/audit_layer/lib.rs.html Constructor for the AuditLayer. It initializes the reqwest client and sets up the layer with the provided logging endpoint, credentials, and Tokio runtime handle. ```rust pub fn new( log_endpoint: String, username: String, password: String, runtime_handle: Handle, ) -> Self { let client = Arc::new(reqwest::Client::new()); Self { client, log_endpoint, username, password, runtime_handle, } } ``` -------------------------------- ### Create AuditLayer Instance Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Constructs a new AuditLayer instance. This layer works with the tracing system to capture and push audit logs to a specified logger over HTTP. ```rust pub fn new( log_endpoint: String, username: String, password: String, runtime_handle: Handle, ) -> Self ``` -------------------------------- ### AuditVisitor Visit Implementation Source: https://docs.rs/audit-layer/latest/src/audit_layer/lib.rs.html Implements the `Visit` trait for `AuditVisitor`. This method is called for each field in a traced event, allowing the visitor to record the field's value into the `json` map or specific fields like `message` and `audit`. ```rust impl Visit for AuditVisitor { fn record_bool(&mut self, field: &Field, value: bool) { if field.name() == "audit" { self.audit = value; } else { self.json.insert(field.name().to_owned(), json!(value)); } } fn record_str(&mut self, field: &Field, value: &str) { if field.name() == "message" { self.message = value.to_owned(); } else { self.json.insert(field.name().to_owned(), json!(value)); } } fn record_f64(&mut self, field: &Field, value: f64) { self.json.insert(field.name().to_owned(), json!(value)); } fn record_i64(&mut self, field: &Field, value: i64) { self.json.insert(field.name().to_owned(), json!(value)); } fn record_u64(&mut self, field: &Field, value: u64) { self.json.insert(field.name().to_owned(), json!(value)); } fn record_debug(&mut self, field: &Field, value: &dyn Debug) { if field.name() == "message" { self.message = format!("{value:?}"); } else { self.json .insert(field.name().to_owned(), json!(format!("{value:?}"))); } } } ``` -------------------------------- ### TryInto::try_into - Perform Conversion Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Performs a conversion from one type to another, returning a Result. This is the inverse of TryFrom. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### AuditLayer::new Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Creates a new AuditLayer instance. This layer integrates with the tracing system to capture and send audit logs to a specified endpoint via HTTP. ```APIDOC ## pub fn new( log_endpoint: String, username: String, password: String, runtime_handle: Handle, ) -> Self ### Description Create an audit layer that works with the tracing system to capture and push audit logs to the appropriate logger over HTTP ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```json { "log_endpoint": "http://example.com/audit", "username": "user", "password": "pass", "runtime_handle": "" } ``` ### Response #### Success Response (Self) - Returns an instance of `AuditLayer`. #### Response Example ```json { "message": "AuditLayer created successfully" } ``` ``` -------------------------------- ### TryFrom::try_from - Perform Conversion Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Performs a conversion from one type to another, returning a Result. This is used when a conversion might fail. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### From Trait: from Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Returns the argument unchanged. This is part of the From trait implementation. ```rust fn from(t: T) -> T ``` -------------------------------- ### WithSubscriber Trait Methods Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Allows attaching subscribers to types, enabling event dispatching. ```APIDOC ## WithSubscriber Trait ### Description Methods for attaching subscribers to types. ### Methods #### fn with_subscriber(self, subscriber: S) -> WithDispatch Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. #### fn with_current_subscriber(self) -> WithDispatch Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. ``` -------------------------------- ### AuditLayer Layer Implementation Source: https://docs.rs/audit-layer/latest/src/audit_layer/lib.rs.html Implements the tracing::Layer trait for AuditLayer. The `enabled` method always returns true to process all events, and `on_event` handles the recording and sending of audit logs. ```rust impl Layer for AuditLayer where S: Subscriber + for<'a> LookupSpan<'a>, { fn enabled(&self, _: &Metadata<'_>, _: Context<'_, S>) -> bool { true // log everything if it is auditable } fn on_event(&self, event: &Event<'_>, _: Context<'_, S>) { let mut visitor = AuditVisitor::default(); event.record(&mut visitor); if visitor.audit { visitor .json .insert("message".to_owned(), json!(visitor.message)); let req = self .client .post(&self.log_endpoint) .basic_auth(&self.username, Some(&self.password)) .json(&visitor.json); self.runtime_handle.spawn(async move { match req.send().await { Ok(r) => { if let Err(e) = r.error_for_status() { println!("{e}") } } Err(e) => eprintln!("Failed to send audit event: {}", e), } }); } } } ``` -------------------------------- ### WithSubscriber::with_subscriber - Attach Subscriber Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Attaches a provided Subscriber to the current type, returning a WithDispatch wrapper. The subscriber must be convertible into a Dispatch. ```rust fn with_subscriber(self, subscriber: S) -> WithDispatch where S: Into, ``` -------------------------------- ### PolicyExt Trait Methods Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Provides methods for composing policies, such as combining them with logical AND or OR operations. ```APIDOC ## PolicyExt Trait ### Description Methods for composing policies. ### Methods #### fn and(self, other: P) -> And Creates a new `Policy` that returns `Action::Follow` only if `self` and `other` return `Action::Follow`. #### fn or(self, other: P) -> Or Creates a new `Policy` that returns `Action::Follow` if either `self` or `other` returns `Action::Follow`. ``` -------------------------------- ### WithSubscriber::with_current_subscriber - Attach Default Subscriber Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Attaches the current default Subscriber to the type, returning a WithDispatch wrapper. This is a convenience method for attaching the globally configured subscriber. ```rust fn with_current_subscriber(self) -> WithDispatch ``` -------------------------------- ### AuditLayer Struct Definition Source: https://docs.rs/audit-layer/latest/src/audit_layer/lib.rs.html Defines the AuditLayer struct which holds the necessary components for capturing and sending audit logs. It includes fields for the HTTP client, authentication credentials, log endpoint, and a Tokio runtime handle. ```rust pub struct AuditLayer { client: Arc, username: String, password: String, log_endpoint: String, runtime_handle: Handle, } ``` -------------------------------- ### Layer Trait: enabled Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Determines if this layer is interested in a span or event based on its metadata and the current context. Similar to Subscriber::enabled. ```rust fn enabled(&self, _: &Metadata<'_>, _: Context<'_, S>) -> bool ``` -------------------------------- ### Define AuditLayer Struct Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Defines the AuditLayer struct, which is used for capturing and pushing audit logs. It has private fields. ```rust pub struct AuditLayer { /* private fields */ } ``` -------------------------------- ### Layer Trait: and_then Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Composes this layer around another given Layer, returning a Layered struct that implements Layer. This is a convenience method for chaining layers. ```rust fn and_then(self, layer: L) -> Layered where L: Layer, Self: Sized, ``` -------------------------------- ### AuditVisitor Struct Definition Source: https://docs.rs/audit-layer/latest/src/audit_layer/lib.rs.html Defines the AuditVisitor struct, which implements the tracing::field::Visit trait. It's used to extract and format event data into a JSON structure for audit logging. ```rust struct AuditVisitor { message: String, json: Map, audit: bool, } ``` -------------------------------- ### Layer Trait: on_layer Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Performs late initialization when attaching a Layer to a Subscriber. This method is part of the Layer trait implementation for AuditLayer. ```rust fn on_layer(&mut self, subscriber: &mut S) ``` -------------------------------- ### Layer Trait: on_enter Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Notifies the layer that a span with the given ID was entered. This is part of the Layer trait implementation. ```rust fn on_enter(&self, _id: &Id, _ctx: Context<'_, S>) ``` -------------------------------- ### Layer Trait: on_follows_from Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Notifies the layer that a span recorded a 'follows from' relationship with another span. This is part of the Layer trait implementation. ```rust fn on_follows_from(&self, _span: &Id, _follows: &Id, _ctx: Context<'_, S>) ``` -------------------------------- ### Layer Trait: register_callsite Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Registers a new callsite with this layer and returns whether the layer is interested in notifications about it. Similar to Subscriber::register_callsite. ```rust fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest ``` -------------------------------- ### Layer Trait: with_subscriber Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Composes this Layer with a given Subscriber, returning a Layered struct that implements Subscriber. This is used for integrating a layer into a subscriber. ```rust fn with_subscriber(self, inner: S) -> Layered where Self: Sized, ``` -------------------------------- ### Layer Trait: on_event Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Callback function that is invoked when an event occurs within the tracing system. This method is part of the Layer trait implementation for AuditLayer. ```rust fn on_event(&self, event: &Event<'_>, _: Context<'_, S>) ``` -------------------------------- ### Layer Trait: on_record Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Notifies the layer that a span recorded specific values. This method is part of the Layer trait implementation for AuditLayer. ```rust fn on_record(&self, _span: &Id, _values: &Record<'_>, _ctx: Context<'_, S>) ``` -------------------------------- ### Layer Trait: with_filter Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Combines this layer with a Filter, returning a Filtered layer. This allows for conditional application of the layer's logic. ```rust fn with_filter(self, filter: F) -> Filtered where Self: Sized, F: Filter, ``` -------------------------------- ### Instrument Trait: instrument Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Instruments this type with the provided Span, returning an Instrumented wrapper. This is used for adding span context to operations. ```rust fn instrument(self, span: Span) -> Instrumented ``` -------------------------------- ### Borrow Trait: borrow Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Immutably borrows from an owned value. This is part of the Borrow trait implementation. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### Layer Trait: on_new_span Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Notifies the layer that a new span has been constructed with the given attributes and ID. This is part of the Layer trait implementation. ```rust fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) ``` -------------------------------- ### Instrument Trait: in_current_span Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Instruments this type with the current Span, returning an Instrumented wrapper. This is useful for automatically associating operations with the current tracing context. ```rust fn in_current_span(self) -> Instrumented ``` -------------------------------- ### Layer Trait: on_exit Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Notifies the layer that the span with the given ID was exited. This method is part of the Layer trait implementation for AuditLayer. ```rust fn on_exit(&self, _id: &Id, _ctx: Context<'_, S>) ``` -------------------------------- ### Layer Trait: event_enabled Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Called before on_event to determine if on_event should be invoked. This method is part of the Layer trait implementation for AuditLayer. ```rust fn event_enabled(&self, _event: &Event<'_>, _ctx: Context<'_, S>) -> bool ``` -------------------------------- ### Layer Trait: on_close Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Notifies the layer that the span with the given ID has been closed. This is part of the Layer trait implementation. ```rust fn on_close(&self, _id: Id, _ctx: Context<'_, S>) ``` -------------------------------- ### Layer Trait: boxed Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Erases the type of this Layer, returning a Boxed dyn Layer trait object. This is useful for dynamic dispatch and when the concrete layer type is not known at compile time. ```rust fn boxed(self) -> Box + Sync + Send> where Self: Sized + Layer + Send + Sync + 'static, S: Subscriber, ``` -------------------------------- ### BorrowMut Trait: borrow_mut Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Mutably borrows from an owned value. This is part of the BorrowMut trait implementation. ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### Layer Trait: on_id_change Source: https://docs.rs/audit-layer/latest/audit_layer/struct.AuditLayer.html Notifies the layer that a span ID has been cloned and the subscriber returned a different ID. This method is part of the Layer trait implementation for AuditLayer. ```rust fn on_id_change(&self, _old: &Id, _new: &Id, _ctx: Context<'_, S>) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.