objectiveai_sdk/filesystem/config/
favorite.rs1use serde::{Serialize, Deserialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
4#[schemars(rename = "filesystem.config.Favorite")]
5pub struct Favorite {
6 name: String,
7 #[serde(flatten)]
8 #[schemars(schema_with = "crate::flatten_schema::<crate::RemotePathCommitOptional>")]
9 pub path: crate::RemotePathCommitOptional,
10 note: String,
11}
12
13impl Favorite {
14 pub fn new(
15 name: String,
16 path: crate::RemotePathCommitOptional,
17 note: String,
18 ) -> Result<Self, super::super::Error> {
19 validate_favorite_name(&name)?;
20 validate_favorite_note(¬e)?;
21 Ok(Self { name, path, note })
22 }
23
24 pub fn get_name(&self) -> &str {
25 &self.name
26 }
27
28 pub fn set_name(&mut self, name: String) -> Result<(), super::super::Error> {
29 validate_favorite_name(&name)?;
30 self.name = name;
31 Ok(())
32 }
33
34 pub fn get_note(&self) -> &str {
35 &self.note
36 }
37
38 pub fn set_note(&mut self, note: String) -> Result<(), super::super::Error> {
39 validate_favorite_note(¬e)?;
40 self.note = note;
41 Ok(())
42 }
43
44 pub fn path(&self) -> &crate::RemotePathCommitOptional {
45 &self.path
46 }
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
50#[schemars(rename = "filesystem.config.PairFavorite")]
51pub struct PairFavorite {
52 name: String,
53 pub function: crate::RemotePathCommitOptional,
54 pub profile: crate::RemotePathCommitOptional,
55 note: String,
56}
57
58impl PairFavorite {
59 pub fn new(
60 name: String,
61 function: crate::RemotePathCommitOptional,
62 profile: crate::RemotePathCommitOptional,
63 note: String,
64 ) -> Result<Self, super::super::Error> {
65 validate_favorite_name(&name)?;
66 validate_favorite_note(¬e)?;
67 Ok(Self { name, function, profile, note })
68 }
69
70 pub fn get_name(&self) -> &str {
71 &self.name
72 }
73
74 pub fn set_name(&mut self, name: String) -> Result<(), super::super::Error> {
75 validate_favorite_name(&name)?;
76 self.name = name;
77 Ok(())
78 }
79
80 pub fn get_note(&self) -> &str {
81 &self.note
82 }
83
84 pub fn set_note(&mut self, note: String) -> Result<(), super::super::Error> {
85 validate_favorite_note(¬e)?;
86 self.note = note;
87 Ok(())
88 }
89}
90
91pub fn validate_favorite_name(name: &str) -> Result<(), super::super::Error> {
93 if name.is_empty() || name.len() > 64 {
94 return Err(super::super::Error::InvalidFavoriteName(name.to_string()));
95 }
96 if !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '-') {
97 return Err(super::super::Error::InvalidFavoriteName(name.to_string()));
98 }
99 Ok(())
100}
101
102pub fn validate_favorite_note(note: &str) -> Result<(), super::super::Error> {
104 if note.len() > 512 {
105 return Err(super::super::Error::InvalidFavoriteNote(note.to_string()));
106 }
107 Ok(())
108}