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
impl BackendNumericPolicy
Sourcepub const fn new(backend: &'static str) -> Self
pub const fn new(backend: &'static str) -> Self
Create a numeric policy that annotates diagnostics with backend.
Sourcepub const fn backend(self) -> &'static str
pub const fn backend(self) -> &'static str
Return the backend label used in numeric diagnostics.
Sourcepub fn usize_to_u64(
self,
value: usize,
label: &str,
) -> Result<u64, BackendError>
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.
Sourcepub fn u128_to_u64(self, value: u128, label: &str) -> Result<u64, BackendError>
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.
Sourcepub fn elapsed_nanos_u64(
self,
started: Instant,
label: &str,
) -> Result<u64, BackendError>
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.
Sourcepub fn rounded_f64_to_u64(
self,
value: f64,
label: &str,
) -> Result<u64, BackendError>
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.
Sourcepub fn ratio_basis_points_u64(
self,
part: u64,
whole: u64,
denominator_zero_value: u32,
label: &str,
) -> u32
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.
Sourcepub fn ratio_basis_points_u64_wide(
self,
part: u64,
whole: u64,
denominator_zero_value: u64,
label: &str,
) -> u64
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.
Sourcepub fn ratio_parts_per_million_u64(
self,
part: u64,
whole: u64,
denominator_zero_value: u32,
label: &str,
) -> u32
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.
Sourcepub fn compose_basis_points_u32(self, left: u32, right: u32, label: &str) -> u32
pub fn compose_basis_points_u32(self, left: u32, right: u32, label: &str) -> u32
Compose two basis-point multipliers into a u32 result.
Sourcepub 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
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.
Sourcepub fn scale_u64_by_basis_points_floor_min(
self,
base: u64,
scale_bps: u32,
min_value: u64,
label: &str,
) -> u64
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.
Sourcepub fn finite_f64_to_u32_trunc(self, value: f64, label: &str) -> u32
pub fn finite_f64_to_u32_trunc(self, value: f64, label: &str) -> u32
Convert finite non-negative floating-point telemetry to u32 by truncation.
Sourcepub fn finite_f64_to_u32_round(self, value: f64, label: &str) -> u32
pub fn finite_f64_to_u32_round(self, value: f64, label: &str) -> u32
Convert finite non-negative floating-point telemetry to rounded u32.
Sourcepub fn finite_f64_ratio_basis_points_trunc(
self,
numerator: f64,
denominator: f64,
invalid_numerator_value: u32,
invalid_denominator_value: u32,
label: &str,
) -> u32
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.
Sourcepub fn finite_f64_ratio_basis_points_round(
self,
numerator: f64,
denominator: f64,
invalid_numerator_value: u32,
invalid_denominator_value: u32,
label: &str,
) -> u32
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.
Sourcepub fn finite_f64_unit_basis_points_trunc(
self,
value: f64,
invalid_value: u32,
label: &str,
) -> u32
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.
Sourcepub fn checked_ceil_div_u64(self, value: u64, divisor: u64) -> Option<u64>
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.
Sourcepub fn checked_dim_product_u64(self, dims: [u32; 3]) -> Option<u64>
pub fn checked_dim_product_u64(self, dims: [u32; 3]) -> Option<u64>
Multiply three u32 launch dimensions into a u64 without wraparound.
Sourcepub fn checked_dim_product_u32(self, dims: [u32; 3]) -> Option<u32>
pub fn checked_dim_product_u32(self, dims: [u32; 3]) -> Option<u32>
Multiply three u32 launch dimensions into a u32 without wraparound.
Sourcepub fn align_up_u64(
self,
value: u64,
alignment: u64,
min_value: u64,
label: &str,
) -> Result<u64, BackendError>
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.
Sourcepub fn align_up_usize(
self,
value: usize,
alignment: usize,
min_value: usize,
label: &str,
) -> Result<usize, BackendError>
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
impl Clone for BackendNumericPolicy
Source§fn clone(&self) -> BackendNumericPolicy
fn clone(&self) -> BackendNumericPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for BackendNumericPolicy
Source§impl Debug for BackendNumericPolicy
impl Debug for BackendNumericPolicy
impl Eq for BackendNumericPolicy
Source§impl PartialEq for BackendNumericPolicy
impl PartialEq for BackendNumericPolicy
Source§fn eq(&self, other: &BackendNumericPolicy) -> bool
fn eq(&self, other: &BackendNumericPolicy) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for BackendNumericPolicy
Auto Trait Implementations§
impl Freeze for BackendNumericPolicy
impl RefUnwindSafe for BackendNumericPolicy
impl Send for BackendNumericPolicy
impl Sync for BackendNumericPolicy
impl Unpin for BackendNumericPolicy
impl UnsafeUnpin for BackendNumericPolicy
impl UnwindSafe for BackendNumericPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.