xcell_types/
utils.rs

1use std::collections::BTreeSet;
2use xcell_errors::{for_3rd::DataType, XError, XErrorKind, XResult};
3
4#[macro_export]
5macro_rules! default_deserialize {
6    ($($t:ty),*) => {
7        $(
8            impl<'de> Deserialize<'de> for $t {
9                fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
10                where
11                    D: Deserializer<'de>,
12                {
13                    deserializer.deserialize_any(Self::default())
14                }
15            }
16        )*
17    };
18}
19
20pub fn type_mismatch<T, S>(except: S, cell: &DataType) -> XResult<T>
21where
22    S: Into<String>,
23{
24    let kind = XErrorKind::TypeMismatch { except: except.into(), current: cell.to_string() };
25    Err(XError::new(kind))
26}
27
28pub fn syntax_error<T, A>(msg: A) -> XResult<T>
29where
30    A: Into<String>,
31{
32    let kind = XErrorKind::SyntaxError { message: msg.into() };
33    Err(XError::new(kind))
34}
35
36pub fn push_delimiter(set: &mut BTreeSet<char>, new: &str) {
37    set.extend(new.chars().filter(|c| !c.is_ascii_whitespace()))
38}