carbone_sdk_rust/
types.rs1use serde::{Deserialize, Serialize};
2
3use crate::errors::CarboneError;
4
5pub type Result<T> = std::result::Result<T, CarboneError>;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct ApiJsonToken(String);
11
12impl ApiJsonToken {
13 pub fn new(s: String) -> Result<Self> {
14 if s.len() >= 300 {
15 Ok(ApiJsonToken(s))
16 } else {
17 Err(CarboneError::Error("wrong token length".to_string()))
18 }
19 }
20
21 pub fn as_str(&self) -> &str {
22 &self.0
23 }
24}
25
26#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
27pub struct ApiVersion(String);
28
29impl ApiVersion {
30 pub fn new(s: String) -> Result<Self> {
31 if !s.is_empty() {
32 Ok(ApiVersion(s))
33 } else {
34 Err(CarboneError::Error("wrong token length".to_string()))
35 }
36 }
37
38 pub fn as_str(&self) -> &str {
39 &self.0
40 }
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
44pub struct Id(String);
45
46impl Id {
47 pub fn new<T: Into<String>>(id: T, type_name: &str) -> Result<Self> {
48 let id = id.into();
49 if !id.is_empty() {
50 Ok(Id(id))
51 } else {
52 Err(CarboneError::EmptyString(type_name.to_string()))
53 }
54 }
55 pub fn as_str(&self) -> &str {
56 &self.0
57 }
58}
59
60impl AsRef<str> for Id {
61 fn as_ref(&self) -> &str {
62 &self.0
63 }
64}
65
66#[derive(Debug, Clone, PartialEq, Eq)]
67pub struct JsonData {
68 render_options: String,
69}
70
71impl JsonData {
72 pub fn new(s: String) -> Result<Self> {
101 if s.is_empty() {
102 return Err(CarboneError::EmptyString("json_data".to_string()));
103 }
104 Ok(Self { render_options: s })
105 }
106
107 pub fn as_str(&self) -> &str {
108 &self.render_options
109 }
110}