Expand description
General-purpose traits for generic Rust programming.
The crate supplies small traits for concepts that are
useful across unrelated types, including IsEmpty,
Len, ToF64, and Zero. Implementations for
built-in and standard-library types are controlled by
feature flags so consumers can choose the API surface
they need.
§Example
use base_traits::ToF64;
struct Price(f64);
impl ToF64 for Price {
fn to_f64(&self) -> f64 {
self.0
}
}
let price = Price(12.50);
assert_eq!(12.50, price.to_f64());The default feature set enables the common built-in and
standard-library implementations. The "full" feature
enables the broader set, including the experimental
process-type implementations. Use "nostd" when the
standard library is unavailable.
Traits§
- AsF64
- Trait defining instance method
as_f64() : f64that provides a cost-free conversion intof64. - AsI32
- Trait defining instance method
as_i32() : i32that provides a cost-free conversion intoi32. - AsI64
- Trait defining instance method
as_i64() : i64that provides a cost-free conversion intoi64. - AsI128
- Trait defining instance method
as_i128() : i128that provides a cost-free conversion intoi128. - AsISize
- Trait defining instance method
as_isize() : isizethat provides a cost-free conversion intoisize. - AsStr
- Trait defining instance method
as_str() : &strthat allows a type to expose its contiguous character representation to client code. - AsU32
- Trait defining instance method
as_u32() : u32that provides a cost-free conversion intou32. - AsU64
- Trait defining instance method
as_u64() : u64that provides a cost-free conversion intou64. - AsU128
- Trait defining instance method
as_u128() : u128that provides a cost-free conversion intou128. - AsUSize
- Trait defining instance method
as_usize() : usizethat provides a cost-free conversion intousize. - Infinity
- Trait defining class method
infinity() : Tthat creates an instance of the implementing type that is conceptually (or actually) infinity. - Integer
- IsDefault
- Trait defining instance method
is_default() : boolthat allows a type instance to indicate whether it holds the “default” value. - IsEmpty
- Trait defining instance method
is_empty() : boolthat indicates whether the implementing type instance is logically empty. - IsInfinity
- Trait defining instance method
is_infinity() : boolthat indicates whether the implementing type instance is conceptually (or actually) infinite. - IsNAN
- Trait defining instance method
is_nan() : boolthat indicates whether the implementing type instance has a value that is deemed to be “not a number” (as in so forf32::NANf64::NAN). - IsZero
- Trait defining instance method
is_zero() : boolthat indicates whether the implementing type instance is numerically zero. - Len
- Trait defining instance method
len() : usizethat indicates whether the implementing type instance is logically empty. - Numeric
- Real
- Scalar
- Signed
- ToF64
- Trait defining instance method
to_f64() : f64that provides a no-cost or low-cost conversion intof64. - ToI16
- Trait defining instance method
to_i16() : i16that provides a no-cost or low-cost conversion intoi16. - ToI32
- Trait defining instance method
to_i32() : i32that provides a no-cost or low-cost conversion intoi32. - ToI64
- Trait defining instance method
to_i64() : i64that provides a no-cost or low-cost conversion intoi64. - ToI128
- Trait defining instance method
to_i128() : i128that provides a no-cost or low-cost conversion intoi128. - ToISize
- Trait defining instance method
to_isize() : isizethat provides a no-cost or low-cost conversion intoisize. - ToU16
- Trait defining instance method
to_u16() : u16that provides a no-cost or low-cost conversion intou16. - ToU32
- Trait defining instance method
to_u32() : u32that provides a no-cost or low-cost conversion intou32. - ToU64
- Trait defining instance method
to_u64() : u64that provides a no-cost or low-cost conversion intou64. - ToU128
- Trait defining instance method
to_u128() : u128that provides a no-cost or low-cost conversion intou128. - ToUSize
- Trait defining instance method
to_usize() : usizethat provides a no-cost or low-cost conversion intousize. - Unsigned
- Zero
- Trait defining class method
zero() : Tthat creates an instance of the implementing type that is conceptually (or actually) zero.