Add String place-holder event type, public facing error message
This commit is contained in:
+92
-3
@@ -1,5 +1,5 @@
|
||||
use crate::SubFrId;
|
||||
use num_traits::{AsPrimitive, Bounded, Float, Zero};
|
||||
use num_traits::{Bounded, Float, Zero};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
@@ -60,14 +60,64 @@ impl PartialOrd for BoolNum {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct StringNum(pub String);
|
||||
|
||||
impl StringNum {
|
||||
pub const MIN: Self = Self(String::new());
|
||||
pub const MAX: Self = Self(String::new());
|
||||
}
|
||||
|
||||
impl Add<StringNum> for StringNum {
|
||||
type Output = StringNum;
|
||||
|
||||
fn add(self, _rhs: StringNum) -> Self::Output {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl num_traits::Zero for StringNum {
|
||||
fn zero() -> Self {
|
||||
Self(String::new())
|
||||
}
|
||||
|
||||
fn is_zero(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl num_traits::Bounded for StringNum {
|
||||
fn min_value() -> Self {
|
||||
Self(String::new())
|
||||
}
|
||||
|
||||
fn max_value() -> Self {
|
||||
Self(String::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for StringNum {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
PartialEq::eq(&self.0, &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for StringNum {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
PartialOrd::partial_cmp(&self.0, &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NumOps:
|
||||
Sized
|
||||
+ Copy
|
||||
//+ Copy
|
||||
+ Clone
|
||||
+ AsPrimF32
|
||||
+ Send
|
||||
+ Unpin
|
||||
+ Debug
|
||||
+ Zero
|
||||
+ AsPrimitive<f32>
|
||||
//+ AsPrimitive<f32>
|
||||
+ Bounded
|
||||
+ PartialOrd
|
||||
+ SubFrId
|
||||
@@ -103,6 +153,44 @@ fn is_nan_float<T: Float>(x: &T) -> bool {
|
||||
x.is_nan()
|
||||
}
|
||||
|
||||
pub trait AsPrimF32 {
|
||||
fn as_prim_f32(&self) -> f32;
|
||||
}
|
||||
|
||||
macro_rules! impl_as_prim_f32 {
|
||||
($ty:ident) => {
|
||||
impl AsPrimF32 for $ty {
|
||||
fn as_prim_f32(&self) -> f32 {
|
||||
*self as f32
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_as_prim_f32!(u8);
|
||||
impl_as_prim_f32!(u16);
|
||||
impl_as_prim_f32!(u32);
|
||||
impl_as_prim_f32!(u64);
|
||||
impl_as_prim_f32!(i8);
|
||||
impl_as_prim_f32!(i16);
|
||||
impl_as_prim_f32!(i32);
|
||||
impl_as_prim_f32!(i64);
|
||||
impl_as_prim_f32!(f32);
|
||||
impl_as_prim_f32!(f64);
|
||||
|
||||
impl AsPrimF32 for BoolNum {
|
||||
fn as_prim_f32(&self) -> f32 {
|
||||
self.0 as f32
|
||||
}
|
||||
}
|
||||
|
||||
impl AsPrimF32 for StringNum {
|
||||
fn as_prim_f32(&self) -> f32 {
|
||||
netpod::log::error!("TODO impl AsPrimF32 for StringNum");
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl_num_ops!(u8, MIN, MAX, is_nan_int);
|
||||
impl_num_ops!(u16, MIN, MAX, is_nan_int);
|
||||
impl_num_ops!(u32, MIN, MAX, is_nan_int);
|
||||
@@ -114,3 +202,4 @@ impl_num_ops!(i64, MIN, MAX, is_nan_int);
|
||||
impl_num_ops!(f32, NAN, NAN, is_nan_float);
|
||||
impl_num_ops!(f64, NAN, NAN, is_nan_float);
|
||||
impl_num_ops!(BoolNum, MIN, MAX, is_nan_int);
|
||||
impl_num_ops!(StringNum, MIN, MAX, is_nan_int);
|
||||
|
||||
Reference in New Issue
Block a user