vos_core/constraint/string_constraint/mod.rs
1use super::*;
2
3#[derive(Clone, Debug, Default, Serialize, Deserialize)]
4pub struct StringConstraint {
5 /// Minimum length of utf8 string
6 pub min_bytes: Option<u32>,
7 /// Maximum length of utf8 string
8 pub max_bytes: Option<u32>,
9 /// Minimum number of unicode characters
10 pub min_length: Option<u32>,
11 /// Maximum number of unicode characters
12 pub max_length: Option<u32>,
13
14 #[serde(flatten)]
15 pub info: SharedConstraint,
16}
17
18impl StringConstraint {
19 /// ```vos
20 /// type Integer: i32 {
21 /// .min: -1
22 /// }
23 /// ```
24 pub fn min_bytes(&mut self, n: &str) -> VosResult {
25 self.min_bytes = Some(u32::from_str(n)?);
26 Ok(())
27 }
28 /// ```vos
29 /// type Integer: i32 {
30 /// .max: +1
31 /// }
32 /// ```
33 pub fn max_bytes(&mut self, n: &str) -> VosResult {
34 self.max_bytes = Some(u32::from_str(n)?);
35 Ok(())
36 }
37 /// ```vos
38 /// type Positive: i32 {
39 /// .positive
40 /// }
41 /// ```
42 /// ```vos
43 /// type Integer: i32 {
44 /// .min: -1
45 /// }
46 /// ```
47 pub fn min_length(&mut self, n: &str) -> VosResult {
48 self.min_length = Some(u32::from_str(n)?);
49 Ok(())
50 }
51 /// ```vos
52 /// type Integer: i32 {
53 /// .max: +1
54 /// }
55 /// ```
56 pub fn max_length(&mut self, n: &str) -> VosResult {
57 self.max_length = Some(u32::from_str(n)?);
58 Ok(())
59 }
60 /// ```vos
61 /// type Positive: i32 {
62 /// .positive
63 /// }
64 /// ```
65 pub fn format(&mut self) {}
66}