1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Module for the [`Value`] marker trait.
use core::fmt::{Debug, Display};
use num_traits::{FromPrimitive, Num, NumCast};
dummy! {
/// Marker trait for a type that can be used as the dimensionless component
/// of a [`Quantity`](crate::Quantity).
///
/// Implemented automatically for any type that implements all of the
/// following:
/// - [`Clone`]
/// - [`Debug`]
/// - [`Display`]
/// - [`FromPrimitive`]
/// - [`Num`]
/// - [`NumCast`]
pub trait Value: Clone
+ Debug
+ Display
+ FromPrimitive
+ Num + NumCast
+ 'static
}
/// Convert an `f64` to any [`Value`] type.
///
/// TODO: This function is a stand-in to concentrate every conversion in one
/// place until the best way to do this is decided. It should be infallible
/// if at all possible, but
/// 1. Will `from_f64` succeed for every `V`? *Probably* not.
/// 2. Is there a better trait than [`FromPrimitive`] to use here?
pub(crate) fn _conv_f64<V: Value>(v: f64) -> V {
V::from_f64(v).unwrap()
}
/// Convert an `i32` to any [`Value`] type.
///
/// TODO: See [`_conv_f64`].
pub(crate) fn _conv_i32<V: Value>(v: i32) -> V {
V::from_i32(v).unwrap()
}