### Invoke the begin macro Source: https://docs.rs/coz/latest/coz/macro.begin.html Example of how to use the 'begin' macro by passing a string literal. ```rust coz::begin!("foo"); ``` -------------------------------- ### Example Calling a Documented Function Source: https://docs.rs/coz/latest/scrape-examples-help.html This example demonstrates how an external crate can call a documented function from another crate. Rustdoc will include this usage in the documentation of `a_func`. ```rust // examples/ex.rs fn main() { a_crate::a_func(); } ``` -------------------------------- ### thread_init Function Source: https://docs.rs/coz/latest/coz/fn.thread_init.html Performs one-time per-thread initialization for `coz`. It's recommended to call this once per thread near where the thread starts. This may help resolve issues with segfaults related to SIGPROF handlers by installing a larger stack earlier in the process. ```APIDOC ## Function thread_init ### Description Perform one-time per-thread initialization for `coz`. This may not be necessary to call, but for good measure it’s recommended to call once per thread in your application near where the thread starts. If you run into issues with segfaults related to SIGPROF handlers this may help fix the issue since it installs a bigger stack earlier on in the process. ### Signature ```rust pub fn thread_init() ``` ### Parameters This function does not take any parameters. ### Request Body N/A ### Response N/A ### Examples ```rust fn main() { coz::thread_init(); let a = std::thread::spawn(move || { coz::thread_init(); for _ in 0..A { coz::progress!("a"); } }); let b = std::thread::spawn(move || { coz::thread_init(); for _ in 0..B { coz::progress!("b"); } }); a.join().unwrap(); b.join().unwrap(); } ``` ``` -------------------------------- ### Initialize Coz and Track Progress in Threads Source: https://docs.rs/coz/latest/src/toy/toy.rs.html This example demonstrates how to initialize the coz profiler for each thread and use the `progress!` macro to mark work done within spawned threads. Ensure `coz::thread_init()` is called at the beginning of each thread's execution. ```rust 1const A: usize = 2_000_000_000; 2const B: usize = (A as f64 * 1.2) as usize; 3 4fn main() { 5 coz::thread_init(); 6 7 let a = std::thread::spawn(move || { 8 coz::thread_init(); 9 for _ in 0..A { 10 coz::progress!("a"); 11 } 12 }); 13 let b = std::thread::spawn(move || { 14 coz::thread_init(); 15 for _ in 0..B { 16 coz::progress!("b"); 17 } 18 }); 19 a.join().unwrap(); 20 b.join().unwrap(); 21} ``` -------------------------------- ### coz::begin! Macro Source: https://docs.rs/coz/latest/coz/macro.begin.html The `begin!` macro is a convenient way to start a new scope or operation within the coz framework, equivalent to the `COZ_BEGIN` macro. ```APIDOC ## Macro begin ### Description Equivalent of the `COZ_BEGIN` macro. ### Syntax ```rust macro_rules! begin { ($name:expr) => { ... }; } ``` ### Usage Example ```rust coz::begin!("foo"); ``` ``` -------------------------------- ### Initialize Thread for Coz Profiling Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Performs one-time per-thread initialization for coz. It's recommended to call this near where the thread starts to ensure a sufficiently large alternate signal stack is installed, which can help prevent segfaults related to SIGPROF handlers. ```rust pub fn thread_init() { thread_local!(static SIGALTSTACK_DISABLED: Cell = Cell::new(false)); if SIGALTSTACK_DISABLED.with(|s| s.replace(true)) { return; } unsafe { let mut stack = mem::zeroed(); libc::sigaltstack(ptr::null(), &mut stack); let size = 1 << 20; // 1mb if stack.ss_size >= size { return; } let ss_sp = libc::mmap( ptr::null_mut(), size, libc::PROT_READ | libc::PROT_WRITE, libc::MAP_PRIVATE | libc::MAP_ANON, -1, 0, ); if ss_sp == libc::MAP_FAILED { panic!("failed to allocate alternative stack"); } let new_stack = libc::stack_t { ss_sp, ss_flags: 0, ss_size: size, }; libc::sigaltstack(&new_stack, ptr::null_mut()); } } ``` -------------------------------- ### Initialize coz per thread Source: https://docs.rs/coz/latest/coz/fn.thread_init.html Call this function once per thread to perform one-time initialization for coz. This may help resolve SIGPROF handler issues by installing a larger stack earlier. ```rust fn main() { coz::thread_init(); let a = std::thread::spawn(move || { coz::thread_init(); for _ in 0..A { coz::progress!("a"); } }); let b = std::thread::spawn(move || { coz::thread_init(); for _ in 0..B { coz::progress!("b"); } }); a.join().unwrap(); b.join().unwrap(); } ``` -------------------------------- ### Documented Function in Library Source: https://docs.rs/coz/latest/scrape-examples-help.html This is an example of a public function within a library's source code that can be documented by Rustdoc. ```rust // src/lib.rs pub fn a_func() {} ``` -------------------------------- ### Get or Create Coz Counter Pointer Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Retrieves the underlying `coz_counter_t` pointer, initializing it if necessary. Returns `None` if the counter cannot be found. ```rust fn create_counter(&self) -> Option<&'static coz_counter_t> { let name = CString::new(self.name).unwrap(); let ptr = coz_get_counter(self.ty, &name); if ptr.is_null() { None } else { Some(unsafe { &*ptr }) } } ``` -------------------------------- ### Get Type ID Source: https://docs.rs/coz/latest/coz/struct.Counter.html Gets the `TypeId` of `self`. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Define Begin Counter Macro for Coz Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Use this macro to mark the beginning of a profiled section. It requires a name to identify the section. ```rust macro_rules! begin { ($name:expr) => {{ static COUNTER: $crate::Counter = $crate::Counter::begin($name); COUNTER.increment(); }}; } ``` -------------------------------- ### Create Latency Coz Counter (Begin) Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Use this to create the beginning of a latency counter. This should be paired with an `end` counter of the same name to measure operation duration. ```rust pub const fn begin(name: &'static str) -> Counter { Counter::new(COZ_COUNTER_TYPE_BEGIN, name) } ``` -------------------------------- ### Define the begin macro in Coz Source: https://docs.rs/coz/latest/coz/macro.begin.html Defines the 'begin' macro, which serves as an alias for COZ_BEGIN. It accepts a single string argument. ```rust macro_rules! begin { ($name:expr) => { ... }; } ``` -------------------------------- ### Create Latency Coz Counter (Begin) Source: https://docs.rs/coz/latest/coz/struct.Counter.html Creates a latency coz counter for the beginning of an operation. This should be paired with an `end` counter of the same name. ```rust pub const fn begin(name: &'static str) -> Counter ``` -------------------------------- ### Execute Progress Macro (With Name) Source: https://docs.rs/coz/latest/coz/macro.progress.html Use the progress macro with a unique name for specific progress tracking. ```rust coz::progress!("my unique name"); ``` -------------------------------- ### Execute Progress Macro (No Name) Source: https://docs.rs/coz/latest/coz/macro.progress.html Use the progress macro without a specific name for general progress tracking. ```rust coz::progress!(); ``` -------------------------------- ### progress Macro Source: https://docs.rs/coz/latest/coz/macro.progress.html The `progress` macro allows for tracking progress within the Coz library. It can be used with or without a name. ```APIDOC ## progress Macro ### Description Equivalent of the `COZ_PROGRESS` and `COZ_PROGRESS_NAMED` macros. ### Usage This macro can be executed in two ways: 1. **Without a name:** ```rust coz::progress!(); ``` 2. **With a unique name:** ```rust coz::progress!("my unique name"); ``` ### Parameters - **`name`** (string literal) - Optional - A unique identifier for the progress tracking point. ``` -------------------------------- ### Coz Functions Source: https://docs.rs/coz/latest/coz Functions provided by the coz crate for thread initialization. ```APIDOC ## Functions ### `thread_init` Perform one-time per-thread initialization for `coz`. ``` -------------------------------- ### Coz Macros Source: https://docs.rs/coz/latest/coz Macros provided by the coz crate for profiling control. ```APIDOC ## Macros ### `begin` Equivalent of the `COZ_BEGIN` macro. ### `end` Equivalent of the `COZ_END` macro. ### `progress` Equivalent of the `COZ_PROGRESS` and `COZ_PROGRESS_NAMED` macros. ### `scope` Marks a lexical scope with `coz::begin!` and `coz::end!` which are executed even on early exit (e.g. via `return`, `?` or `panic!`). ``` -------------------------------- ### Execute the end! macro Source: https://docs.rs/coz/latest/coz/macro.end.html Demonstrates how to execute the `coz::end!` macro with a string literal argument. ```rust coz::end!("foo"); ``` -------------------------------- ### Counter Methods Source: https://docs.rs/coz/latest/coz/struct.Counter.html Details on methods available for interacting with Counter instances, such as incrementing. ```APIDOC ## Implementations for Counter ### `impl Counter` #### `pub fn increment(&self)` Increment that an operation happened on this counter. For throughput counters this should be called in a location where you want something to happen more often. For latency-based counters this should be called before and after the operation you’d like to measure the latency of. ``` -------------------------------- ### Crate coz - Macros Source: https://docs.rs/coz/latest/coz/index.html Macros provided by the coz crate for profiling. ```APIDOC ## Macros ### begin Equivalent of the `COZ_BEGIN` macro. ### end Equivalent of the `COZ_END` macro. ### progress Equivalent of the `COZ_PROGRESS` and `COZ_PROGRESS_NAMED` macros. ### scope Marks a lexical scope with `coz::begin!` and `coz::end!` which are executed even on early exit (e.g. via `return`, `?` or `panic!`). ``` -------------------------------- ### Counter Creation and Types Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Defines the different types of counters and how to create them. ```APIDOC ## Counter Types ### Description Constants defining the types of counters available in the Coz library. ### Constants - `COZ_COUNTER_TYPE_THROUGHPUT`: Represents a counter for measuring throughput. - `COZ_COUNTER_TYPE_BEGIN`: Represents the start of an operation for latency measurement. - `COZ_COUNTER_TYPE_END`: Represents the end of an operation for latency measurement. ## Counter::progress ### Description Creates a throughput coz counter with the given name. ### Method `const fn` ### Parameters - **name** (`&'static str`) - The name of the counter. ### Returns A new `Counter` instance configured for throughput measurement. ## Counter::begin ### Description Creates a latency coz counter with the given name, used for when an operation begins. This counter should be paired with an `end` counter of the same name. ### Method `const fn` ### Parameters - **name** (`&'static str`) - The name of the counter. ### Returns A new `Counter` instance configured for the beginning of latency measurement. ## Counter::end ### Description Creates a latency coz counter with the given name, used for when an operation ends. This counter should be paired with a `begin` counter of the same name. ### Method `const fn` ### Parameters - **name** (`&'static str`) - The name of the counter. ### Returns A new `Counter` instance configured for the end of latency measurement. ``` -------------------------------- ### Guard Implementations Source: https://docs.rs/coz/latest/coz/struct.Guard.html Details the implementations for the Guard struct, including its Drop trait implementation and various auto-trait implementations. ```APIDOC ## Implementations for Guard<'t> ### `impl<'t> Drop for Guard<'t>` #### `fn drop(&mut self)` Executes the destructor for this type. This is where the counter is typically incremented. ``` ```APIDOC ## Auto Trait Implementations for Guard<'t> ### `impl<'t> Freeze for Guard<'t>` ### `impl<'t> RefUnwindSafe for Guard<'t>` ### `impl<'t> Send for Guard<'t>` ### `impl<'t> Sync for Guard<'t>` ### `impl<'t> Unpin for Guard<'t>` ### `impl<'t> UnsafeUnpin for Guard<'t>` ### `impl<'t> UnwindSafe for Guard<'t>` ``` -------------------------------- ### Implement Guard Constructor Source: https://docs.rs/coz/latest/coz/struct.Guard.html Provides the constructor for the Guard struct. It takes a reference to a Counter, which it will manage for the lifetime of the Guard. ```rust pub fn new(counter: &'t Counter) -> Self ``` -------------------------------- ### Create Latency Coz Counter (End) Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Use this to create the ending of a latency counter. This should be paired with a `begin` counter of the same name to measure operation duration. ```rust pub const fn end(name: &'static str) -> Counter { Counter::new(COZ_COUNTER_TYPE_END, name) } ``` -------------------------------- ### Counter Struct and Constructors Source: https://docs.rs/coz/latest/coz/struct.Counter.html Information about the Counter struct and its constructor methods for creating throughput or latency counters. ```APIDOC ## Struct Counter ### Description A `coz`-counter which is either intended for throughput or `begin`/`end` points. This is typically created by macros above via `progress!()`, `begin!()`, or `end!()`, but if necessary you can also create one of these manually in your own application for your own macros. ### Methods #### `pub const fn progress(name: &'static str) -> Counter` Creates a throughput coz counter with the given name. #### `pub const fn begin(name: &'static str) -> Counter` Creates a latency coz counter with the given name, used for when an operation begins. Note that this counter should be paired with an `end` counter of the same name. #### `pub const fn end(name: &'static str) -> Counter` Creates a latency coz counter with the given name, used for when an operation ends. Note that this counter should be paired with an `begin` counter of the same name. ``` -------------------------------- ### Using coz::scope! Macro Source: https://docs.rs/coz/latest/coz/macro.scope.html Demonstrates the usage of the coz::scope! macro to define nested lexical scopes. The inner scope is correctly handled even when it exits. ```rust coz::scope!("outer"); { coz::scope!("inner"); } ``` -------------------------------- ### Counter Increment and Guard Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Details on how to increment counters and use the Guard for automatic measurement. ```APIDOC ## Counter::increment ### Description Increments the counter. For throughput counters, this is called when an event occurs. For latency counters, this should be called before and after the operation to be measured. ### Method `pub fn` ### Parameters None. ### Request Example ```rust let my_counter = Counter::progress("my_operation"); my_counter.increment(); ``` ## Guard ### Description A type that increments a counter on drop. This allows for automatic measurement of the duration of a scope, ensuring the `begin` and `end` counters are called correctly even with early returns or panics. ### Guard::new #### Description Creates a new `Guard` instance. #### Method `pub fn` #### Parameters - **counter** (`&'t Counter`) - A reference to the `Counter` to be managed by the guard. #### Request Example ```rust let my_counter = Counter::begin("my_operation"); let _guard = Guard::new(&my_counter); // Operation code here... // The counter will be incremented when _guard goes out of scope. ``` ### Drop for Guard #### Description Implements the `Drop` trait for `Guard`. This method is automatically called when the `Guard` goes out of scope, triggering the `increment` method on the associated `Counter`. #### Method `impl Drop` #### Parameters - `self` (`&mut self`) - A mutable reference to the `Guard` instance. #### Behavior Calls `self.counter.increment()`. ``` -------------------------------- ### Crate coz - Structs Source: https://docs.rs/coz/latest/coz/index.html Structs provided by the coz crate for profiling. ```APIDOC ## Structs ### Counter A `coz`-counter which is either intended for throughput or `begin`/`end` points. ### Guard A type that increments a counter on drop. This allows us to issue the right coz calls to `begin` and `end` for the duration of a scope, regardless of how the scope was exited (e.g. by early return, `?` or panic). ``` -------------------------------- ### Initialize New Counter Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Internal function to create a new `Counter` instance with a specified type and name. ```rust const fn new(ty: libc::c_int, name: &'static str) -> Counter { Counter { slot: OnceCell::new(), ty, name, } } ``` -------------------------------- ### Crate coz - Functions Source: https://docs.rs/coz/latest/coz/index.html Functions provided by the coz crate for profiling. ```APIDOC ## Functions ### thread_init Perform one-time per-thread initialization for `coz`. ``` -------------------------------- ### Define Progress Counter Macro for Coz Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Use this macro to mark progress points in your code. It can be used with or without a custom name. The name is generated from the file and line number if not provided. ```rust macro_rules! progress { () => {{ static COUNTER: $crate::Counter = $crate::Counter::progress(concat!(file!(), ":", line!())); COUNTER.increment(); }}; ($name:expr) => {{ static COUNTER: $crate::Counter = $crate::Counter::progress($name); COUNTER.increment(); }}; } ``` -------------------------------- ### Create Throughput Coz Counter Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Use this to create a throughput counter with a given name. Throughput counters should be incremented when an event of interest occurs. ```rust pub const fn progress(name: &'static str) -> Counter { Counter::new(COZ_COUNTER_TYPE_THROUGHPUT, name) } ``` -------------------------------- ### Coz Structs Source: https://docs.rs/coz/latest/coz Structs provided by the coz crate for managing profiling data. ```APIDOC ## Structs ### `Counter` A `coz`-counter which is either intended for throughput or `begin`/`end` points. ### `Guard` A type that increments a counter on drop. This allows us to issue the right coz calls to `begin` and `end` for the duration of a scope, regardless of how the scope was exited (e.g. by early return, `?` or panic). ``` -------------------------------- ### Create Throughput Coz Counter Source: https://docs.rs/coz/latest/coz/struct.Counter.html Creates a throughput coz counter with a given name. Use this when you want to measure the frequency of operations. ```rust pub const fn progress(name: &'static str) -> Counter ``` -------------------------------- ### Non-Linux Coz Counter Retrieval Source: https://docs.rs/coz/latest/src/coz/lib.rs.html On non-Linux systems, this function always returns a null pointer, as the Coz counter functionality is not available. ```rust fn coz_get_counter(_ty: libc::c_int, _name: &CStr) -> *mut coz_counter_t { ptr::null_mut() } ``` -------------------------------- ### Create Latency Coz Counter (End) Source: https://docs.rs/coz/latest/coz/struct.Counter.html Creates a latency coz counter for the end of an operation. This should be paired with a `begin` counter of the same name. ```rust pub const fn end(name: &'static str) -> Counter ``` -------------------------------- ### Define Progress Macro Source: https://docs.rs/coz/latest/coz/macro.progress.html Defines the progress macro with two variants: one for general progress and another for named progress. ```rust macro_rules! progress { () => { ... }; ($name:expr) => { ... }; } ``` -------------------------------- ### Into Trait Implementation Source: https://docs.rs/coz/latest/coz/struct.Counter.html Calls `U::from(self)`. The conversion behavior is determined by the `From` for `U` implementation. ```rust fn into(self) -> U ``` -------------------------------- ### Linux-specific Coz Counter Retrieval Source: https://docs.rs/coz/latest/src/coz/lib.rs.html On Linux, this function dynamically loads the `_coz_get_counter` symbol from the default dynamic libraries and calls it to retrieve a `coz_counter_t` pointer. It handles thread initialization. ```rust fn coz_get_counter(ty: libc::c_int, name: &CStr) -> *mut coz_counter_t { static PTR: AtomicUsize = AtomicUsize::new(1); let mut ptr = PTR.load(SeqCst); if ptr == 1 { let name = CStr::from_bytes_with_nul(b"_coz_get_counter\0").unwrap(); ptr = unsafe { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr() as *const _) as usize }; PTR.store(ptr, SeqCst); } if ptr == 0 { return ptr::null_mut(); } thread_init(); // just in case we haven't already unsafe { mem::transmute:: *mut coz_counter_t>(ptr)(ty, name.as_ptr()) } } ``` -------------------------------- ### Define End Counter Macro for Coz Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Use this macro to mark the end of a profiled section. It requires a name to identify the section. ```rust macro_rules! end { ($name:expr) => {{ static COUNTER: $crate::Counter = $crate::Counter::end($name); COUNTER.increment(); }}; } ``` -------------------------------- ### From Trait Implementation Source: https://docs.rs/coz/latest/coz/struct.Counter.html Returns the argument unchanged. This is part of the `From` for `T` trait implementation. ```rust fn from(t: T) -> T ``` -------------------------------- ### coz::scope! Macro Source: https://docs.rs/coz/latest/coz/macro.scope.html Defines a lexical scope that is automatically profiled using coz::begin! and coz::end! macros. These counters are executed even if the scope is exited early due to return, ?, or panic. ```APIDOC ## scope! Macro ### Description Marks a lexical scope with `coz::begin!` and `coz::end!` which are executed even on early exit (e.g. via `return`, `?` or `panic!`). Where this macro is invoked is where a `begin` counter is placed, and then at the end of the lexical scope (when this macro’s local variable goes out of scope) an `end` counter is placed. ### Syntax ```rust macro_rules! scope { ($name:expr) => { ... }; } ``` ### Parameters #### Path Parameters - **name** (string literal) - Required - A string literal to identify the scope. ### Request Example ```rust coz::scope!("outer"); { coz::scope!("inner"); } ``` ### Response This macro does not produce a direct response. It affects the internal state of the `coz` profiling library. ``` -------------------------------- ### Define the end! macro Source: https://docs.rs/coz/latest/coz/macro.end.html Defines the `end!` macro, which takes an expression as an argument. ```rust macro_rules! end { ($name:expr) => { ... }; } ``` -------------------------------- ### Blanket Implementations Source: https://docs.rs/coz/latest/coz/struct.Guard.html Shows blanket implementations for the Guard struct, which are derived from generic trait implementations. ```APIDOC ## Blanket Implementations ### `impl Any for T` #### `fn type_id(&self) -> TypeId` Gets the `TypeId` of `self`. ### `impl Borrow for T` #### `fn borrow(&self) -> &T` Immutably borrows from an owned value. ### `impl BorrowMut for T` #### `fn borrow_mut(&mut self) -> &mut T` Mutably borrows from an owned value. ### `impl From for T` #### `fn from(t: T) -> T` Returns the argument unchanged. ### `impl Into for T` #### `fn into(self) -> U` Calls `U::from(self)`. ### `impl TryFrom for T` #### `type Error = Infallible` #### `fn try_from(value: U) -> Result>::Error>` Performs the conversion. ### `impl TryInto for T` #### `type Error = >::Error` #### `fn try_into(self) -> Result>::Error>` Performs the conversion. ``` -------------------------------- ### Internal Coz Counter Implementation Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Internal details of the coz_counter_t structure and the coz_get_counter function. ```APIDOC ## coz_counter_t ### Description Represents the internal structure of a Coz counter. ### Fields - **count** (`AtomicUsize`) - The atomic counter value. - **backoff** (`libc::size_t`) - Backoff value, likely for synchronization. ## coz_get_counter ### Description Retrieves a pointer to a Coz counter of a specific type and name. This function is platform-dependent. ### Method `fn` (platform-dependent) ### Parameters - **ty** (`libc::c_int`) - The type of the counter (e.g., `COZ_COUNTER_TYPE_THROUGHPUT`). - **name** (`&CStr`) - The name of the counter. ### Returns - `*mut coz_counter_t` - A mutable pointer to the `coz_counter_t` if found. - `ptr::null_mut()` - If the counter is not found or on unsupported platforms. ### Platform Specifics - **Linux**: Uses `dlsym` to find the `_coz_get_counter` symbol and then calls it. - **Other OS**: Returns a null pointer, indicating no Coz counter support. ``` -------------------------------- ### Define Scope Macro for Coz Source: https://docs.rs/coz/latest/src/coz/lib.rs.html This macro marks a lexical scope with `begin!` and `end!` counters that are executed even on early exit (return, ?, panic!). It ensures profiling data is captured for the entire scope. ```rust macro_rules! scope { ($name:expr) => { static BEGIN_COUNTER: $crate::Counter = $crate::Counter::begin($name); static END_COUNTER: $crate::Counter = $crate::Counter::end($name); BEGIN_COUNTER.increment(); let _coz_scope_guard = $crate::Guard::new(&END_COUNTER); }; } ``` -------------------------------- ### Create Guard for Automatic Increment Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Creates a new `Guard` instance that will automatically increment the associated counter when it is dropped. This is useful for measuring the duration of a scope. ```rust pub fn new(counter: &'t Counter) -> Self { Guard { counter } } ``` -------------------------------- ### Guard Struct Source: https://docs.rs/coz/latest/coz/struct.Guard.html The Guard struct is a type that increments a counter when it is dropped. This mechanism ensures that the correct 'begin' and 'end' calls are made for a scope, irrespective of how the scope is exited (e.g., early return, '?', or panic). ```APIDOC ## Struct Guard ### Description A type that increments a counter on drop. This allows us to issue the right coz calls to `begin` and `end` for the duration of a scope, regardless of how the scope was exited (e.g. by early return, `?` or panic). ### Fields (private fields) ### Methods #### `new(counter: &'t Counter) -> Self` Creates a new Guard instance associated with a given Counter. ``` -------------------------------- ### TryFrom Trait Implementation Source: https://docs.rs/coz/latest/coz/struct.Counter.html Performs the conversion. The `Error` type is `Infallible`. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### TryInto Trait Implementation Source: https://docs.rs/coz/latest/coz/struct.Counter.html Performs the conversion. The `Error` type is derived from the `TryFrom` implementation. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Implement TryInto Trait for Guard Source: https://docs.rs/coz/latest/coz/struct.Guard.html Implements the TryInto trait for the Guard struct, enabling fallible conversion to type U. The associated Error type is derived from U's TryFrom implementation. ```rust type Error = >::Error ``` ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Drop Guard and Increment Counter Source: https://docs.rs/coz/latest/src/coz/lib.rs.html The `Drop` implementation for `Guard` ensures that the associated counter is incremented when the guard goes out of scope, regardless of how the scope is exited. ```rust fn drop(&mut self) { self.counter.increment(); } ``` -------------------------------- ### Implement Drop for Guard Source: https://docs.rs/coz/latest/coz/struct.Guard.html Implements the Drop trait for the Guard struct. This ensures that the necessary cleanup or finalization logic is executed when the Guard goes out of scope. ```rust fn drop(&mut self) ``` -------------------------------- ### Define Coz Counter Struct Source: https://docs.rs/coz/latest/coz/struct.Counter.html Defines the private fields of the Coz Counter struct. This is typically created by macros like progress!(), begin!(), or end!(). ```rust pub struct Counter { /* private fields */ } ``` -------------------------------- ### Increment Coz Counter Source: https://docs.rs/coz/latest/coz/struct.Counter.html Increments the counter. For throughput counters, call this where an operation occurs. For latency counters, call this before and after the operation to measure its duration. ```rust pub fn increment(&self) ``` -------------------------------- ### Define coz::scope! Macro Source: https://docs.rs/coz/latest/coz/macro.scope.html Defines the coz::scope! macro. This macro is used to mark lexical scopes with `coz::begin!` and `coz::end!`. ```rust macro_rules! scope { ($name:expr) => { ... }; } ``` -------------------------------- ### Increment Coz Counter Source: https://docs.rs/coz/latest/src/coz/lib.rs.html Increments the counter's value. For throughput counters, call this when an event occurs. For latency counters, call this before and after the operation to be measured. ```rust pub fn increment(&self) { let counter = self.slot.get_or_init(|| self.create_counter()); if let Some(counter) = counter { assert_eq!( mem::size_of_val(&counter.count), mem::size_of::() ); counter.count.fetch_add(1, SeqCst); } } ``` -------------------------------- ### Implement TryFrom Trait for Guard Source: https://docs.rs/coz/latest/coz/struct.Guard.html Implements the TryFrom trait for the Guard struct, allowing fallible conversion from type U to T. The associated Error type is Infallible, indicating success. ```rust type Error = Infallible ``` ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### coz::end! Macro Source: https://docs.rs/coz/latest/coz/macro.end.html The `coz::end!` macro is a convenience macro that provides an equivalent functionality to the `COZ_END` macro. It is used to mark the end of a section or operation within the coz framework. ```APIDOC ## coz::end! Macro ### Description Equivalent of the `COZ_END` macro. ### Usage This macro can be invoked with a string literal representing a name. ### Example ```rust coz::end!("foo"); ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None (This is a macro, not an API endpoint) #### Response Example None ``` -------------------------------- ### Borrow Immutably Source: https://docs.rs/coz/latest/coz/struct.Counter.html Immutably borrows from an owned value. This is part of the `Borrow` trait implementation. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### Define Guard Struct Source: https://docs.rs/coz/latest/coz/struct.Guard.html Defines the Guard struct, which holds a private counter reference. This struct is central to managing scoped operations within the Coz library. ```rust pub struct Guard<'t> { /* private fields */ } ``` -------------------------------- ### Borrow Mutably Source: https://docs.rs/coz/latest/coz/struct.Counter.html Mutably borrows from an owned value. This is part of the `BorrowMut` trait implementation. ```rust fn borrow_mut(&mut self) -> &mut T ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.