ecli_server_codegen/
models.rs

1#![allow(unused_qualifications)]
2
3#[cfg(any(feature = "client", feature = "server"))]
4use crate::header;
5use crate::models;
6
7#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
8#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
9pub struct GeneralError {
10    /// description of the unexpected situation
11    #[serde(rename = "message")]
12    pub message: String,
13}
14
15impl GeneralError {
16    #[allow(clippy::new_without_default)]
17    pub fn new(message: String) -> GeneralError {
18        GeneralError { message }
19    }
20}
21
22/// Converts the GeneralError value to the Query Parameters representation (style=form, explode=false)
23/// specified in https://swagger.io/docs/specification/serialization/
24/// Should be implemented in a serde serializer
25impl std::string::ToString for GeneralError {
26    fn to_string(&self) -> String {
27        let params: Vec<Option<String>> =
28            vec![Some("message".to_string()), Some(self.message.to_string())];
29
30        params.into_iter().flatten().collect::<Vec<_>>().join(",")
31    }
32}
33
34/// Converts Query Parameters representation (style=form, explode=false) to a GeneralError value
35/// as specified in https://swagger.io/docs/specification/serialization/
36/// Should be implemented in a serde deserializer
37impl std::str::FromStr for GeneralError {
38    type Err = String;
39
40    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
41        /// An intermediate representation of the struct to use for parsing.
42        #[derive(Default)]
43        #[allow(dead_code)]
44        struct IntermediateRep {
45            pub message: Vec<String>,
46        }
47
48        let mut intermediate_rep = IntermediateRep::default();
49
50        // Parse into intermediate representation
51        let mut string_iter = s.split(',');
52        let mut key_result = string_iter.next();
53
54        while key_result.is_some() {
55            let val = match string_iter.next() {
56                Some(x) => x,
57                None => {
58                    return std::result::Result::Err(
59                        "Missing value while parsing GeneralError".to_string(),
60                    )
61                }
62            };
63
64            if let Some(key) = key_result {
65                #[allow(clippy::match_single_binding)]
66                match key {
67                    #[allow(clippy::redundant_clone)]
68                    "message" => intermediate_rep.message.push(
69                        <String as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
70                    ),
71                    _ => {
72                        return std::result::Result::Err(
73                            "Unexpected key while parsing GeneralError".to_string(),
74                        )
75                    }
76                }
77            }
78
79            // Get the next key
80            key_result = string_iter.next();
81        }
82
83        // Use the intermediate representation to return the struct
84        std::result::Result::Ok(GeneralError {
85            message: intermediate_rep
86                .message
87                .into_iter()
88                .next()
89                .ok_or_else(|| "message missing in GeneralError".to_string())?,
90        })
91    }
92}
93
94// Methods for converting between header::IntoHeaderValue<GeneralError> and hyper::header::HeaderValue
95
96#[cfg(any(feature = "client", feature = "server"))]
97impl std::convert::TryFrom<header::IntoHeaderValue<GeneralError>> for hyper::header::HeaderValue {
98    type Error = String;
99
100    fn try_from(
101        hdr_value: header::IntoHeaderValue<GeneralError>,
102    ) -> std::result::Result<Self, Self::Error> {
103        let hdr_value = hdr_value.to_string();
104        match hyper::header::HeaderValue::from_str(&hdr_value) {
105            std::result::Result::Ok(value) => std::result::Result::Ok(value),
106            std::result::Result::Err(e) => std::result::Result::Err(format!(
107                "Invalid header value for GeneralError - value: {} is invalid {}",
108                hdr_value, e
109            )),
110        }
111    }
112}
113
114#[cfg(any(feature = "client", feature = "server"))]
115impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<GeneralError> {
116    type Error = String;
117
118    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
119        match hdr_value.to_str() {
120            std::result::Result::Ok(value) => {
121                match <GeneralError as std::str::FromStr>::from_str(value) {
122                    std::result::Result::Ok(value) => {
123                        std::result::Result::Ok(header::IntoHeaderValue(value))
124                    }
125                    std::result::Result::Err(err) => std::result::Result::Err(format!(
126                        "Unable to convert header value '{}' into GeneralError - {}",
127                        value, err
128                    )),
129                }
130            }
131            std::result::Result::Err(e) => std::result::Result::Err(format!(
132                "Unable to convert header: {:?} to string: {}",
133                hdr_value, e
134            )),
135        }
136    }
137}
138
139#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
140#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
141pub struct GetTaskLogRequest {
142    /// The program ID
143    #[serde(rename = "id")]
144    pub id: u64,
145
146    /// Only fetch logs after this cursor (included). If not provided, return logs stored with minimum cursor
147    #[serde(rename = "log_cursor")]
148    #[serde(skip_serializing_if = "Option::is_none")]
149    pub log_cursor: Option<u64>,
150
151    /// Fetch at most such number of logs. If not provided, use a default value that server specified
152    #[serde(rename = "maximum_count")]
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub maximum_count: Option<u64>,
155}
156
157impl GetTaskLogRequest {
158    #[allow(clippy::new_without_default)]
159    pub fn new(id: u64) -> GetTaskLogRequest {
160        GetTaskLogRequest {
161            id,
162            log_cursor: None,
163            maximum_count: None,
164        }
165    }
166}
167
168/// Converts the GetTaskLogRequest value to the Query Parameters representation (style=form, explode=false)
169/// specified in https://swagger.io/docs/specification/serialization/
170/// Should be implemented in a serde serializer
171impl std::string::ToString for GetTaskLogRequest {
172    fn to_string(&self) -> String {
173        let params: Vec<Option<String>> = vec![
174            Some("id".to_string()),
175            Some(self.id.to_string()),
176            self.log_cursor
177                .as_ref()
178                .map(|log_cursor| vec!["log_cursor".to_string(), log_cursor.to_string()].join(",")),
179            self.maximum_count.as_ref().map(|maximum_count| {
180                vec!["maximum_count".to_string(), maximum_count.to_string()].join(",")
181            }),
182        ];
183
184        params.into_iter().flatten().collect::<Vec<_>>().join(",")
185    }
186}
187
188/// Converts Query Parameters representation (style=form, explode=false) to a GetTaskLogRequest value
189/// as specified in https://swagger.io/docs/specification/serialization/
190/// Should be implemented in a serde deserializer
191impl std::str::FromStr for GetTaskLogRequest {
192    type Err = String;
193
194    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
195        /// An intermediate representation of the struct to use for parsing.
196        #[derive(Default)]
197        #[allow(dead_code)]
198        struct IntermediateRep {
199            pub id: Vec<u64>,
200            pub log_cursor: Vec<u64>,
201            pub maximum_count: Vec<u64>,
202        }
203
204        let mut intermediate_rep = IntermediateRep::default();
205
206        // Parse into intermediate representation
207        let mut string_iter = s.split(',');
208        let mut key_result = string_iter.next();
209
210        while key_result.is_some() {
211            let val = match string_iter.next() {
212                Some(x) => x,
213                None => {
214                    return std::result::Result::Err(
215                        "Missing value while parsing GetTaskLogRequest".to_string(),
216                    )
217                }
218            };
219
220            if let Some(key) = key_result {
221                #[allow(clippy::match_single_binding)]
222                match key {
223                    #[allow(clippy::redundant_clone)]
224                    "id" => intermediate_rep.id.push(
225                        <u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
226                    ),
227                    #[allow(clippy::redundant_clone)]
228                    "log_cursor" => intermediate_rep.log_cursor.push(
229                        <u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
230                    ),
231                    #[allow(clippy::redundant_clone)]
232                    "maximum_count" => intermediate_rep.maximum_count.push(
233                        <u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
234                    ),
235                    _ => {
236                        return std::result::Result::Err(
237                            "Unexpected key while parsing GetTaskLogRequest".to_string(),
238                        )
239                    }
240                }
241            }
242
243            // Get the next key
244            key_result = string_iter.next();
245        }
246
247        // Use the intermediate representation to return the struct
248        std::result::Result::Ok(GetTaskLogRequest {
249            id: intermediate_rep
250                .id
251                .into_iter()
252                .next()
253                .ok_or_else(|| "id missing in GetTaskLogRequest".to_string())?,
254            log_cursor: intermediate_rep.log_cursor.into_iter().next(),
255            maximum_count: intermediate_rep.maximum_count.into_iter().next(),
256        })
257    }
258}
259
260// Methods for converting between header::IntoHeaderValue<GetTaskLogRequest> and hyper::header::HeaderValue
261
262#[cfg(any(feature = "client", feature = "server"))]
263impl std::convert::TryFrom<header::IntoHeaderValue<GetTaskLogRequest>>
264    for hyper::header::HeaderValue
265{
266    type Error = String;
267
268    fn try_from(
269        hdr_value: header::IntoHeaderValue<GetTaskLogRequest>,
270    ) -> std::result::Result<Self, Self::Error> {
271        let hdr_value = hdr_value.to_string();
272        match hyper::header::HeaderValue::from_str(&hdr_value) {
273            std::result::Result::Ok(value) => std::result::Result::Ok(value),
274            std::result::Result::Err(e) => std::result::Result::Err(format!(
275                "Invalid header value for GetTaskLogRequest - value: {} is invalid {}",
276                hdr_value, e
277            )),
278        }
279    }
280}
281
282#[cfg(any(feature = "client", feature = "server"))]
283impl std::convert::TryFrom<hyper::header::HeaderValue>
284    for header::IntoHeaderValue<GetTaskLogRequest>
285{
286    type Error = String;
287
288    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
289        match hdr_value.to_str() {
290            std::result::Result::Ok(value) => {
291                match <GetTaskLogRequest as std::str::FromStr>::from_str(value) {
292                    std::result::Result::Ok(value) => {
293                        std::result::Result::Ok(header::IntoHeaderValue(value))
294                    }
295                    std::result::Result::Err(err) => std::result::Result::Err(format!(
296                        "Unable to convert header value '{}' into GetTaskLogRequest - {}",
297                        value, err
298                    )),
299                }
300            }
301            std::result::Result::Err(e) => std::result::Result::Err(format!(
302                "Unable to convert header: {:?} to string: {}",
303                hdr_value, e
304            )),
305        }
306    }
307}
308
309#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
310#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
311pub struct GetTaskLogResponseInner {
312    #[serde(rename = "cursor")]
313    pub cursor: u64,
314
315    #[serde(rename = "log")]
316    pub log: models::GetTaskLogResponseInnerLog,
317}
318
319impl GetTaskLogResponseInner {
320    #[allow(clippy::new_without_default)]
321    pub fn new(cursor: u64, log: models::GetTaskLogResponseInnerLog) -> GetTaskLogResponseInner {
322        GetTaskLogResponseInner { cursor, log }
323    }
324}
325
326/// Converts the GetTaskLogResponseInner value to the Query Parameters representation (style=form, explode=false)
327/// specified in https://swagger.io/docs/specification/serialization/
328/// Should be implemented in a serde serializer
329impl std::string::ToString for GetTaskLogResponseInner {
330    fn to_string(&self) -> String {
331        let params: Vec<Option<String>> = vec![
332            Some("cursor".to_string()),
333            Some(self.cursor.to_string()),
334            // Skipping log in query parameter serialization
335        ];
336
337        params.into_iter().flatten().collect::<Vec<_>>().join(",")
338    }
339}
340
341/// Converts Query Parameters representation (style=form, explode=false) to a GetTaskLogResponseInner value
342/// as specified in https://swagger.io/docs/specification/serialization/
343/// Should be implemented in a serde deserializer
344impl std::str::FromStr for GetTaskLogResponseInner {
345    type Err = String;
346
347    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
348        /// An intermediate representation of the struct to use for parsing.
349        #[derive(Default)]
350        #[allow(dead_code)]
351        struct IntermediateRep {
352            pub cursor: Vec<u64>,
353            pub log: Vec<models::GetTaskLogResponseInnerLog>,
354        }
355
356        let mut intermediate_rep = IntermediateRep::default();
357
358        // Parse into intermediate representation
359        let mut string_iter = s.split(',');
360        let mut key_result = string_iter.next();
361
362        while key_result.is_some() {
363            let val = match string_iter.next() {
364                Some(x) => x,
365                None => {
366                    return std::result::Result::Err(
367                        "Missing value while parsing GetTaskLogResponseInner".to_string(),
368                    )
369                }
370            };
371
372            if let Some(key) = key_result {
373                #[allow(clippy::match_single_binding)]
374                match key {
375                    #[allow(clippy::redundant_clone)]
376                    "cursor" => intermediate_rep.cursor.push(
377                        <u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
378                    ),
379                    #[allow(clippy::redundant_clone)]
380                    "log" => intermediate_rep.log.push(
381                        <models::GetTaskLogResponseInnerLog as std::str::FromStr>::from_str(val)
382                            .map_err(|x| x.to_string())?,
383                    ),
384                    _ => {
385                        return std::result::Result::Err(
386                            "Unexpected key while parsing GetTaskLogResponseInner".to_string(),
387                        )
388                    }
389                }
390            }
391
392            // Get the next key
393            key_result = string_iter.next();
394        }
395
396        // Use the intermediate representation to return the struct
397        std::result::Result::Ok(GetTaskLogResponseInner {
398            cursor: intermediate_rep
399                .cursor
400                .into_iter()
401                .next()
402                .ok_or_else(|| "cursor missing in GetTaskLogResponseInner".to_string())?,
403            log: intermediate_rep
404                .log
405                .into_iter()
406                .next()
407                .ok_or_else(|| "log missing in GetTaskLogResponseInner".to_string())?,
408        })
409    }
410}
411
412// Methods for converting between header::IntoHeaderValue<GetTaskLogResponseInner> and hyper::header::HeaderValue
413
414#[cfg(any(feature = "client", feature = "server"))]
415impl std::convert::TryFrom<header::IntoHeaderValue<GetTaskLogResponseInner>>
416    for hyper::header::HeaderValue
417{
418    type Error = String;
419
420    fn try_from(
421        hdr_value: header::IntoHeaderValue<GetTaskLogResponseInner>,
422    ) -> std::result::Result<Self, Self::Error> {
423        let hdr_value = hdr_value.to_string();
424        match hyper::header::HeaderValue::from_str(&hdr_value) {
425            std::result::Result::Ok(value) => std::result::Result::Ok(value),
426            std::result::Result::Err(e) => std::result::Result::Err(format!(
427                "Invalid header value for GetTaskLogResponseInner - value: {} is invalid {}",
428                hdr_value, e
429            )),
430        }
431    }
432}
433
434#[cfg(any(feature = "client", feature = "server"))]
435impl std::convert::TryFrom<hyper::header::HeaderValue>
436    for header::IntoHeaderValue<GetTaskLogResponseInner>
437{
438    type Error = String;
439
440    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
441        match hdr_value.to_str() {
442            std::result::Result::Ok(value) => {
443                match <GetTaskLogResponseInner as std::str::FromStr>::from_str(value) {
444                    std::result::Result::Ok(value) => {
445                        std::result::Result::Ok(header::IntoHeaderValue(value))
446                    }
447                    std::result::Result::Err(err) => std::result::Result::Err(format!(
448                        "Unable to convert header value '{}' into GetTaskLogResponseInner - {}",
449                        value, err
450                    )),
451                }
452            }
453            std::result::Result::Err(e) => std::result::Result::Err(format!(
454                "Unable to convert header: {:?} to string: {}",
455                hdr_value, e
456            )),
457        }
458    }
459}
460
461#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
462#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
463pub struct GetTaskLogResponseInnerLog {
464    #[serde(rename = "log")]
465    pub log: String,
466
467    #[serde(rename = "timestamp")]
468    pub timestamp: u64,
469
470    #[serde(rename = "log_type")]
471    pub log_type: models::LogType,
472}
473
474impl GetTaskLogResponseInnerLog {
475    #[allow(clippy::new_without_default)]
476    pub fn new(
477        log: String,
478        timestamp: u64,
479        log_type: models::LogType,
480    ) -> GetTaskLogResponseInnerLog {
481        GetTaskLogResponseInnerLog {
482            log,
483            timestamp,
484            log_type,
485        }
486    }
487}
488
489/// Converts the GetTaskLogResponseInnerLog value to the Query Parameters representation (style=form, explode=false)
490/// specified in https://swagger.io/docs/specification/serialization/
491/// Should be implemented in a serde serializer
492impl std::string::ToString for GetTaskLogResponseInnerLog {
493    fn to_string(&self) -> String {
494        let params: Vec<Option<String>> = vec![
495            Some("log".to_string()),
496            Some(self.log.to_string()),
497            Some("timestamp".to_string()),
498            Some(self.timestamp.to_string()),
499            // Skipping log_type in query parameter serialization
500        ];
501
502        params.into_iter().flatten().collect::<Vec<_>>().join(",")
503    }
504}
505
506/// Converts Query Parameters representation (style=form, explode=false) to a GetTaskLogResponseInnerLog value
507/// as specified in https://swagger.io/docs/specification/serialization/
508/// Should be implemented in a serde deserializer
509impl std::str::FromStr for GetTaskLogResponseInnerLog {
510    type Err = String;
511
512    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
513        /// An intermediate representation of the struct to use for parsing.
514        #[derive(Default)]
515        #[allow(dead_code)]
516        struct IntermediateRep {
517            pub log: Vec<String>,
518            pub timestamp: Vec<u64>,
519            pub log_type: Vec<models::LogType>,
520        }
521
522        let mut intermediate_rep = IntermediateRep::default();
523
524        // Parse into intermediate representation
525        let mut string_iter = s.split(',');
526        let mut key_result = string_iter.next();
527
528        while key_result.is_some() {
529            let val = match string_iter.next() {
530                Some(x) => x,
531                None => {
532                    return std::result::Result::Err(
533                        "Missing value while parsing GetTaskLogResponseInnerLog".to_string(),
534                    )
535                }
536            };
537
538            if let Some(key) = key_result {
539                #[allow(clippy::match_single_binding)]
540                match key {
541                    #[allow(clippy::redundant_clone)]
542                    "log" => intermediate_rep.log.push(
543                        <String as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
544                    ),
545                    #[allow(clippy::redundant_clone)]
546                    "timestamp" => intermediate_rep.timestamp.push(
547                        <u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
548                    ),
549                    #[allow(clippy::redundant_clone)]
550                    "log_type" => intermediate_rep.log_type.push(
551                        <models::LogType as std::str::FromStr>::from_str(val)
552                            .map_err(|x| x.to_string())?,
553                    ),
554                    _ => {
555                        return std::result::Result::Err(
556                            "Unexpected key while parsing GetTaskLogResponseInnerLog".to_string(),
557                        )
558                    }
559                }
560            }
561
562            // Get the next key
563            key_result = string_iter.next();
564        }
565
566        // Use the intermediate representation to return the struct
567        std::result::Result::Ok(GetTaskLogResponseInnerLog {
568            log: intermediate_rep
569                .log
570                .into_iter()
571                .next()
572                .ok_or_else(|| "log missing in GetTaskLogResponseInnerLog".to_string())?,
573            timestamp: intermediate_rep
574                .timestamp
575                .into_iter()
576                .next()
577                .ok_or_else(|| "timestamp missing in GetTaskLogResponseInnerLog".to_string())?,
578            log_type: intermediate_rep
579                .log_type
580                .into_iter()
581                .next()
582                .ok_or_else(|| "log_type missing in GetTaskLogResponseInnerLog".to_string())?,
583        })
584    }
585}
586
587// Methods for converting between header::IntoHeaderValue<GetTaskLogResponseInnerLog> and hyper::header::HeaderValue
588
589#[cfg(any(feature = "client", feature = "server"))]
590impl std::convert::TryFrom<header::IntoHeaderValue<GetTaskLogResponseInnerLog>>
591    for hyper::header::HeaderValue
592{
593    type Error = String;
594
595    fn try_from(
596        hdr_value: header::IntoHeaderValue<GetTaskLogResponseInnerLog>,
597    ) -> std::result::Result<Self, Self::Error> {
598        let hdr_value = hdr_value.to_string();
599        match hyper::header::HeaderValue::from_str(&hdr_value) {
600            std::result::Result::Ok(value) => std::result::Result::Ok(value),
601            std::result::Result::Err(e) => std::result::Result::Err(format!(
602                "Invalid header value for GetTaskLogResponseInnerLog - value: {} is invalid {}",
603                hdr_value, e
604            )),
605        }
606    }
607}
608
609#[cfg(any(feature = "client", feature = "server"))]
610impl std::convert::TryFrom<hyper::header::HeaderValue>
611    for header::IntoHeaderValue<GetTaskLogResponseInnerLog>
612{
613    type Error = String;
614
615    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
616        match hdr_value.to_str() {
617            std::result::Result::Ok(value) => {
618                match <GetTaskLogResponseInnerLog as std::str::FromStr>::from_str(value) {
619                    std::result::Result::Ok(value) => {
620                        std::result::Result::Ok(header::IntoHeaderValue(value))
621                    }
622                    std::result::Result::Err(err) => std::result::Result::Err(format!(
623                        "Unable to convert header value '{}' into GetTaskLogResponseInnerLog - {}",
624                        value, err
625                    )),
626                }
627            }
628            std::result::Result::Err(e) => std::result::Result::Err(format!(
629                "Unable to convert header: {:?} to string: {}",
630                hdr_value, e
631            )),
632        }
633    }
634}
635
636/// Enumeration of values.
637/// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]`
638/// which helps with FFI.
639#[allow(non_camel_case_types)]
640#[repr(C)]
641#[derive(
642    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
643)]
644#[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))]
645pub enum LogType {
646    #[serde(rename = "stderr")]
647    Stderr,
648    #[serde(rename = "stdout")]
649    Stdout,
650    #[serde(rename = "plain")]
651    Plain,
652}
653
654impl std::fmt::Display for LogType {
655    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
656        match *self {
657            LogType::Stderr => write!(f, "stderr"),
658            LogType::Stdout => write!(f, "stdout"),
659            LogType::Plain => write!(f, "plain"),
660        }
661    }
662}
663
664impl std::str::FromStr for LogType {
665    type Err = String;
666
667    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
668        match s {
669            "stderr" => std::result::Result::Ok(LogType::Stderr),
670            "stdout" => std::result::Result::Ok(LogType::Stdout),
671            "plain" => std::result::Result::Ok(LogType::Plain),
672            _ => std::result::Result::Err(format!("Value not valid: {}", s)),
673        }
674    }
675}
676
677/// Enumeration of values.
678/// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]`
679/// which helps with FFI.
680#[allow(non_camel_case_types)]
681#[repr(C)]
682#[derive(
683    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
684)]
685#[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))]
686pub enum ProgramType {
687    #[serde(rename = "wasm")]
688    Wasm,
689    #[serde(rename = "json")]
690    Json,
691    #[serde(rename = "tar")]
692    Tar,
693}
694
695impl std::fmt::Display for ProgramType {
696    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
697        match *self {
698            ProgramType::Wasm => write!(f, "wasm"),
699            ProgramType::Json => write!(f, "json"),
700            ProgramType::Tar => write!(f, "tar"),
701        }
702    }
703}
704
705impl std::str::FromStr for ProgramType {
706    type Err = String;
707
708    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
709        match s {
710            "wasm" => std::result::Result::Ok(ProgramType::Wasm),
711            "json" => std::result::Result::Ok(ProgramType::Json),
712            "tar" => std::result::Result::Ok(ProgramType::Tar),
713            _ => std::result::Result::Err(format!("Value not valid: {}", s)),
714        }
715    }
716}
717
718#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
719#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
720pub struct SimpleIdRequest {
721    #[serde(rename = "id")]
722    pub id: u64,
723}
724
725impl SimpleIdRequest {
726    #[allow(clippy::new_without_default)]
727    pub fn new(id: u64) -> SimpleIdRequest {
728        SimpleIdRequest { id }
729    }
730}
731
732/// Converts the SimpleIdRequest value to the Query Parameters representation (style=form, explode=false)
733/// specified in https://swagger.io/docs/specification/serialization/
734/// Should be implemented in a serde serializer
735impl std::string::ToString for SimpleIdRequest {
736    fn to_string(&self) -> String {
737        let params: Vec<Option<String>> = vec![Some("id".to_string()), Some(self.id.to_string())];
738
739        params.into_iter().flatten().collect::<Vec<_>>().join(",")
740    }
741}
742
743/// Converts Query Parameters representation (style=form, explode=false) to a SimpleIdRequest value
744/// as specified in https://swagger.io/docs/specification/serialization/
745/// Should be implemented in a serde deserializer
746impl std::str::FromStr for SimpleIdRequest {
747    type Err = String;
748
749    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
750        /// An intermediate representation of the struct to use for parsing.
751        #[derive(Default)]
752        #[allow(dead_code)]
753        struct IntermediateRep {
754            pub id: Vec<u64>,
755        }
756
757        let mut intermediate_rep = IntermediateRep::default();
758
759        // Parse into intermediate representation
760        let mut string_iter = s.split(',');
761        let mut key_result = string_iter.next();
762
763        while key_result.is_some() {
764            let val = match string_iter.next() {
765                Some(x) => x,
766                None => {
767                    return std::result::Result::Err(
768                        "Missing value while parsing SimpleIdRequest".to_string(),
769                    )
770                }
771            };
772
773            if let Some(key) = key_result {
774                #[allow(clippy::match_single_binding)]
775                match key {
776                    #[allow(clippy::redundant_clone)]
777                    "id" => intermediate_rep.id.push(
778                        <u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
779                    ),
780                    _ => {
781                        return std::result::Result::Err(
782                            "Unexpected key while parsing SimpleIdRequest".to_string(),
783                        )
784                    }
785                }
786            }
787
788            // Get the next key
789            key_result = string_iter.next();
790        }
791
792        // Use the intermediate representation to return the struct
793        std::result::Result::Ok(SimpleIdRequest {
794            id: intermediate_rep
795                .id
796                .into_iter()
797                .next()
798                .ok_or_else(|| "id missing in SimpleIdRequest".to_string())?,
799        })
800    }
801}
802
803// Methods for converting between header::IntoHeaderValue<SimpleIdRequest> and hyper::header::HeaderValue
804
805#[cfg(any(feature = "client", feature = "server"))]
806impl std::convert::TryFrom<header::IntoHeaderValue<SimpleIdRequest>>
807    for hyper::header::HeaderValue
808{
809    type Error = String;
810
811    fn try_from(
812        hdr_value: header::IntoHeaderValue<SimpleIdRequest>,
813    ) -> std::result::Result<Self, Self::Error> {
814        let hdr_value = hdr_value.to_string();
815        match hyper::header::HeaderValue::from_str(&hdr_value) {
816            std::result::Result::Ok(value) => std::result::Result::Ok(value),
817            std::result::Result::Err(e) => std::result::Result::Err(format!(
818                "Invalid header value for SimpleIdRequest - value: {} is invalid {}",
819                hdr_value, e
820            )),
821        }
822    }
823}
824
825#[cfg(any(feature = "client", feature = "server"))]
826impl std::convert::TryFrom<hyper::header::HeaderValue>
827    for header::IntoHeaderValue<SimpleIdRequest>
828{
829    type Error = String;
830
831    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
832        match hdr_value.to_str() {
833            std::result::Result::Ok(value) => {
834                match <SimpleIdRequest as std::str::FromStr>::from_str(value) {
835                    std::result::Result::Ok(value) => {
836                        std::result::Result::Ok(header::IntoHeaderValue(value))
837                    }
838                    std::result::Result::Err(err) => std::result::Result::Err(format!(
839                        "Unable to convert header value '{}' into SimpleIdRequest - {}",
840                        value, err
841                    )),
842                }
843            }
844            std::result::Result::Err(e) => std::result::Result::Err(format!(
845                "Unable to convert header: {:?} to string: {}",
846                hdr_value, e
847            )),
848        }
849    }
850}
851
852#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
853#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
854pub struct StartTask200Response {
855    #[serde(rename = "id")]
856    pub id: u64,
857
858    #[serde(rename = "task_list")]
859    pub task_list: models::TaskListResponse,
860}
861
862impl StartTask200Response {
863    #[allow(clippy::new_without_default)]
864    pub fn new(id: u64, task_list: models::TaskListResponse) -> StartTask200Response {
865        StartTask200Response { id, task_list }
866    }
867}
868
869/// Converts the StartTask200Response value to the Query Parameters representation (style=form, explode=false)
870/// specified in https://swagger.io/docs/specification/serialization/
871/// Should be implemented in a serde serializer
872impl std::string::ToString for StartTask200Response {
873    fn to_string(&self) -> String {
874        let params: Vec<Option<String>> = vec![
875            Some("id".to_string()),
876            Some(self.id.to_string()),
877            // Skipping task_list in query parameter serialization
878        ];
879
880        params.into_iter().flatten().collect::<Vec<_>>().join(",")
881    }
882}
883
884/// Converts Query Parameters representation (style=form, explode=false) to a StartTask200Response value
885/// as specified in https://swagger.io/docs/specification/serialization/
886/// Should be implemented in a serde deserializer
887impl std::str::FromStr for StartTask200Response {
888    type Err = String;
889
890    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
891        /// An intermediate representation of the struct to use for parsing.
892        #[derive(Default)]
893        #[allow(dead_code)]
894        struct IntermediateRep {
895            pub id: Vec<u64>,
896            pub task_list: Vec<models::TaskListResponse>,
897        }
898
899        let mut intermediate_rep = IntermediateRep::default();
900
901        // Parse into intermediate representation
902        let mut string_iter = s.split(',');
903        let mut key_result = string_iter.next();
904
905        while key_result.is_some() {
906            let val = match string_iter.next() {
907                Some(x) => x,
908                None => {
909                    return std::result::Result::Err(
910                        "Missing value while parsing StartTask200Response".to_string(),
911                    )
912                }
913            };
914
915            if let Some(key) = key_result {
916                #[allow(clippy::match_single_binding)]
917                match key {
918                    #[allow(clippy::redundant_clone)]
919                    "id" => intermediate_rep.id.push(
920                        <u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
921                    ),
922                    #[allow(clippy::redundant_clone)]
923                    "task_list" => intermediate_rep.task_list.push(
924                        <models::TaskListResponse as std::str::FromStr>::from_str(val)
925                            .map_err(|x| x.to_string())?,
926                    ),
927                    _ => {
928                        return std::result::Result::Err(
929                            "Unexpected key while parsing StartTask200Response".to_string(),
930                        )
931                    }
932                }
933            }
934
935            // Get the next key
936            key_result = string_iter.next();
937        }
938
939        // Use the intermediate representation to return the struct
940        std::result::Result::Ok(StartTask200Response {
941            id: intermediate_rep
942                .id
943                .into_iter()
944                .next()
945                .ok_or_else(|| "id missing in StartTask200Response".to_string())?,
946            task_list: intermediate_rep
947                .task_list
948                .into_iter()
949                .next()
950                .ok_or_else(|| "task_list missing in StartTask200Response".to_string())?,
951        })
952    }
953}
954
955// Methods for converting between header::IntoHeaderValue<StartTask200Response> and hyper::header::HeaderValue
956
957#[cfg(any(feature = "client", feature = "server"))]
958impl std::convert::TryFrom<header::IntoHeaderValue<StartTask200Response>>
959    for hyper::header::HeaderValue
960{
961    type Error = String;
962
963    fn try_from(
964        hdr_value: header::IntoHeaderValue<StartTask200Response>,
965    ) -> std::result::Result<Self, Self::Error> {
966        let hdr_value = hdr_value.to_string();
967        match hyper::header::HeaderValue::from_str(&hdr_value) {
968            std::result::Result::Ok(value) => std::result::Result::Ok(value),
969            std::result::Result::Err(e) => std::result::Result::Err(format!(
970                "Invalid header value for StartTask200Response - value: {} is invalid {}",
971                hdr_value, e
972            )),
973        }
974    }
975}
976
977#[cfg(any(feature = "client", feature = "server"))]
978impl std::convert::TryFrom<hyper::header::HeaderValue>
979    for header::IntoHeaderValue<StartTask200Response>
980{
981    type Error = String;
982
983    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
984        match hdr_value.to_str() {
985            std::result::Result::Ok(value) => {
986                match <StartTask200Response as std::str::FromStr>::from_str(value) {
987                    std::result::Result::Ok(value) => {
988                        std::result::Result::Ok(header::IntoHeaderValue(value))
989                    }
990                    std::result::Result::Err(err) => std::result::Result::Err(format!(
991                        "Unable to convert header value '{}' into StartTask200Response - {}",
992                        value, err
993                    )),
994                }
995            }
996            std::result::Result::Err(e) => std::result::Result::Err(format!(
997                "Unable to convert header: {:?} to string: {}",
998                hdr_value, e
999            )),
1000        }
1001    }
1002}
1003
1004#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
1005#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
1006pub struct StartTaskRequest {
1007    /// Base64-encoded program data
1008    #[serde(rename = "program_data_buf")]
1009    pub program_data_buf: String,
1010
1011    #[serde(rename = "program_type")]
1012    pub program_type: models::ProgramType,
1013
1014    /// The name of the program. If not provided, will generate a random one
1015    #[serde(rename = "program_name")]
1016    #[serde(skip_serializing_if = "Option::is_none")]
1017    pub program_name: Option<String>,
1018
1019    /// Btf archive path in the server.
1020    #[serde(rename = "btf_archive_path")]
1021    #[serde(skip_serializing_if = "Option::is_none")]
1022    pub btf_archive_path: Option<String>,
1023
1024    /// Command line arguments to the eBPF program
1025    #[serde(rename = "extra_args")]
1026    #[serde(skip_serializing_if = "Option::is_none")]
1027    pub extra_args: Option<Vec<String>>,
1028
1029    /// Whether to let the bpf-loader program dumps json. Only works for json & tar program
1030    #[serde(rename = "export_json")]
1031    #[serde(skip_serializing_if = "Option::is_none")]
1032    pub export_json: Option<bool>,
1033}
1034
1035impl StartTaskRequest {
1036    #[allow(clippy::new_without_default)]
1037    pub fn new(program_data_buf: String, program_type: models::ProgramType) -> StartTaskRequest {
1038        StartTaskRequest {
1039            program_data_buf,
1040            program_type,
1041            program_name: None,
1042            btf_archive_path: None,
1043            extra_args: None,
1044            export_json: None,
1045        }
1046    }
1047}
1048
1049/// Converts the StartTaskRequest value to the Query Parameters representation (style=form, explode=false)
1050/// specified in https://swagger.io/docs/specification/serialization/
1051/// Should be implemented in a serde serializer
1052impl std::string::ToString for StartTaskRequest {
1053    fn to_string(&self) -> String {
1054        let params: Vec<Option<String>> = vec![
1055            Some("program_data_buf".to_string()),
1056            Some(self.program_data_buf.to_string()),
1057            // Skipping program_type in query parameter serialization
1058            self.program_name.as_ref().map(|program_name| {
1059                vec!["program_name".to_string(), program_name.to_string()].join(",")
1060            }),
1061            self.btf_archive_path.as_ref().map(|btf_archive_path| {
1062                vec!["btf_archive_path".to_string(), btf_archive_path.to_string()].join(",")
1063            }),
1064            self.extra_args.as_ref().map(|extra_args| {
1065                vec![
1066                    "extra_args".to_string(),
1067                    extra_args
1068                        .iter()
1069                        .map(|x| x.to_string())
1070                        .collect::<Vec<_>>()
1071                        .join(","),
1072                ]
1073                .join(",")
1074            }),
1075            self.export_json.as_ref().map(|export_json| {
1076                vec!["export_json".to_string(), export_json.to_string()].join(",")
1077            }),
1078        ];
1079
1080        params.into_iter().flatten().collect::<Vec<_>>().join(",")
1081    }
1082}
1083
1084/// Converts Query Parameters representation (style=form, explode=false) to a StartTaskRequest value
1085/// as specified in https://swagger.io/docs/specification/serialization/
1086/// Should be implemented in a serde deserializer
1087impl std::str::FromStr for StartTaskRequest {
1088    type Err = String;
1089
1090    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
1091        /// An intermediate representation of the struct to use for parsing.
1092        #[derive(Default)]
1093        #[allow(dead_code)]
1094        struct IntermediateRep {
1095            pub program_data_buf: Vec<String>,
1096            pub program_type: Vec<models::ProgramType>,
1097            pub program_name: Vec<String>,
1098            pub btf_archive_path: Vec<String>,
1099            pub extra_args: Vec<Vec<String>>,
1100            pub export_json: Vec<bool>,
1101        }
1102
1103        let mut intermediate_rep = IntermediateRep::default();
1104
1105        // Parse into intermediate representation
1106        let mut string_iter = s.split(',');
1107        let mut key_result = string_iter.next();
1108
1109        while key_result.is_some() {
1110            let val = match string_iter.next() {
1111                Some(x) => x,
1112                None => {
1113                    return std::result::Result::Err(
1114                        "Missing value while parsing StartTaskRequest".to_string(),
1115                    )
1116                }
1117            };
1118
1119            if let Some(key) = key_result {
1120                #[allow(clippy::match_single_binding)]
1121                match key {
1122                    #[allow(clippy::redundant_clone)]
1123                    "program_data_buf" => intermediate_rep.program_data_buf.push(
1124                        <String as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
1125                    ),
1126                    #[allow(clippy::redundant_clone)]
1127                    "program_type" => intermediate_rep.program_type.push(
1128                        <models::ProgramType as std::str::FromStr>::from_str(val)
1129                            .map_err(|x| x.to_string())?,
1130                    ),
1131                    #[allow(clippy::redundant_clone)]
1132                    "program_name" => intermediate_rep.program_name.push(
1133                        <String as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
1134                    ),
1135                    #[allow(clippy::redundant_clone)]
1136                    "btf_archive_path" => intermediate_rep.btf_archive_path.push(
1137                        <String as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
1138                    ),
1139                    "extra_args" => return std::result::Result::Err(
1140                        "Parsing a container in this style is not supported in StartTaskRequest"
1141                            .to_string(),
1142                    ),
1143                    #[allow(clippy::redundant_clone)]
1144                    "export_json" => intermediate_rep.export_json.push(
1145                        <bool as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
1146                    ),
1147                    _ => {
1148                        return std::result::Result::Err(
1149                            "Unexpected key while parsing StartTaskRequest".to_string(),
1150                        )
1151                    }
1152                }
1153            }
1154
1155            // Get the next key
1156            key_result = string_iter.next();
1157        }
1158
1159        // Use the intermediate representation to return the struct
1160        std::result::Result::Ok(StartTaskRequest {
1161            program_data_buf: intermediate_rep
1162                .program_data_buf
1163                .into_iter()
1164                .next()
1165                .ok_or_else(|| "program_data_buf missing in StartTaskRequest".to_string())?,
1166            program_type: intermediate_rep
1167                .program_type
1168                .into_iter()
1169                .next()
1170                .ok_or_else(|| "program_type missing in StartTaskRequest".to_string())?,
1171            program_name: intermediate_rep.program_name.into_iter().next(),
1172            btf_archive_path: intermediate_rep.btf_archive_path.into_iter().next(),
1173            extra_args: intermediate_rep.extra_args.into_iter().next(),
1174            export_json: intermediate_rep.export_json.into_iter().next(),
1175        })
1176    }
1177}
1178
1179// Methods for converting between header::IntoHeaderValue<StartTaskRequest> and hyper::header::HeaderValue
1180
1181#[cfg(any(feature = "client", feature = "server"))]
1182impl std::convert::TryFrom<header::IntoHeaderValue<StartTaskRequest>>
1183    for hyper::header::HeaderValue
1184{
1185    type Error = String;
1186
1187    fn try_from(
1188        hdr_value: header::IntoHeaderValue<StartTaskRequest>,
1189    ) -> std::result::Result<Self, Self::Error> {
1190        let hdr_value = hdr_value.to_string();
1191        match hyper::header::HeaderValue::from_str(&hdr_value) {
1192            std::result::Result::Ok(value) => std::result::Result::Ok(value),
1193            std::result::Result::Err(e) => std::result::Result::Err(format!(
1194                "Invalid header value for StartTaskRequest - value: {} is invalid {}",
1195                hdr_value, e
1196            )),
1197        }
1198    }
1199}
1200
1201#[cfg(any(feature = "client", feature = "server"))]
1202impl std::convert::TryFrom<hyper::header::HeaderValue>
1203    for header::IntoHeaderValue<StartTaskRequest>
1204{
1205    type Error = String;
1206
1207    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
1208        match hdr_value.to_str() {
1209            std::result::Result::Ok(value) => {
1210                match <StartTaskRequest as std::str::FromStr>::from_str(value) {
1211                    std::result::Result::Ok(value) => {
1212                        std::result::Result::Ok(header::IntoHeaderValue(value))
1213                    }
1214                    std::result::Result::Err(err) => std::result::Result::Err(format!(
1215                        "Unable to convert header value '{}' into StartTaskRequest - {}",
1216                        value, err
1217                    )),
1218                }
1219            }
1220            std::result::Result::Err(e) => std::result::Result::Err(format!(
1221                "Unable to convert header: {:?} to string: {}",
1222                hdr_value, e
1223            )),
1224        }
1225    }
1226}
1227
1228#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
1229#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
1230pub struct TaskListResponse {
1231    #[serde(rename = "tasks")]
1232    pub tasks: Vec<models::TaskListResponseTasksInner>,
1233}
1234
1235impl TaskListResponse {
1236    #[allow(clippy::new_without_default)]
1237    pub fn new(tasks: Vec<models::TaskListResponseTasksInner>) -> TaskListResponse {
1238        TaskListResponse { tasks }
1239    }
1240}
1241
1242/// Converts the TaskListResponse value to the Query Parameters representation (style=form, explode=false)
1243/// specified in https://swagger.io/docs/specification/serialization/
1244/// Should be implemented in a serde serializer
1245impl std::string::ToString for TaskListResponse {
1246    fn to_string(&self) -> String {
1247        let params: Vec<Option<String>> = vec![
1248            // Skipping tasks in query parameter serialization
1249
1250        ];
1251
1252        params.into_iter().flatten().collect::<Vec<_>>().join(",")
1253    }
1254}
1255
1256/// Converts Query Parameters representation (style=form, explode=false) to a TaskListResponse value
1257/// as specified in https://swagger.io/docs/specification/serialization/
1258/// Should be implemented in a serde deserializer
1259impl std::str::FromStr for TaskListResponse {
1260    type Err = String;
1261
1262    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
1263        /// An intermediate representation of the struct to use for parsing.
1264        #[derive(Default)]
1265        #[allow(dead_code)]
1266        struct IntermediateRep {
1267            pub tasks: Vec<Vec<models::TaskListResponseTasksInner>>,
1268        }
1269
1270        let mut intermediate_rep = IntermediateRep::default();
1271
1272        // Parse into intermediate representation
1273        let mut string_iter = s.split(',');
1274        let mut key_result = string_iter.next();
1275
1276        while key_result.is_some() {
1277            let val = match string_iter.next() {
1278                Some(x) => x,
1279                None => {
1280                    return std::result::Result::Err(
1281                        "Missing value while parsing TaskListResponse".to_string(),
1282                    )
1283                }
1284            };
1285
1286            if let Some(key) = key_result {
1287                #[allow(clippy::match_single_binding)]
1288                match key {
1289                    "tasks" => return std::result::Result::Err(
1290                        "Parsing a container in this style is not supported in TaskListResponse"
1291                            .to_string(),
1292                    ),
1293                    _ => {
1294                        return std::result::Result::Err(
1295                            "Unexpected key while parsing TaskListResponse".to_string(),
1296                        )
1297                    }
1298                }
1299            }
1300
1301            // Get the next key
1302            key_result = string_iter.next();
1303        }
1304
1305        // Use the intermediate representation to return the struct
1306        std::result::Result::Ok(TaskListResponse {
1307            tasks: intermediate_rep
1308                .tasks
1309                .into_iter()
1310                .next()
1311                .ok_or_else(|| "tasks missing in TaskListResponse".to_string())?,
1312        })
1313    }
1314}
1315
1316// Methods for converting between header::IntoHeaderValue<TaskListResponse> and hyper::header::HeaderValue
1317
1318#[cfg(any(feature = "client", feature = "server"))]
1319impl std::convert::TryFrom<header::IntoHeaderValue<TaskListResponse>>
1320    for hyper::header::HeaderValue
1321{
1322    type Error = String;
1323
1324    fn try_from(
1325        hdr_value: header::IntoHeaderValue<TaskListResponse>,
1326    ) -> std::result::Result<Self, Self::Error> {
1327        let hdr_value = hdr_value.to_string();
1328        match hyper::header::HeaderValue::from_str(&hdr_value) {
1329            std::result::Result::Ok(value) => std::result::Result::Ok(value),
1330            std::result::Result::Err(e) => std::result::Result::Err(format!(
1331                "Invalid header value for TaskListResponse - value: {} is invalid {}",
1332                hdr_value, e
1333            )),
1334        }
1335    }
1336}
1337
1338#[cfg(any(feature = "client", feature = "server"))]
1339impl std::convert::TryFrom<hyper::header::HeaderValue>
1340    for header::IntoHeaderValue<TaskListResponse>
1341{
1342    type Error = String;
1343
1344    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
1345        match hdr_value.to_str() {
1346            std::result::Result::Ok(value) => {
1347                match <TaskListResponse as std::str::FromStr>::from_str(value) {
1348                    std::result::Result::Ok(value) => {
1349                        std::result::Result::Ok(header::IntoHeaderValue(value))
1350                    }
1351                    std::result::Result::Err(err) => std::result::Result::Err(format!(
1352                        "Unable to convert header value '{}' into TaskListResponse - {}",
1353                        value, err
1354                    )),
1355                }
1356            }
1357            std::result::Result::Err(e) => std::result::Result::Err(format!(
1358                "Unable to convert header: {:?} to string: {}",
1359                hdr_value, e
1360            )),
1361        }
1362    }
1363}
1364
1365#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
1366#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
1367pub struct TaskListResponseTasksInner {
1368    #[serde(rename = "status")]
1369    pub status: models::TaskStatus,
1370
1371    /// The ID of the task
1372    #[serde(rename = "id")]
1373    pub id: u64,
1374
1375    /// The name of the task
1376    #[serde(rename = "name")]
1377    pub name: String,
1378}
1379
1380impl TaskListResponseTasksInner {
1381    #[allow(clippy::new_without_default)]
1382    pub fn new(status: models::TaskStatus, id: u64, name: String) -> TaskListResponseTasksInner {
1383        TaskListResponseTasksInner { status, id, name }
1384    }
1385}
1386
1387/// Converts the TaskListResponseTasksInner value to the Query Parameters representation (style=form, explode=false)
1388/// specified in https://swagger.io/docs/specification/serialization/
1389/// Should be implemented in a serde serializer
1390impl std::string::ToString for TaskListResponseTasksInner {
1391    fn to_string(&self) -> String {
1392        let params: Vec<Option<String>> = vec![
1393            // Skipping status in query parameter serialization
1394            Some("id".to_string()),
1395            Some(self.id.to_string()),
1396            Some("name".to_string()),
1397            Some(self.name.to_string()),
1398        ];
1399
1400        params.into_iter().flatten().collect::<Vec<_>>().join(",")
1401    }
1402}
1403
1404/// Converts Query Parameters representation (style=form, explode=false) to a TaskListResponseTasksInner value
1405/// as specified in https://swagger.io/docs/specification/serialization/
1406/// Should be implemented in a serde deserializer
1407impl std::str::FromStr for TaskListResponseTasksInner {
1408    type Err = String;
1409
1410    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
1411        /// An intermediate representation of the struct to use for parsing.
1412        #[derive(Default)]
1413        #[allow(dead_code)]
1414        struct IntermediateRep {
1415            pub status: Vec<models::TaskStatus>,
1416            pub id: Vec<u64>,
1417            pub name: Vec<String>,
1418        }
1419
1420        let mut intermediate_rep = IntermediateRep::default();
1421
1422        // Parse into intermediate representation
1423        let mut string_iter = s.split(',');
1424        let mut key_result = string_iter.next();
1425
1426        while key_result.is_some() {
1427            let val = match string_iter.next() {
1428                Some(x) => x,
1429                None => {
1430                    return std::result::Result::Err(
1431                        "Missing value while parsing TaskListResponseTasksInner".to_string(),
1432                    )
1433                }
1434            };
1435
1436            if let Some(key) = key_result {
1437                #[allow(clippy::match_single_binding)]
1438                match key {
1439                    #[allow(clippy::redundant_clone)]
1440                    "status" => intermediate_rep.status.push(
1441                        <models::TaskStatus as std::str::FromStr>::from_str(val)
1442                            .map_err(|x| x.to_string())?,
1443                    ),
1444                    #[allow(clippy::redundant_clone)]
1445                    "id" => intermediate_rep.id.push(
1446                        <u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
1447                    ),
1448                    #[allow(clippy::redundant_clone)]
1449                    "name" => intermediate_rep.name.push(
1450                        <String as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
1451                    ),
1452                    _ => {
1453                        return std::result::Result::Err(
1454                            "Unexpected key while parsing TaskListResponseTasksInner".to_string(),
1455                        )
1456                    }
1457                }
1458            }
1459
1460            // Get the next key
1461            key_result = string_iter.next();
1462        }
1463
1464        // Use the intermediate representation to return the struct
1465        std::result::Result::Ok(TaskListResponseTasksInner {
1466            status: intermediate_rep
1467                .status
1468                .into_iter()
1469                .next()
1470                .ok_or_else(|| "status missing in TaskListResponseTasksInner".to_string())?,
1471            id: intermediate_rep
1472                .id
1473                .into_iter()
1474                .next()
1475                .ok_or_else(|| "id missing in TaskListResponseTasksInner".to_string())?,
1476            name: intermediate_rep
1477                .name
1478                .into_iter()
1479                .next()
1480                .ok_or_else(|| "name missing in TaskListResponseTasksInner".to_string())?,
1481        })
1482    }
1483}
1484
1485// Methods for converting between header::IntoHeaderValue<TaskListResponseTasksInner> and hyper::header::HeaderValue
1486
1487#[cfg(any(feature = "client", feature = "server"))]
1488impl std::convert::TryFrom<header::IntoHeaderValue<TaskListResponseTasksInner>>
1489    for hyper::header::HeaderValue
1490{
1491    type Error = String;
1492
1493    fn try_from(
1494        hdr_value: header::IntoHeaderValue<TaskListResponseTasksInner>,
1495    ) -> std::result::Result<Self, Self::Error> {
1496        let hdr_value = hdr_value.to_string();
1497        match hyper::header::HeaderValue::from_str(&hdr_value) {
1498            std::result::Result::Ok(value) => std::result::Result::Ok(value),
1499            std::result::Result::Err(e) => std::result::Result::Err(format!(
1500                "Invalid header value for TaskListResponseTasksInner - value: {} is invalid {}",
1501                hdr_value, e
1502            )),
1503        }
1504    }
1505}
1506
1507#[cfg(any(feature = "client", feature = "server"))]
1508impl std::convert::TryFrom<hyper::header::HeaderValue>
1509    for header::IntoHeaderValue<TaskListResponseTasksInner>
1510{
1511    type Error = String;
1512
1513    fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
1514        match hdr_value.to_str() {
1515            std::result::Result::Ok(value) => {
1516                match <TaskListResponseTasksInner as std::str::FromStr>::from_str(value) {
1517                    std::result::Result::Ok(value) => {
1518                        std::result::Result::Ok(header::IntoHeaderValue(value))
1519                    }
1520                    std::result::Result::Err(err) => std::result::Result::Err(format!(
1521                        "Unable to convert header value '{}' into TaskListResponseTasksInner - {}",
1522                        value, err
1523                    )),
1524                }
1525            }
1526            std::result::Result::Err(e) => std::result::Result::Err(format!(
1527                "Unable to convert header: {:?} to string: {}",
1528                hdr_value, e
1529            )),
1530        }
1531    }
1532}
1533
1534/// The status of the task
1535/// Enumeration of values.
1536/// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]`
1537/// which helps with FFI.
1538#[allow(non_camel_case_types)]
1539#[repr(C)]
1540#[derive(
1541    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
1542)]
1543#[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))]
1544pub enum TaskStatus {
1545    #[serde(rename = "running")]
1546    Running,
1547    #[serde(rename = "paused")]
1548    Paused,
1549}
1550
1551impl std::fmt::Display for TaskStatus {
1552    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1553        match *self {
1554            TaskStatus::Running => write!(f, "running"),
1555            TaskStatus::Paused => write!(f, "paused"),
1556        }
1557    }
1558}
1559
1560impl std::str::FromStr for TaskStatus {
1561    type Err = String;
1562
1563    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
1564        match s {
1565            "running" => std::result::Result::Ok(TaskStatus::Running),
1566            "paused" => std::result::Result::Ok(TaskStatus::Paused),
1567            _ => std::result::Result::Err(format!("Value not valid: {}", s)),
1568        }
1569    }
1570}