xcell_types/vector/
mod.rs

1use std::{any::type_name, collections::BTreeSet, fmt::Formatter};
2
3use serde::{
4    de::{MapAccess, Visitor},
5    Deserialize, Deserializer, Serialize,
6};
7
8use serde_types::OneOrMany;
9use xcell_errors::{
10    for_3rd::{read_map_next_extra, read_map_next_value, DataType},
11    XResult,
12};
13
14use crate::{utils::push_delimiter, XCellTyped, XCellValue};
15
16mod der;
17mod parse_cell;
18
19#[derive(Debug, Clone, Serialize)]
20pub struct VectorDescription {
21    delimiter: BTreeSet<char>,
22    suffix: BTreeSet<String>,
23    typing: XCellTyped,
24    pub default: Vec<XCellValue>,
25}
26
27impl VectorDescription {
28    pub fn add_delimiter(&mut self, set: &str) {
29        push_delimiter(&mut self.delimiter, set)
30    }
31    pub fn add_suffix<S>(&mut self, suffix: S)
32    where
33        S: Into<String>,
34    {
35        self.suffix.insert(suffix.into());
36    }
37    pub fn matches_rest<'i>(&self, s: &'i str) -> Option<&'i str> {
38        for suffix in &self.suffix {
39            if s.to_ascii_lowercase().ends_with(&suffix.to_ascii_lowercase()) {
40                return Some(&s[0..s.len() - suffix.len()]);
41            }
42        }
43        None
44    }
45    pub fn get_type(&self) -> &XCellTyped {
46        &self.typing
47    }
48    pub fn set_type<T>(&mut self, typing: T)
49    where
50        T: Into<XCellTyped>,
51    {
52        self.typing = typing.into()
53    }
54    pub fn with_type<T>(mut self, typing: T) -> Self
55    where
56        T: Into<XCellTyped>,
57    {
58        self.typing = typing.into();
59        self
60    }
61}