### Usage Example: #[hotpath::measure_all] and #[hotpath::skip] (Rust) Source: https://docs.rs/hotpath/0.9.0/hotpath/attr.skip_search= This example demonstrates the practical application of #[hotpath::measure_all] for bulk instrumentation and #[hotpath::skip] for excluding specific methods from being measured. It shows how to apply these macros within an `impl` block for a struct. The code illustrates that `important_method` will be profiled, while `not_so_important_method` will be skipped. ```Rust #[hotpath::measure_all] impl MyStruct { fn important_method(&self) { // This will be measured } #[hotpath::skip] fn not_so_important_method(&self) -> usize { // This will NOT be measured self.value } } ``` -------------------------------- ### FuturesGuardBuilder Constructor and Builder Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/futures/struct.FuturesGuardBuilder_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the implementation for FuturesGuardBuilder, including the 'new' constructor to create an instance, the 'format' method to set a format (though unused in this example), and the 'build' method to finalize the construction of a FuturesGuard. ```rust pub fn new() -> Self pub fn format(self, _format: Format) -> Self pub fn build(self) -> FuturesGuard ``` -------------------------------- ### Generic TryFrom Usage Example Source: https://docs.rs/hotpath/0.9.0/hotpath/enum.Format_search=u32+-%3E+bool Illustrates the generic usage of the `try_from` method, particularly when converting `u32` to `bool` within various `hotpath` components. ```rust /// Example for hotpath::MeasurementGuard::try_from // U -> Result // where u32 matches U // bool matches T let result: Result = MeasurementGuard::try_from(some_u32_value); /// Example for hotpath::Format::try_from // U -> Result // where u32 matches U // bool matches T let format_result: Result = Format::try_from(some_u32_value); ``` -------------------------------- ### Initialize hotpath Profiling with `main` Macro Source: https://docs.rs/hotpath/0.9.0/hotpath/attr.main The `#[hotpath::main]` attribute macro initializes the hotpath profiling system. It should be applied to the main function to enable profiling, creating a guard that starts a measurement processing thread and displays a performance summary upon program exit. It also creates a measurement guard for the wrapper function itself. Parameters include `percentiles`, `format`, `limit`, and `timeout`. ```rust #[hotpath::main] fn main() { // Your code here } ``` ```rust #[tokio::main] #[hotpath::main(percentiles = [50, 90, 95, 99])] async fn main() { // Your code here } ``` ```rust #[hotpath::main(format = "json-pretty")] fn main() { // Your code here } ``` ```rust #[hotpath::main(percentiles = [50, 99], format = "json")] fn main() { // Your code here } ``` ```rust #[hotpath::main(limit = 20)] fn main() { // Your code here } ``` ```rust #[tokio::main] #[hotpath::main] async fn main() { // Your code here } ``` -------------------------------- ### ChannelsGuard Constructor and Formatting Source: https://docs.rs/hotpath/0.9.0/hotpath/channels/struct.ChannelsGuard_search= This section details how to create a new instance of ChannelsGuard and apply formatting options. ```APIDOC ## POST /channels/guard ### Description Creates a new instance of ChannelsGuard and optionally applies a format. ### Method POST ### Endpoint /channels/guard ### Parameters #### Query Parameters - **format** (Format) - Optional - Specifies the formatting to be applied to the ChannelsGuard. ### Request Body This endpoint does not require a request body. ### Request Example ```json { "message": "No request body needed" } ``` ### Response #### Success Response (200) - **ChannelsGuard** (object) - A new instance of ChannelsGuard. #### Response Example ```json { "guard_instance": "ChannelsGuard_instance_id" } ``` ``` -------------------------------- ### Type Mismatch Example: u32 to bool in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/futures/struct.FuturesGuard_search=u32+-%3E+bool This example illustrates a common scenario in Rust where a function signature expects a generic type `T`, but the provided value matches a different type, such as `u32` being passed where `bool` is expected as `T`. This often occurs in generic function calls or trait implementations where type constraints are not perfectly met. ```rust // Example scenario highlighting the type mismatch // This is conceptual and depends on the actual function context. // let result: bool = hotpath::some_function(10u32); // This would fail if 10u32 does not match the expected generic type T which is bool. ``` -------------------------------- ### Get TypeId of ChannelsGuardBuilder in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/channels/struct.ChannelsGuardBuilder_search=std%3A%3Avec Implements the Any trait, providing a method to retrieve the TypeId of the ChannelsGuardBuilder instance. This is useful for runtime type checks. ```Rust fn type_id(&self) -> TypeId; ``` -------------------------------- ### Create MeasurementGuardWithLog Instance (Rust) Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog These functions demonstrate how to create instances of MeasurementGuardWithLog. `new` takes a name, wrapper flag, and async unsupported flag, while `build` takes a name, wrapper flag, and async flag. ```rust pub fn new( _name: &'static str, _wrapper: bool, _unsupported_async: bool, ) -> Self ``` ```rust pub fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self ``` -------------------------------- ### TryFrom and TryInto Trait Implementations Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog Documentation for the blanket implementations of `TryFrom` and `TryInto` traits. ```APIDOC ## Blanket Implementations ### impl TryFrom for T where U: Into #### `type Error = Infallible` The type returned in the event of a conversion error. #### `fn try_from(value: U) -> Result>::Error>` Performs the conversion. - **`value`** (`U`) - The value to convert. - **Returns** (`Result>::Error>`) - A `Result` containing the converted value or an error. ``` ```APIDOC ### impl TryInto for T where U: TryFrom #### `type Error = >::Error` The type returned in the event of a conversion error. #### `fn try_into(self) -> Result>::Error>` Performs the conversion. - **`self`** (`T`) - The value to convert. - **Returns** (`Result>::Error>`) - A `Result` containing the converted value or an error. ``` -------------------------------- ### Apply `measure_all` to a Rust module Source: https://docs.rs/hotpath/0.9.0/hotpath/attr.measure_all_search= The `measure_all` attribute macro from the `hotpath` crate can be applied to a Rust module to automatically instrument all functions within that module with the `measure` macro. This streamlines the profiling setup for multiple functions. ```Rust #[hotpath::measure_all] mod my_module { fn function_one() { // This will be automatically measured } fn function_two() { // This will also be automatically measured } } ``` -------------------------------- ### TryFrom Implementations Source: https://docs.rs/hotpath/0.9.0/hotpath/trait.MetricsProvider_search=u32+-%3E+bool Details on the `try_from` method implementations across different types in the hotpath crate, particularly concerning generic type conversions. ```APIDOC ## TryFrom Method Implementations ### Description Provides details on the `try_from` method used for converting between different types, especially in the context of measurement guards and builders. ### Method Signatures - **hotpath::MeasurementGuard::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::MeasurementGuardWithLog::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::HotPath::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::FunctionsGuardBuilder::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::Format::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::FunctionStats::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::channels::ChannelsGuardBuilder::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::channels::ChannelsGuard::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::futures::FuturesGuardBuilder::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::futures::FuturesGuard::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::streams::StreamsGuardBuilder::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` - **hotpath::streams::StreamsGuard::try_from** - Signature: `U -> Result` - Constraints: `u32` matches `U`, `bool` matches `T` ``` -------------------------------- ### Type Mismatch Example: u32 to bool in measure_with_log_async in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/streams/struct.StreamsGuard_search=u32+-%3E+bool Shows a type mismatch in the measure_with_log_async function signature in Rust, where u32 is matched with F and bool with T. Similar to measure_with_log, this highlights a specific generic type usage. ```rust // Example from hotpath::measure_with_log_async // where u32 matches F and bool matches T fn measure_with_log_async(_: &str, _: F) -> T where F: Into { /* ... */ } ``` -------------------------------- ### Initialize Hotpath Profiling with #[main] Source: https://docs.rs/hotpath/0.9.0/hotpath/attr.main_search= The `#[main]` attribute macro initializes the hotpath profiling system. It should be applied to the main function to enable profiling, automatically generating a performance report on program exit. Parameters can be configured to customize the report's percentiles, format, and displayed function limit. ```rust #[hotpath::main] fn main() { // Your code here } ``` ```rust #[hotpath::main(percentiles = [50, 90, 95, 99])] async fn main() { // Your code here } ``` ```rust #[hotpath::main(format = "json-pretty")] fn main() { // Your code here } ``` ```rust #[hotpath::main(percentiles = [50, 99], format = "json")] fn main() { // Your code here } ``` ```rust #[hotpath::main(limit = 20)] fn main() { // Your code here } ``` -------------------------------- ### Implement Default for FuturesGuardBuilder in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/futures/struct.FuturesGuardBuilder_search=u32+-%3E+bool This code implements the Default trait for the FuturesGuardBuilder struct. This allows creating a default instance of FuturesGuardBuilder using the ::default() method, providing a standard starting point for building futures guards. ```rust impl Default for FuturesGuardBuilder { fn default() -> Self { // Implementation details for default value } } ``` -------------------------------- ### Rust StreamsGuardBuilder and StreamsGuard Implementation Source: https://docs.rs/hotpath/0.9.0/src/hotpath/lib_off.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Implements the builder and guard for streams. Similar to channels, the StreamsGuardBuilder facilitates stream setup with formatting options, and the StreamsGuard manages stream resources, ensuring proper cleanup via the Drop trait. ```rust pub mod streams { use super::Format; pub struct StreamsGuardBuilder; impl StreamsGuardBuilder { pub fn new() -> Self { Self } pub fn format(self, _format: Format) -> Self { self } pub fn build(self) -> StreamsGuard { StreamsGuard } } impl Default for StreamsGuardBuilder { fn default() -> Self { Self::new() } } pub struct StreamsGuard; impl StreamsGuard { pub fn new() -> Self { Self } pub fn format(self, _format: Format) -> Self { self } } impl Default for StreamsGuard { fn default() -> Self { Self::new() } } impl Drop for StreamsGuard { fn drop(&mut self) {} } } ``` -------------------------------- ### Implement StreamsGuardBuilder Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/streams/struct.StreamsGuardBuilder_search=std%3A%3Avec Provides core methods for the StreamsGuardBuilder, including `new` for creating an instance, `format` for setting the format, and `build` for constructing a StreamsGuard. These methods facilitate the fluent configuration of StreamsGuard objects. ```rust pub fn new() -> Self ``` ```rust pub fn format(self, _format: Format) -> Self ``` ```rust pub fn build(self) -> StreamsGuard ``` -------------------------------- ### Type Mismatch Example: u32 to bool in measure_with_log in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/streams/struct.StreamsGuard_search=u32+-%3E+bool Illustrates a type mismatch in the measure_with_log function signature in Rust, where u32 is matched with the generic parameter F and bool with T. This suggests a specific intended usage or a potential point of confusion. ```rust // Example from hotpath::measure_with_log // where u32 matches F and bool matches T fn measure_with_log(_: &str, _: bool, _: bool, _: F) -> T where F: Into { /* ... */ } ``` -------------------------------- ### try_from method for various types Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog_search=u32+-%3E+bool Demonstrates the usage of the `try_from` method for different types within the hotpath library, highlighting type compatibility and potential conversion errors. ```APIDOC ## Method: try_from ### Description Attempts to convert a value from one type to another. This is used across various components of the `hotpath` library, including `MeasurementGuard`, `MeasurementGuardWithLog`, `HotPath`, `FunctionsGuardBuilder`, `Format`, `FunctionStats`, and channel/future/stream related guards. ### Method Signature Examples #### `hotpath::MeasurementGuard::try_from` - **Parameters**: - `U`: A type that can be converted into `T`. In the context of the provided signature, `u32` matches `U`. - `T`: The target type. In the context of the provided signature, `bool` matches `T`. #### `hotpath::MeasurementGuardWithLog::try_from` - **Parameters**: - `U`: A type that can be converted into `T`. In the context of the provided signature, `u32` matches `U`. - `T`: The target type. In the context of the provided signature, `bool` matches `T`. (Similar signatures apply to `HotPath`, `FunctionsGuardBuilder`, `Format`, `FunctionStats`, `ChannelsGuardBuilder`, `ChannelsGuard`, `FuturesGuardBuilder`, `FuturesGuard`, `StreamsGuardBuilder`, and `StreamsGuard`) ### Return Value - `Result>::Error>`: Returns `Ok(T)` if the conversion is successful, otherwise returns an error. ### Type Mismatch Example - **Error**: `"Type \"bool\" not found and used as generic parameter."` This error indicates that a `bool` type was expected or used in a context where it was not compatible, likely during a `try_from` operation where the generic type `T` was intended to be `bool` but the provided type was different. ``` -------------------------------- ### StreamsGuardBuilder Constructor and Methods Source: https://docs.rs/hotpath/0.9.0/hotpath/streams/struct.StreamsGuardBuilder Provides the public API for the StreamsGuardBuilder. It includes a constructor `new` to create an instance, a `format` method to set the desired format, and a `build` method to construct the final StreamsGuard object. ```rust pub fn new() -> Self ``` ```rust pub fn format(self, _format: Format) -> Self ``` ```rust pub fn build(self) -> StreamsGuard ``` -------------------------------- ### Type Mismatch Example: u32 vs bool in Function Signatures (Rust) Source: https://docs.rs/hotpath/0.9.0/hotpath/channels/struct.ChannelsGuard_search=u32+-%3E+bool Illustrates a common pattern of type mismatches found in function signatures within the hotpath crate. Specifically, it highlights scenarios where a function expects a generic type `T` but receives `bool` when `u32` was intended, as seen in various `try_from` methods and measurement functions. ```rust // Example of a function signature with potential type mismatch // where `u32` is expected but `bool` might be inferred or passed. // This is a conceptual representation based on the summary provided. // fn some_function(input: U) -> Result // where u32 matches U, // bool matches T // The actual functions demonstrating this pattern include: // hotpath::channels::ChannelsGuard::try_from // hotpath::measure_with_log // hotpath::measure_with_log_async // and others listed in the summary. ``` -------------------------------- ### From and Into Trait Implementations Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog Documentation for the blanket implementations of `From` and `Into` traits. ```APIDOC ## Blanket Implementations ### impl From for T #### `fn from(t: T) -> T` Returns the argument unchanged. - **`t`** (`T`) - The value to convert. - **Returns** (`T`) - The converted value. ### impl Into for T where U: From #### `fn into(self) -> U` Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. - **`self`** (`T`) - The value to convert. - **Returns** (`U`) - The converted value. ``` -------------------------------- ### StreamsGuardBuilder Blanket Implementations (Any, Borrow, From, Into, TryFrom, TryInto) Source: https://docs.rs/hotpath/0.9.0/hotpath/streams/struct.StreamsGuardBuilder Illustrates various blanket implementations for StreamsGuardBuilder, demonstrating its compatibility with generic Rust features. This includes `Any` for type identification, `Borrow` and `BorrowMut` for referencing, `From` and `Into` for conversions, and `TryFrom` and `TryInto` for fallible conversions. ```rust impl Any for T where T: 'static + ?Sized, fn type_id(&self) -> TypeId ``` ```rust impl Borrow for T where T: ?Sized, fn borrow(&self) -> &T ``` ```rust impl BorrowMut for T where T: ?Sized, fn borrow_mut(&mut self) -> &mut T ``` ```rust impl From for T fn from(t: T) -> T ``` ```rust impl Into for T where U: From, fn into(self) -> U ``` ```rust impl TryFrom for T where U: Into, type Error = Infallible fn try_from(value: U) -> Result>::Error> ``` ```rust impl TryInto for T where U: TryFrom, type Error = >::Error fn try_into(self) -> Result>::Error> ``` -------------------------------- ### StreamsGuardBuilder Methods - Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/streams/struct.StreamsGuardBuilder_search= Provides implementations for key methods of StreamsGuardBuilder. `new()` creates an instance, `format()` configures the builder, and `build()` finalizes the creation of a StreamsGuard object. ```rust impl StreamsGuardBuilder { pub fn new() -> Self { /* ... */ } pub fn format(self, _format: Format) -> Self { /* ... */ } pub fn build(self) -> StreamsGuard { /* ... */ } } ``` -------------------------------- ### Implement StreamsGuardBuilder Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/streams/struct.StreamsGuardBuilder_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides implementations for key methods of the StreamsGuardBuilder, including a constructor 'new', a 'format' method for setting format, and a 'build' method to finalize the StreamsGuard creation. ```rust impl StreamsGuardBuilder { pub fn new() -> Self pub fn format(self, _format: Format) -> Self pub fn build(self) -> StreamsGuard } ``` -------------------------------- ### Rust: Implement ChannelsGuardBuilder Source: https://docs.rs/hotpath/0.9.0/src/hotpath/lib_off.rs Defines the ChannelsGuardBuilder struct and its associated methods in Rust. This includes creating a new builder, setting a format, and building the ChannelsGuard. It also implements the Default trait for easy initialization. ```rust pub struct ChannelsGuardBuilder; impl ChannelsGuardBuilder { pub fn new() -> Self { Self } pub fn format(self, _format: Format) -> Self { self } pub fn build(self) -> ChannelsGuard { ChannelsGuard } } impl Default for ChannelsGuardBuilder { fn default() -> Self { Self::new() } } ``` -------------------------------- ### Blanket Implementations Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuard_search= Documentation for blanket implementations available for MeasurementGuard. ```APIDOC ## Blanket Implementations ### `impl Any for T where T: 'static + ?Sized` #### `fn type_id(&self) -> TypeId` ##### Description Gets the `TypeId` of `self`. ### `impl Borrow for T where T: ?Sized` #### `fn borrow(&self) -> &T` ##### Description Immutably borrows from an owned value. ### `impl BorrowMut for T where T: ?Sized` #### `fn borrow_mut(&mut self) -> &mut T` ##### Description Mutably borrows from an owned value. ### `impl From for T` #### `fn from(t: T) -> T` ##### Description Returns the argument unchanged. ### `impl Into for T where U: From` #### `fn into(self) -> U` ##### Description Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ### `impl TryFrom for T where U: Into` #### `type Error = Infallible` ##### Description The type returned in the event of a conversion error. #### `fn try_from(value: U) -> Result>::Error>` ##### Description Performs the conversion. ### `impl TryInto for T where U: TryFrom` #### `type Error = >::Error` ##### Description The type returned in the event of a conversion error. #### `fn try_into(self) -> Result>::Error>` ##### Description Performs the conversion. ``` -------------------------------- ### Implement MeasurementGuard Constructor Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuard Provides methods for creating instances of MeasurementGuard. `new` takes a name, a boolean for wrapper status, and a boolean for unsupported async status. `build` takes a name, wrapper status, and async status. `build_with_timeout` takes an existing MeasurementGuard instance and a duration to configure a timeout. ```rust pub fn new( _name: &'static str, _wrapper: bool, _unsupported_async: bool, ) -> Self ``` ```rust pub fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self ``` ```rust pub fn build_with_timeout(self, _duration: Duration) ``` -------------------------------- ### ChannelsGuardBuilder Methods Source: https://docs.rs/hotpath/0.9.0/hotpath/channels/struct.ChannelsGuardBuilder_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for the methods available on the ChannelsGuardBuilder struct. ```APIDOC ## ChannelsGuardBuilder Methods ### Description Provides methods to configure and build a `ChannelsGuard`. ### Methods #### `new()` - **Description**: Creates a new instance of `ChannelsGuardBuilder`. - **Returns**: `Self` (a new `ChannelsGuardBuilder` instance). #### `format(self, _format: Format)` - **Description**: Sets the format for the ChannelsGuard. - **Parameters**: - `_format` (Format): The desired format. - **Returns**: `Self` (the modified `ChannelsGuardBuilder` instance). #### `build(self)` - **Description**: Builds the `ChannelsGuard`. - **Returns**: `ChannelsGuard` (the constructed ChannelsGuard instance). ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog Documentation for the blanket implementation of the `Any` trait for `T` where `T` is `'static + ?Sized`. ```APIDOC ## Blanket Implementations ### impl Any for T where T: 'static + ?Sized #### `fn type_id(&self) -> TypeId` Gets the `TypeId` of `self`. - **`self`** (`&T`) - A reference to the value. - **Returns** (`TypeId`) - The `TypeId` of the value. ``` -------------------------------- ### Blanket Implementations Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog_search= Shows blanket implementations for common traits like Any, Borrow, From, Into, and TryFrom/TryInto. ```APIDOC ## Blanket Implementations ### impl Any for T #### Description Provides the `type_id` method for any type `T` that is `'static` and sized. #### Source Code ```rust fn type_id(&self) -> TypeId ``` ### impl Borrow for T #### Description Provides the `borrow` method for immutable borrowing. #### Source Code ```rust fn borrow(&self) -> &T ``` ### impl BorrowMut for T #### Description Provides the `borrow_mut` method for mutable borrowing. #### Source Code ```rust fn borrow_mut(&mut self) -> &mut T ``` ### impl From for T #### Description Provides the `from` method, which returns the argument unchanged. #### Source Code ```rust fn from(t: T) -> T ``` ### impl Into for T #### Description Provides the `into` method, which calls `U::from(self)`. #### Source Code ```rust fn into(self) -> U ``` ### impl TryFrom for T #### Description Provides the `try_from` method for fallible conversions. The associated `Error` type is `Infallible`. #### Source Code ```rust type Error = Infallible fn try_from(value: U) -> Result>::Error> ``` ### impl TryInto for T #### Description Provides the `try_into` method for fallible conversions. The associated `Error` type is derived from `U`'s `TryFrom` implementation. #### Source Code ```rust type Error = >::Error fn try_into(self) -> Result>::Error> ``` ``` -------------------------------- ### MeasurementGuardWithLog Methods Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog_search= Provides methods for creating and managing MeasurementGuardWithLog instances. ```APIDOC ## impl MeasurementGuardWithLog ### fn new #### Description Creates a new `MeasurementGuardWithLog` instance. #### Parameters * `_name` ( &'static str ) - Required - The name of the measurement. * `_wrapper` ( bool ) - Required - Indicates if this guard is a wrapper. * `_unsupported_async` ( bool ) - Required - Indicates if async is unsupported. #### Source Code ```rust pub fn new( _name: &'static str, _wrapper: bool, _unsupported_async: bool, ) -> Self ``` ### fn build #### Description Builds a `MeasurementGuardWithLog` instance with specified parameters. #### Parameters * `_name` ( &'static str ) - Required - The name for the measurement. * `_wrapper` ( bool ) - Required - Specifies if the guard is a wrapper. * `_is_async` ( bool ) - Required - Indicates if the operation is asynchronous. #### Source Code ```rust pub fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self ``` ### fn finish_with_result #### Description Finalizes the measurement and logs the result. #### Parameters * `self` ( MeasurementGuardWithLog ) - Required - The measurement guard instance. * `_result` ( &T ) - Required - A reference to the result to be logged. `T` must implement `Debug`. #### Source Code ```rust pub fn finish_with_result(self, _result: &T) ``` ``` -------------------------------- ### ChannelsGuardBuilder API Source: https://docs.rs/hotpath/0.9.0/hotpath/channels/struct.ChannelsGuardBuilder Documentation for the ChannelsGuardBuilder struct, including its constructor and methods for configuring channel guards. ```APIDOC ## Struct ChannelsGuardBuilder ### Description A builder for creating `ChannelsGuard` instances. ### Methods #### `new()` - **Description**: Creates a new `ChannelsGuardBuilder` instance. - **Returns**: `Self` (a new `ChannelsGuardBuilder`) #### `format(self, _format: Format)` - **Description**: Sets the format for the channel guard. The `_format` parameter is currently unused. - **Parameters**: - `_format` (Format) - The desired format for the channel guard. - **Returns**: `Self` (the modified `ChannelsGuardBuilder`) #### `build(self) -> ChannelsGuard` - **Description**: Constructs and returns a `ChannelsGuard` instance using the configured builder settings. - **Returns**: `ChannelsGuard` ### Default Implementation #### `default() -> Self` - **Description**: Returns the default value for `ChannelsGuardBuilder`. - **Returns**: `Self` (a default `ChannelsGuardBuilder`) ``` -------------------------------- ### GuardBuilder Implementation Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/type.GuardBuilder_search=u32+-%3E+bool Details the public methods available for implementing the 'FunctionsGuardBuilder' (formerly 'GuardBuilder'). These methods allow configuration of percentiles, format, limits, and building the final 'HotPath' object, including timeout and reporter options. ```Rust pub fn new(_caller_name: impl Into) -> Self ``` ```Rust pub fn percentiles(self, _percentiles: &[u8]) -> Self ``` ```Rust pub fn format(self, _format: Format) -> Self ``` ```Rust pub fn limit(self, _limit: usize) -> Self ``` ```Rust pub fn build(self) -> HotPath ``` ```Rust pub fn build_with_timeout(self, _duration: Duration) -> HotPath ``` ```Rust pub fn reporter(self, _reporter: Box) -> Self ``` -------------------------------- ### Rust: Implement FuturesGuardBuilder Source: https://docs.rs/hotpath/0.9.0/src/hotpath/lib_off.rs Defines the FuturesGuardBuilder struct and its associated methods in Rust. This includes creating a new builder, setting a format, and building the FuturesGuard. It also implements the Default trait for easy initialization. ```rust pub struct FuturesGuardBuilder; impl FuturesGuardBuilder { pub fn new() -> Self { Self } pub fn format(self, _format: Format) -> Self { self } pub fn build(self) -> FuturesGuard { FuturesGuard } } impl Default for FuturesGuardBuilder { fn default() -> Self { Self::new() } } ``` -------------------------------- ### MeasurementGuard Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuard_search= Documentation for the MeasurementGuard struct. ```APIDOC ## Struct MeasurementGuard ### Description Represents a guard for measurements within the hotpath system. ### Fields This struct does not have publicly exposed fields. ### Methods #### `fn new(_name: &'static str, _wrapper: bool, _unsupported_async: bool) -> Self` ##### Description Creates a new `MeasurementGuard` instance. ##### Parameters * `_name` ( &'static str ) - The name associated with the measurement. * `_wrapper` ( bool ) - Indicates if this guard is acting as a wrapper. * `_unsupported_async` ( bool ) - Flag indicating if async is unsupported. #### `fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self` ##### Description Builds a `MeasurementGuard` instance with specified async status. ##### Parameters * `_name` ( &'static str ) - The name associated with the measurement. * `_wrapper` ( bool ) - Indicates if this guard is acting as a wrapper. * `_is_async` ( bool ) - Flag indicating if the measurement is asynchronous. #### `fn build_with_timeout(self, _duration: Duration)` ##### Description Configures the `MeasurementGuard` with a specific timeout duration. ##### Parameters * `self` ( MeasurementGuard ) - The `MeasurementGuard` instance to configure. * `_duration` ( Duration ) - The timeout duration for the measurement. ``` -------------------------------- ### Type Information and Conversion Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/futures/struct.FuturesGuardBuilder Illustrates generic implementations for traits that provide type introspection and conversion capabilities. This includes `Any` for dynamic type identification, `Borrow` and `BorrowMut` for accessing the underlying data, and `From`/`Into`/`TryFrom`/`TryInto` for various conversion scenarios. ```rust impl Any for T where T: 'static + ?Sized fn type_id(&self) -> TypeId impl Borrow for T where T: ?Sized fn borrow(&self) -> &T impl BorrowMut for T where T: ?Sized fn borrow_mut(&mut self) -> &mut T impl From for T fn from(t: T) -> T impl Into for T where U: From fn into(self) -> U impl TryFrom for T where U: Into type Error = Infallible fn try_from(value: U) -> Result>::Error> impl TryInto for T where U: TryFrom type Error = >::Error fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Rust: Implement ChannelsGuard Source: https://docs.rs/hotpath/0.9.0/src/hotpath/lib_off.rs Defines the ChannelsGuard struct in Rust, with methods for initialization and formatting. It also implements the Default and Drop traits, ensuring proper handling and cleanup. ```rust pub struct ChannelsGuard; impl ChannelsGuard { pub fn new() -> Self { Self } pub fn format(self, _format: Format) -> Self { self } } impl Default for ChannelsGuard { fn default() -> Self { Self::new() } } impl Drop for ChannelsGuard { fn drop(&mut self) {} } ``` -------------------------------- ### Borrow Trait Implementations Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog Documentation for the blanket implementations of `Borrow` and `BorrowMut` traits. ```APIDOC ## Blanket Implementations ### impl Borrow for T where T: ?Sized #### `fn borrow(&self) -> &T` Immutably borrows from an owned value. - **`self`** (`&T`) - A reference to the value. - **Returns** (`&T`) - An immutable reference to the value. ### impl BorrowMut for T where T: ?Sized #### `fn borrow_mut(&mut self) -> &mut T` Mutably borrows from an owned value. - **`self`** (`&mut T`) - A mutable reference to the value. - **Returns** (`&mut T`) - A mutable reference to the value. ``` -------------------------------- ### FunctionsGuardBuilder Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.FunctionsGuardBuilder_search= Provides methods to configure and build a HotPath instance with various settings. ```APIDOC ## Struct FunctionsGuardBuilder ### Description Represents a builder for configuring a `HotPath` instance. It allows setting percentiles, format, limit, reporter, and timeout. ### Methods #### `new(_caller_name: impl Into) -> Self` - **Description**: Creates a new instance of `FunctionsGuardBuilder`. - **Parameters**: - `_caller_name` (String) - The name of the caller. - **Returns**: `Self` (a new `FunctionsGuardBuilder` instance). #### `percentiles(self, _percentiles: &[u8]) -> Self` - **Description**: Sets the percentiles for the `HotPath`. - **Parameters**: - `_percentiles` (&[u8]) - A slice of unsigned 8-bit integers representing the percentiles. - **Returns**: `Self` (the modified `FunctionsGuardBuilder` instance). #### `format(self, _format: Format) -> Self` - **Description**: Sets the output format for the `HotPath`. - **Parameters**: - `_format` (Format) - The desired output format. - **Returns**: `Self` (the modified `FunctionsGuardBuilder` instance). #### `limit(self, _limit: usize) -> Self` - **Description**: Sets the limit for the `HotPath`. - **Parameters**: - `_limit` (usize) - The limit value. - **Returns**: `Self` (the modified `FunctionsGuardBuilder` instance). #### `build(self) -> HotPath` - **Description**: Builds and returns a `HotPath` instance with the configured settings. - **Returns**: `HotPath` (the built `HotPath` instance). #### `build_with_timeout(self, _duration: Duration) -> HotPath` - **Description**: Builds and returns a `HotPath` instance with a specified timeout. - **Parameters**: - `_duration` (Duration) - The timeout duration. - **Returns**: `HotPath` (the built `HotPath` instance with timeout). #### `reporter(self, _reporter: Box) -> Self` - **Description**: Sets a custom reporter for the `HotPath`. - **Parameters**: - `_reporter` (Box) - A boxed dynamic trait object implementing the `Reporter` trait. - **Returns**: `Self` (the modified `FunctionsGuardBuilder` instance). ### Auto Trait Implementations `FunctionsGuardBuilder` implements the following auto traits: `Freeze`, `RefUnwindSafe`, `Send`, `Sync`, `Unpin`, `UnwindSafe`. ### Blanket Implementations `FunctionsGuardBuilder` also has blanket implementations for traits like `Any`, `Borrow`, `BorrowMut`, `From`, `Into`, `TryFrom`, and `TryInto`. ``` -------------------------------- ### Implementations for MeasurementGuard Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuard_search= Documentation for the implementations of traits for MeasurementGuard. ```APIDOC ## Implementations for MeasurementGuard ### `impl Freeze for MeasurementGuard` ### `impl RefUnwindSafe for MeasurementGuard` ### `impl Send for MeasurementGuard` ### `impl Sync for MeasurementGuard` ### `impl Unpin for MeasurementGuard` ### `impl UnwindSafe for MeasurementGuard` ``` -------------------------------- ### Rust ChannelsGuardBuilder new, format, build methods Source: https://docs.rs/hotpath/0.9.0/src/hotpath/lib_off.rs_search=std%3A%3Avec Implements builder pattern for ChannelsGuard with methods to initialize, format, and build the guard. Uses a fluent interface pattern. ```rust pub struct ChannelsGuardBuilder; impl ChannelsGuardBuilder { pub fn new() -> Self { Self } pub fn format(self, _format: Format) -> Self { self } pub fn build(self) -> ChannelsGuard { ChannelsGuard } } ``` -------------------------------- ### Initialize hotpath profiling with the main attribute macro (Rust) Source: https://docs.rs/hotpath/0.9.0/hotpath/index_search=std%3A%3Avec The `main` attribute macro initializes the hotpath profiling system. It automatically generates a performance report upon program exit, providing insights into code execution time and memory allocation. ```Rust #[hotpath::main] fn main() { // Your application code here } ``` -------------------------------- ### ChannelsGuardBuilder Constructor and Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/channels/struct.ChannelsGuardBuilder Provides the implementation for the ChannelsGuardBuilder struct. It includes the `new` function to create an instance, `format` to set a format, and `build` to finalize the guard creation. ```rust impl ChannelsGuardBuilder { pub fn new() -> Self pub fn format(self, _format: Format) -> Self pub fn build(self) -> ChannelsGuard } ``` -------------------------------- ### Implement MeasurementGuardWithLog Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog_search=std%3A%3Avec Provides implementations for the MeasurementGuardWithLog struct in Rust. This includes constructor-like functions `new` and `build` for creating instances, and `finish_with_result` for completing a measurement and logging its outcome. These methods are part of the hotpath crate. ```rust pub fn new( _name: &'static str, _wrapper: bool, _unsupported_async: bool, ) -> Self ``` ```rust pub fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self ``` ```rust pub fn finish_with_result(self, _result: &T) ``` -------------------------------- ### MeasurementGuardWithLog Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog Documentation for the MeasurementGuardWithLog struct. ```APIDOC ## Struct MeasurementGuardWithLog ### Summary ```rust pub struct MeasurementGuardWithLog {} ``` ### Implementations #### impl MeasurementGuardWithLog ##### `pub fn new(_name: &'static str, _wrapper: bool, _unsupported_async: bool) -> Self` Creates a new instance of `MeasurementGuardWithLog`. - **`_name`** (`&'static str`) - The name for the measurement. - **`_wrapper`** (`bool`) - Indicates if this measurement is a wrapper. - **`_unsupported_async`** (`bool`) - Indicates if async is unsupported. ##### `pub fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self` Builds a `MeasurementGuardWithLog` instance. - **`_name`** (`&'static str`) - The name for the measurement. - **`_wrapper`** (`bool`) - Indicates if this measurement is a wrapper. - **`_is_async`** (`bool`) - Indicates if the measurement is asynchronous. ##### `pub fn finish_with_result(self, _result: &T)` Finishes the measurement and logs the result. - **`self`** (`MeasurementGuardWithLog`) - The measurement guard instance. - **`_result`** (`&T`) - The result to log, must implement `Debug`. ``` -------------------------------- ### FunctionsGuardBuilder Implementations Source: https://docs.rs/hotpath/0.9.0/hotpath/type.GuardBuilder_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides details on the methods available for building and configuring a HotPath using the FunctionsGuardBuilder. ```APIDOC ## Implementations for FunctionsGuardBuilder ### `new(_caller_name: impl Into) -> Self` Creates a new instance of `FunctionsGuardBuilder` with the given caller name. ### `percentiles(self, _percentiles: &[u8]) -> Self` Sets the percentiles for the guard builder. ### `format(self, _format: Format) -> Self` Sets the output format for the guard builder. ### `limit(self, _limit: usize) -> Self` Sets the limit for the guard builder. ### `build(self) -> HotPath` Builds the `HotPath` instance without a timeout. ### `build_with_timeout(self, _duration: Duration) -> HotPath` Builds the `HotPath` instance with a specified timeout duration. ### `reporter(self, _reporter: Box) -> Self` Sets a custom reporter for the guard builder. ``` -------------------------------- ### Implementations for FunctionsGuardBuilder in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.FunctionsGuardBuilder_search=std%3A%3Avec This section details the various methods available for the `FunctionsGuardBuilder` struct in Rust. These methods allow for customization of guard behavior, such as setting percentiles, format, limits, and building the final `HotPath` object, potentially with a timeout or custom reporter. The `impl` blocks demonstrate how to chain configurations. ```rust impl FunctionsGuardBuilder { pub fn new(_caller_name: impl Into) -> Self pub fn percentiles(self, _percentiles: &[u8]) -> Self pub fn format(self, _format: Format) -> Self pub fn limit(self, _limit: usize) -> Self pub fn build(self) -> HotPath pub fn build_with_timeout(self, _duration: Duration) -> HotPath pub fn reporter(self, _reporter: Box) -> Self } ``` -------------------------------- ### Implement MeasurementGuardWithLog Methods in Rust Source: https://docs.rs/hotpath/0.9.0/hotpath/struct.MeasurementGuardWithLog_search=u32+-%3E+bool Provides implementations for key methods of the MeasurementGuardWithLog struct. These include constructors like 'new' and 'build', and a method 'finish_with_result' for concluding a measurement with a result. ```rust impl MeasurementGuardWithLog { pub fn new( _name: &'static str, _wrapper: bool, _unsupported_async: bool, ) -> Self {} pub fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self {} pub fn finish_with_result(self, _result: &T) } ``` -------------------------------- ### Rust Measurement Guards and Logging Source: https://docs.rs/hotpath/0.9.0/src/hotpath/lib_off.rs Implements `MeasurementGuard` and `MeasurementGuardWithLog` for managing and logging performance measurements. These guards provide methods to initialize, build, and finalize measurements, with options for timeouts and result logging. ```rust pub struct MeasurementGuard {} impl MeasurementGuard { pub fn new(_name: &'static str, _wrapper: bool, _unsupported_async: bool) -> Self { Self {} } pub fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self { Self {} } pub fn build_with_timeout(self, _duration: std::time::Duration) {} } pub struct MeasurementGuardWithLog {} impl MeasurementGuardWithLog { pub fn new(_name: &'static str, _wrapper: bool, _unsupported_async: bool) -> Self { Self {} } pub fn build(_name: &'static str, _wrapper: bool, _is_async: bool) -> Self { Self {} } pub fn finish_with_result(self, _result: &T) {} } #[inline] pub fn measure_with_log T>( _name: &'static str, _wrapper: bool, _is_async: bool, f: F, ) -> T { f() } pub async fn measure_with_log_async(_name: &'static str, f: F) -> T where F: FnOnce() -> Fut, Fut: std::future::Future, { f().await } ```