trait ScalarCore = Sized
+ Clone
+ Debug
+ Display
+ PartialEq
+ Send
+ Sync
+ Zero
+ One
+ Serialize
+ DeserializeOwned
+ 'static;Expand description
Fundamental trait alias bundling core requirements for all scalar types.
ScalarCore aggregates the essential traits that every scalar type in num-valid
must implement, regardless of whether it’s real or complex, native or arbitrary-precision.
This trait alias provides a single, maintainable definition of the foundational capabilities
required by all floating-point scalar types.
§Included Traits
Sized: Types must have a known size at compile timeClone: Values can be duplicated (note: not necessarilyCopy)Debug: Supports formatted debugging output with{:?}Display: Supports user-facing formatted output with{}PartialEq: Supports equality comparisons (may upgrade toEqwith finite guarantees)Send: Safe to transfer ownership across thread boundariesSync: Safe to share references across threadsZero: Has an additive identity element (0)One: Has a multiplicative identity element (1)Serialize: Can be serialized (viaserde)DeserializeOwned: Can be deserialized without borrowing (viaserde)'static: Contains no non-static references
§Design Rationale
This trait alias serves several important purposes:
- Single Source of Truth: Defines core requirements in one place, reducing duplication
- Maintainability: Changes to fundamental requirements only need to be made once
- Readability: Simplifies trait bounds in
FpScalarand other high-level traits - Consistency: Ensures all scalar types share the same baseline capabilities
§Usage in Type Bounds
ScalarCore is primarily used as a super-trait bound in FpScalar:
// Instead of listing all traits individually:
// pub trait FpScalar: Sized + Clone + Debug + Display + PartialEq + Send + Sync + ...
// We use the trait alias:
pub trait FpScalar: ScalarCore + /* other mathematical traits */ {
// ...
}§Thread Safety
The inclusion of Send and Sync makes all scalar types safe for concurrent use:
This enables parallel numerical computations without additional synchronization overhead.
§Serialization Support
All scalar types support serialization through serde:
use num_valid::RealNative64StrictFinite;
use try_create::TryNew;
use serde_json;
let value = RealNative64StrictFinite::try_new(3.14159).unwrap();
// Serialize to JSON
let json = serde_json::to_string(&value).unwrap();
assert_eq!(json, "3.14159");
// Deserialize from JSON
let deserialized: RealNative64StrictFinite = serde_json::from_str(&json).unwrap();
assert_eq!(value, deserialized);§Relationship to Other Traits
FpScalar: ExtendsScalarCorewith mathematical operations and floating-point checksRealScalar: Further specializesFpScalarfor real numbersComplexScalar: Further specializesFpScalarfor complex numbers
§Implementation Note
This is a trait alias, not a regular trait. It cannot be implemented directly; instead, types must implement all the constituent traits individually. The trait alias simply provides a convenient shorthand for referring to this specific combination of traits.
§See Also
FpScalar: The main scalar trait that usesScalarCoreas a foundationRealScalar: Specialized trait for real number typesComplexScalar: Specialized trait for complex number types