Skip to main content

base_traits/
lib.rs

1// lib.rs : base-traits
2
3//! General-purpose traits for generic Rust programming.
4//!
5//! The crate supplies small traits for concepts that are
6//! useful across unrelated types, including [`IsEmpty`],
7//! [`Len`], [`ToF64`], and [`Zero`]. Implementations for
8//! built-in and standard-library types are controlled by
9//! feature flags so consumers can choose the API surface
10//! they need.
11//!
12//! # Example
13//!
14//! ```
15//! use base_traits::ToF64;
16//!
17//! struct Price(f64);
18//!
19//! impl ToF64 for Price {
20//!     fn to_f64(&self) -> f64 {
21//!         self.0
22//!     }
23//! }
24//!
25//! let price = Price(12.50);
26//! assert_eq!(12.50, price.to_f64());
27//! ```
28//!
29//! The default feature set enables the common built-in and
30//! standard-library implementations. The `"full"` feature
31//! enables the broader set, including the experimental
32//! process-type implementations. Use `"nostd"` when the
33//! standard library is unavailable.
34
35// /////////////////////////////////////////////////////////
36// crate-level feature definitions
37
38#![cfg_attr(feature = "experimental-exact_size_is_empty", feature(exact_size_is_empty))]
39#![cfg_attr(all(not(test), feature = "nostd"), no_std)]
40
41// /////////////////////////////////////////////////////////
42// crate-level feature discrimination
43
44// /////////////////////////////////////////////////////////
45// imports
46
47pub(crate) mod macros;
48
49macros::declare_and_publish!(pub traits,
50    AsF64,
51    AsI128,
52    AsI32,
53    AsI64,
54    AsISize,
55    AsStr,
56    AsU128,
57    AsU32,
58    AsU64,
59    AsUSize,
60    Infinity,
61    Integer,
62    IsDefault,
63    IsEmpty,
64    IsInfinity,
65    IsNAN,
66    IsZero,
67    Len,
68    Numeric,
69    Real,
70    Scalar,
71    Signed,
72    ToF64,
73    ToI128,
74    ToI16,
75    ToI32,
76    ToI64,
77    ToISize,
78    ToU128,
79    ToU16,
80    ToU32,
81    ToU64,
82    ToUSize,
83    Unsigned,
84    Zero,
85);
86
87mod private {
88    #![allow(unused_imports)]
89
90    pub(crate) use super::traits::Sealed;
91}
92
93// ///////////////////////////// end of file //////////////////////////// //