pub trait Reciprocal: TryNew {
type Error: Debug;
// Required methods
fn try_reciprocal(self) -> Result<Self, <Self as Reciprocal>::Error>;
fn reciprocal(self) -> Self;
}
Expand description
A trait for computing the reciprocal of a number.
Required Associated Types§
Required Methods§
Sourcefn try_reciprocal(self) -> Result<Self, <Self as Reciprocal>::Error>
fn try_reciprocal(self) -> Result<Self, <Self as Reciprocal>::Error>
Computes the reciprocal of self
, checking the input and output values for validity.
§Validity
- The input value is valid if it is finite, non-zero, and normal.
§Returns
Ok(self)
if the reciprocal computation is successful and the input and output values are valid.Err(Self::Error)
if the input or output values are invalid.
Sourcefn reciprocal(self) -> Self
fn reciprocal(self) -> Self
Computes the reciprocal of self
, with no checks (in Release mode) on the validity of the input and output values.
In Debug mode, this function internally calls the function Reciprocal::try_reciprocal()
and a panic!
is raised if the function returns an error.
§Panics
This function will panic in Debug mode if the input or output values are invalid.
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.