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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::{any::type_name, collections::BTreeSet, fmt::Formatter};
use serde::{
de::{MapAccess, Visitor},
Deserialize, Deserializer, Serialize,
};
use serde_types::OneOrMany;
use xcell_errors::{
for_3rd::{read_map_next_extra, read_map_next_value, DataType},
XResult,
};
use crate::{utils::push_delimiter, XCellTyped, XCellValue};
mod der;
mod parse_cell;
#[derive(Debug, Clone, Serialize)]
pub struct VectorDescription {
delimiter: BTreeSet<char>,
suffix: BTreeSet<String>,
typing: XCellTyped,
pub default: Vec<XCellValue>,
}
impl VectorDescription {
pub fn add_delimiter(&mut self, set: &str) {
push_delimiter(&mut self.delimiter, set)
}
pub fn add_suffix<S>(&mut self, suffix: S)
where
S: Into<String>,
{
self.suffix.insert(suffix.into());
}
pub fn matches_rest<'i>(&self, s: &'i str) -> Option<&'i str> {
let normed = s.to_ascii_lowercase();
for suffix in &self.suffix {
if normed.ends_with(suffix) {
return Some(&s[0..s.len() - suffix.len()]);
}
}
None
}
pub fn get_type(&self) -> &XCellTyped {
&self.typing
}
pub fn set_type<T>(&mut self, typing: T)
where
T: Into<XCellTyped>,
{
self.typing = typing.into()
}
pub fn with_type<T>(mut self, typing: T) -> Self
where
T: Into<XCellTyped>,
{
self.typing = typing.into();
self
}
}