Skip to main content

AnalyticsContext

Struct AnalyticsContext 

Source
pub struct AnalyticsContext { /* private fields */ }
Expand description

Context for analytics operations with grouped buffer lifecycle.

All buffers allocated through this context are released together when the context is dropped. This is useful for analytics operations that need multiple temporary buffers.

§Thread Safety

AnalyticsContext is Send but not Sync. Each context should be used from a single thread. For parallel analytics, create a separate context per thread.

Implementations§

Source§

impl AnalyticsContext

Source

pub fn new(name: impl Into<String>) -> Self

Create a new analytics context.

§Arguments
  • name - Descriptive name for debugging and profiling
Source

pub fn with_capacity( name: impl Into<String>, expected_allocations: usize, ) -> Self

Create a context with pre-allocated capacity.

Reserves space for the expected number of allocations to avoid reallocations of the internal vectors.

Source

pub fn name(&self) -> &str

Get the context name.

Source

pub fn allocate(&mut self, size: usize) -> AllocationHandle

Allocate a buffer of the specified size.

Returns a handle that can be used with get() and get_mut().

§Arguments
  • size - Size in bytes
§Returns

Handle to the allocated buffer

Source

pub fn allocate_typed<T: Copy + Default + 'static>( &mut self, count: usize, ) -> AllocationHandle

Allocate a typed buffer.

Allocates space for count elements of type T, zero-initialized.

§Arguments
  • count - Number of elements
§Returns

Handle to the allocated buffer

§Type Parameters
  • T - Element type (must be Copy and have a meaningful zero value)
Source

pub fn get(&self, handle: AllocationHandle) -> &[u8]

Get a reference to an allocated buffer.

§Arguments
  • handle - Handle returned from allocate() or allocate_typed()
§Panics

Panics if the handle is invalid.

Source

pub fn get_mut(&mut self, handle: AllocationHandle) -> &mut [u8]

Get a mutable reference to an allocated buffer.

§Arguments
  • handle - Handle returned from allocate() or allocate_typed()
§Panics

Panics if the handle is invalid.

Source

pub fn get_typed<T: Copy>(&self, handle: AllocationHandle) -> &[T]

Get a typed reference to an allocated buffer.

§Safety

The caller must ensure the buffer was allocated with the correct type and size using allocate_typed::<T>().

§Panics

Panics if the handle is invalid.

Source

pub fn get_typed_mut<T: Copy>(&mut self, handle: AllocationHandle) -> &mut [T]

Get a mutable typed reference to an allocated buffer.

§Safety

The caller must ensure the buffer was allocated with the correct type and size using allocate_typed::<T>().

§Panics

Panics if the handle is invalid.

Source

pub fn try_get(&self, handle: AllocationHandle) -> Option<&[u8]>

Try to get a reference to an allocated buffer.

Returns None if the handle is invalid.

Source

pub fn try_get_mut(&mut self, handle: AllocationHandle) -> Option<&mut [u8]>

Try to get a mutable reference to an allocated buffer.

Returns None if the handle is invalid.

Source

pub fn allocation_size(&self, handle: AllocationHandle) -> usize

Get the size of an allocation.

§Panics

Panics if the handle is invalid.

Source

pub fn allocation_count(&self) -> usize

Get the number of allocations in this context.

Source

pub fn stats(&self) -> &ContextStats

Get statistics for this context.

Source

pub fn release_all(&mut self)

Release all allocations and reset the context.

After calling this, all handles become invalid.

Source

pub fn sub_context(&self, name: impl Into<String>) -> Self

Create a sub-context for a nested operation.

The sub-context shares no allocations with the parent.

Trait Implementations§

Source§

impl Drop for AnalyticsContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more