pub trait Log2: Sized {
type Error: Error;
// Required methods
fn try_log2(self) -> Result<Self, Self::Error>;
fn log2(self) -> Self;
}Expand description
Trait for computing the base-2 logarithm of a number.
Provides both a fallible method that returns a Result and a panicking method that directly returns the computed value or panics on invalid input.
§Associated Types
Error: The error type that is returned by thetry_log2method. This type must implement thestd::error::Errortrait.
§Required Methods
try_log2: Computes the base-2 logarithm ofselfand returns aResult. If the computation is successful, it returnsOkwith the computed value. If an error occurs, it returnsErrwith the associated error.log2: Computes the base-2 logarithm ofselfand directly returns the computed value. This method may panic (in Debug mode) if the computation fails.
Required Associated Types§
Required Methods§
Sourcefn try_log2(self) -> Result<Self, Self::Error>
fn try_log2(self) -> Result<Self, Self::Error>
Computes the base-2 logarithm of self and returns a Result.
If the computation is successful, it returns Ok with the computed value. If an error occurs, it returns Err with the associated error.
§Errors
This method returns an error if the computation fails. The error type is defined by the associated Log2::Error type.
Sourcefn log2(self) -> Self
fn log2(self) -> Self
Computes the base-2 logarithm of self and directly returns the computed value.
This method may panic (in Debug mode) if the computation fails.
§Panics
This method may panic (in Debug mode) if the computation fails. It is recommended to use the try_log2 method for safe computations.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.