Skip to main content

BackendNumericPolicy

Struct BackendNumericPolicy 

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

Backend-bound numeric conversion policy.

Backends should keep their label in one constant of this type instead of cloning one local wrapper per numeric helper. The free functions below remain available for backend-neutral callers and tests.

Implementations§

Source§

impl BackendNumericPolicy

Source

pub const fn new(backend: &'static str) -> Self

Create a numeric policy that annotates diagnostics with backend.

Source

pub const fn backend(self) -> &'static str

Return the backend label used in numeric diagnostics.

Source

pub fn usize_to_u64( self, value: usize, label: &str, ) -> Result<u64, BackendError>

Convert a host usize to a backend/API u64.

§Errors

Returns BackendError::InvalidProgram when the value cannot fit in the backend/API boundary type.

Source

pub fn u128_to_u64(self, value: u128, label: &str) -> Result<u64, BackendError>

Convert a wide counter to telemetry u64.

§Errors

Returns BackendError::InvalidProgram when the counter does not fit in telemetry storage.

Source

pub fn elapsed_nanos_u64( self, started: Instant, label: &str, ) -> Result<u64, BackendError>

Convert elapsed wall-clock time to telemetry nanoseconds.

§Errors

Returns BackendError::InvalidProgram when the elapsed nanoseconds cannot fit in telemetry storage.

Source

pub fn rounded_f64_to_u64( self, value: f64, label: &str, ) -> Result<u64, BackendError>

Round a finite floating-point nanosecond value into telemetry storage.

§Errors

Returns BackendError::InvalidProgram when the rounded value is negative, non-finite, or too large for telemetry storage.

Source

pub fn ratio_basis_points_u64( self, part: u64, whole: u64, denominator_zero_value: u32, label: &str, ) -> u32

Compute part / whole as floor basis points in a u32 telemetry domain.

Source

pub fn ratio_basis_points_u64_wide( self, part: u64, whole: u64, denominator_zero_value: u64, label: &str, ) -> u64

Compute part / whole as floor basis points in a u64 telemetry domain.

Source

pub fn ratio_parts_per_million_u64( self, part: u64, whole: u64, denominator_zero_value: u32, label: &str, ) -> u32

Compute part / whole as floor parts-per-million.

Source

pub fn compose_basis_points_u32(self, left: u32, right: u32, label: &str) -> u32

Compose two basis-point multipliers into a u32 result.

Source

pub fn scale_u64_by_basis_points_round_clamped( self, base: u64, scale_bps: u32, zero_scale_value: u64, max_scale_bps: u32, label: &str, ) -> u64

Apply rounded basis-point scaling with optional high clamp.

Source

pub fn scale_u64_by_basis_points_floor_min( self, base: u64, scale_bps: u32, min_value: u64, label: &str, ) -> u64

Apply floor basis-point scaling with a lower bound.

Source

pub fn finite_f64_to_u32_trunc(self, value: f64, label: &str) -> u32

Convert finite non-negative floating-point telemetry to u32 by truncation.

Source

pub fn finite_f64_to_u32_round(self, value: f64, label: &str) -> u32

Convert finite non-negative floating-point telemetry to rounded u32.

Source

pub fn finite_f64_ratio_basis_points_trunc( self, numerator: f64, denominator: f64, invalid_numerator_value: u32, invalid_denominator_value: u32, label: &str, ) -> u32

Convert a finite floating-point ratio into floor basis points.

Source

pub fn finite_f64_ratio_basis_points_round( self, numerator: f64, denominator: f64, invalid_numerator_value: u32, invalid_denominator_value: u32, label: &str, ) -> u32

Convert a finite floating-point ratio into rounded basis points.

Source

pub fn finite_f64_unit_basis_points_trunc( self, value: f64, invalid_value: u32, label: &str, ) -> u32

Convert a finite scalar where 1.0 == 10_000 bps into floor basis points.

Source

pub fn checked_ceil_div_u64(self, value: u64, divisor: u64) -> Option<u64>

Compute ceil(value / divisor) in u64, returning None for zero divisors or arithmetic overflow.

Source

pub fn checked_dim_product_u64(self, dims: [u32; 3]) -> Option<u64>

Multiply three u32 launch dimensions into a u64 without wraparound.

Source

pub fn checked_dim_product_u32(self, dims: [u32; 3]) -> Option<u32>

Multiply three u32 launch dimensions into a u32 without wraparound.

Source

pub fn align_up_u64( self, value: u64, alignment: u64, min_value: u64, label: &str, ) -> Result<u64, BackendError>

Align value upward to alignment, after applying min_value.

§Errors

Returns BackendError::InvalidProgram when alignment is zero or the padded value would overflow u64.

Source

pub fn align_up_usize( self, value: usize, alignment: usize, min_value: usize, label: &str, ) -> Result<usize, BackendError>

Align value upward to alignment, after applying min_value.

§Errors

Returns BackendError::InvalidProgram when alignment is zero or the padded value would overflow usize.

Trait Implementations§

Source§

impl Clone for BackendNumericPolicy

Source§

fn clone(&self) -> BackendNumericPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BackendNumericPolicy

Source§

impl Debug for BackendNumericPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for BackendNumericPolicy

Source§

impl PartialEq for BackendNumericPolicy

Source§

fn eq(&self, other: &BackendNumericPolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for BackendNumericPolicy

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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