1#![allow(unused_qualifications)]
2
3use crate::models;
4#[cfg(any(feature = "client", feature = "server"))]
5use crate::header;
6
7
8#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
10#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
11pub struct Addr(i32);
12
13impl std::convert::From<i32> for Addr {
14 fn from(x: i32) -> Self {
15 Addr(x)
16 }
17}
18
19
20impl std::convert::From<Addr> for i32 {
21 fn from(x: Addr) -> Self {
22 x.0
23 }
24}
25
26impl std::ops::Deref for Addr {
27 type Target = i32;
28 fn deref(&self) -> &i32 {
29 &self.0
30 }
31}
32
33impl std::ops::DerefMut for Addr {
34 fn deref_mut(&mut self) -> &mut i32 {
35 &mut self.0
36 }
37}
38
39
40
41#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
43#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
44pub struct BusId(i32);
45
46impl std::convert::From<i32> for BusId {
47 fn from(x: i32) -> Self {
48 BusId(x)
49 }
50}
51
52
53impl std::convert::From<BusId> for i32 {
54 fn from(x: BusId) -> Self {
55 x.0
56 }
57}
58
59impl std::ops::Deref for BusId {
60 type Target = i32;
61 fn deref(&self) -> &i32 {
62 &self.0
63 }
64}
65
66impl std::ops::DerefMut for BusId {
67 fn deref_mut(&mut self) -> &mut i32 {
68 &mut self.0
69 }
70}
71
72
73
74#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
76#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
77pub struct Error(String);
78
79impl std::convert::From<String> for Error {
80 fn from(x: String) -> Self {
81 Error(x)
82 }
83}
84
85impl std::string::ToString for Error {
86 fn to_string(&self) -> String {
87 self.0.to_string()
88 }
89}
90
91impl std::str::FromStr for Error {
92 type Err = std::string::ParseError;
93 fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
94 std::result::Result::Ok(Error(x.to_string()))
95 }
96}
97
98impl std::convert::From<Error> for String {
99 fn from(x: Error) -> Self {
100 x.0
101 }
102}
103
104impl std::ops::Deref for Error {
105 type Target = String;
106 fn deref(&self) -> &String {
107 &self.0
108 }
109}
110
111impl std::ops::DerefMut for Error {
112 fn deref_mut(&mut self) -> &mut String {
113 &mut self.0
114 }
115}
116
117
118
119#[cfg(any(feature = "client", feature = "server"))]
123impl std::convert::TryFrom<header::IntoHeaderValue<I2cBusArg>> for hyper::header::HeaderValue {
124 type Error = String;
125
126 fn try_from(hdr_value: header::IntoHeaderValue<I2cBusArg>) -> std::result::Result<Self, Self::Error> {
127 let hdr_value = hdr_value.to_string();
128 match hyper::header::HeaderValue::from_str(&hdr_value) {
129 std::result::Result::Ok(value) => std::result::Result::Ok(value),
130 std::result::Result::Err(e) => std::result::Result::Err(
131 format!("Invalid header value for I2cBusArg - value: {} is invalid {}",
132 hdr_value, e))
133 }
134 }
135}
136
137#[cfg(any(feature = "client", feature = "server"))]
138impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<I2cBusArg> {
139 type Error = String;
140
141 fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
142 match hdr_value.to_str() {
143 std::result::Result::Ok(value) => {
144 match <I2cBusArg as std::str::FromStr>::from_str(value) {
145 std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
146 std::result::Result::Err(err) => std::result::Result::Err(
147 format!("Unable to convert header value '{}' into I2cBusArg - {}",
148 value, err))
149 }
150 },
151 std::result::Result::Err(e) => std::result::Result::Err(
152 format!("Unable to convert header: {:?} to string: {}",
153 hdr_value, e))
154 }
155 }
156}
157
158
159#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
160#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
161pub struct I2cBusArg {
162 #[serde(rename = "arg")]
163 #[serde(skip_serializing_if="Option::is_none")]
164 pub arg: Option<String>,
165
166 #[serde(rename = "description")]
167 #[serde(skip_serializing_if="Option::is_none")]
168 pub description: Option<String>,
169
170}
171
172impl I2cBusArg {
173 pub fn new() -> I2cBusArg {
174 I2cBusArg {
175 arg: None,
176 description: None,
177 }
178 }
179}
180
181impl std::string::ToString for I2cBusArg {
185 fn to_string(&self) -> String {
186 let mut params: Vec<String> = vec![];
187
188 if let Some(ref arg) = self.arg {
189 params.push("arg".to_string());
190 params.push(arg.to_string());
191 }
192
193
194 if let Some(ref description) = self.description {
195 params.push("description".to_string());
196 params.push(description.to_string());
197 }
198
199 params.join(",").to_string()
200 }
201}
202
203impl std::str::FromStr for I2cBusArg {
207 type Err = String;
208
209 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
210 #[derive(Default)]
211 struct IntermediateRep {
213 pub arg: Vec<String>,
214 pub description: Vec<String>,
215 }
216
217 let mut intermediate_rep = IntermediateRep::default();
218
219 let mut string_iter = s.split(',').into_iter();
221 let mut key_result = string_iter.next();
222
223 while key_result.is_some() {
224 let val = match string_iter.next() {
225 Some(x) => x,
226 None => return std::result::Result::Err("Missing value while parsing I2cBusArg".to_string())
227 };
228
229 if let Some(key) = key_result {
230 match key {
231 "arg" => intermediate_rep.arg.push(String::from_str(val).map_err(|x| format!("{}", x))?),
232 "description" => intermediate_rep.description.push(String::from_str(val).map_err(|x| format!("{}", x))?),
233 _ => return std::result::Result::Err("Unexpected key while parsing I2cBusArg".to_string())
234 }
235 }
236
237 key_result = string_iter.next();
239 }
240
241 std::result::Result::Ok(I2cBusArg {
243 arg: intermediate_rep.arg.into_iter().next(),
244 description: intermediate_rep.description.into_iter().next(),
245 })
246 }
247}
248
249
250
251#[cfg(any(feature = "client", feature = "server"))]
255impl std::convert::TryFrom<header::IntoHeaderValue<I2cBusError>> for hyper::header::HeaderValue {
256 type Error = String;
257
258 fn try_from(hdr_value: header::IntoHeaderValue<I2cBusError>) -> std::result::Result<Self, Self::Error> {
259 let hdr_value = hdr_value.to_string();
260 match hyper::header::HeaderValue::from_str(&hdr_value) {
261 std::result::Result::Ok(value) => std::result::Result::Ok(value),
262 std::result::Result::Err(e) => std::result::Result::Err(
263 format!("Invalid header value for I2cBusError - value: {} is invalid {}",
264 hdr_value, e))
265 }
266 }
267}
268
269#[cfg(any(feature = "client", feature = "server"))]
270impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<I2cBusError> {
271 type Error = String;
272
273 fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
274 match hdr_value.to_str() {
275 std::result::Result::Ok(value) => {
276 match <I2cBusError as std::str::FromStr>::from_str(value) {
277 std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
278 std::result::Result::Err(err) => std::result::Result::Err(
279 format!("Unable to convert header value '{}' into I2cBusError - {}",
280 value, err))
281 }
282 },
283 std::result::Result::Err(e) => std::result::Result::Err(
284 format!("Unable to convert header: {:?} to string: {}",
285 hdr_value, e))
286 }
287 }
288}
289
290
291#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
292#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
293pub struct I2cBusError {
294 #[serde(rename = "error")]
295 #[serde(skip_serializing_if="Option::is_none")]
296 pub error: Option<i32>,
297
298 #[serde(rename = "description")]
299 #[serde(skip_serializing_if="Option::is_none")]
300 pub description: Option<String>,
301
302}
303
304impl I2cBusError {
305 pub fn new() -> I2cBusError {
306 I2cBusError {
307 error: None,
308 description: None,
309 }
310 }
311}
312
313impl std::string::ToString for I2cBusError {
317 fn to_string(&self) -> String {
318 let mut params: Vec<String> = vec![];
319
320 if let Some(ref error) = self.error {
321 params.push("error".to_string());
322 params.push(error.to_string());
323 }
324
325
326 if let Some(ref description) = self.description {
327 params.push("description".to_string());
328 params.push(description.to_string());
329 }
330
331 params.join(",").to_string()
332 }
333}
334
335impl std::str::FromStr for I2cBusError {
339 type Err = String;
340
341 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
342 #[derive(Default)]
343 struct IntermediateRep {
345 pub error: Vec<i32>,
346 pub description: Vec<String>,
347 }
348
349 let mut intermediate_rep = IntermediateRep::default();
350
351 let mut string_iter = s.split(',').into_iter();
353 let mut key_result = string_iter.next();
354
355 while key_result.is_some() {
356 let val = match string_iter.next() {
357 Some(x) => x,
358 None => return std::result::Result::Err("Missing value while parsing I2cBusError".to_string())
359 };
360
361 if let Some(key) = key_result {
362 match key {
363 "error" => intermediate_rep.error.push(i32::from_str(val).map_err(|x| format!("{}", x))?),
364 "description" => intermediate_rep.description.push(String::from_str(val).map_err(|x| format!("{}", x))?),
365 _ => return std::result::Result::Err("Unexpected key while parsing I2cBusError".to_string())
366 }
367 }
368
369 key_result = string_iter.next();
371 }
372
373 std::result::Result::Ok(I2cBusError {
375 error: intermediate_rep.error.into_iter().next(),
376 description: intermediate_rep.description.into_iter().next(),
377 })
378 }
379}
380
381
382
383#[cfg(any(feature = "client", feature = "server"))]
387impl std::convert::TryFrom<header::IntoHeaderValue<I2cBusList>> for hyper::header::HeaderValue {
388 type Error = String;
389
390 fn try_from(hdr_value: header::IntoHeaderValue<I2cBusList>) -> std::result::Result<Self, Self::Error> {
391 let hdr_value = hdr_value.to_string();
392 match hyper::header::HeaderValue::from_str(&hdr_value) {
393 std::result::Result::Ok(value) => std::result::Result::Ok(value),
394 std::result::Result::Err(e) => std::result::Result::Err(
395 format!("Invalid header value for I2cBusList - value: {} is invalid {}",
396 hdr_value, e))
397 }
398 }
399}
400
401#[cfg(any(feature = "client", feature = "server"))]
402impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<I2cBusList> {
403 type Error = String;
404
405 fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
406 match hdr_value.to_str() {
407 std::result::Result::Ok(value) => {
408 match <I2cBusList as std::str::FromStr>::from_str(value) {
409 std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
410 std::result::Result::Err(err) => std::result::Result::Err(
411 format!("Unable to convert header value '{}' into I2cBusList - {}",
412 value, err))
413 }
414 },
415 std::result::Result::Err(e) => std::result::Result::Err(
416 format!("Unable to convert header: {:?} to string: {}",
417 hdr_value, e))
418 }
419 }
420}
421
422
423#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
424#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
425pub struct I2cBusList {
426 #[serde(rename = "path")]
427 #[serde(skip_serializing_if="Option::is_none")]
428 pub path: Option<String>,
429
430 #[serde(rename = "id")]
431 #[serde(skip_serializing_if="Option::is_none")]
432 pub id: Option<i32>,
433
434}
435
436impl I2cBusList {
437 pub fn new() -> I2cBusList {
438 I2cBusList {
439 path: None,
440 id: None,
441 }
442 }
443}
444
445impl std::string::ToString for I2cBusList {
449 fn to_string(&self) -> String {
450 let mut params: Vec<String> = vec![];
451
452 if let Some(ref path) = self.path {
453 params.push("path".to_string());
454 params.push(path.to_string());
455 }
456
457
458 if let Some(ref id) = self.id {
459 params.push("id".to_string());
460 params.push(id.to_string());
461 }
462
463 params.join(",").to_string()
464 }
465}
466
467impl std::str::FromStr for I2cBusList {
471 type Err = String;
472
473 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
474 #[derive(Default)]
475 struct IntermediateRep {
477 pub path: Vec<String>,
478 pub id: Vec<i32>,
479 }
480
481 let mut intermediate_rep = IntermediateRep::default();
482
483 let mut string_iter = s.split(',').into_iter();
485 let mut key_result = string_iter.next();
486
487 while key_result.is_some() {
488 let val = match string_iter.next() {
489 Some(x) => x,
490 None => return std::result::Result::Err("Missing value while parsing I2cBusList".to_string())
491 };
492
493 if let Some(key) = key_result {
494 match key {
495 "path" => intermediate_rep.path.push(String::from_str(val).map_err(|x| format!("{}", x))?),
496 "id" => intermediate_rep.id.push(i32::from_str(val).map_err(|x| format!("{}", x))?),
497 _ => return std::result::Result::Err("Unexpected key while parsing I2cBusList".to_string())
498 }
499 }
500
501 key_result = string_iter.next();
503 }
504
505 std::result::Result::Ok(I2cBusList {
507 path: intermediate_rep.path.into_iter().next(),
508 id: intermediate_rep.id.into_iter().next(),
509 })
510 }
511}
512
513
514
515#[cfg(any(feature = "client", feature = "server"))]
519impl std::convert::TryFrom<header::IntoHeaderValue<I2cBusOk>> for hyper::header::HeaderValue {
520 type Error = String;
521
522 fn try_from(hdr_value: header::IntoHeaderValue<I2cBusOk>) -> std::result::Result<Self, Self::Error> {
523 let hdr_value = hdr_value.to_string();
524 match hyper::header::HeaderValue::from_str(&hdr_value) {
525 std::result::Result::Ok(value) => std::result::Result::Ok(value),
526 std::result::Result::Err(e) => std::result::Result::Err(
527 format!("Invalid header value for I2cBusOk - value: {} is invalid {}",
528 hdr_value, e))
529 }
530 }
531}
532
533#[cfg(any(feature = "client", feature = "server"))]
534impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<I2cBusOk> {
535 type Error = String;
536
537 fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
538 match hdr_value.to_str() {
539 std::result::Result::Ok(value) => {
540 match <I2cBusOk as std::str::FromStr>::from_str(value) {
541 std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
542 std::result::Result::Err(err) => std::result::Result::Err(
543 format!("Unable to convert header value '{}' into I2cBusOk - {}",
544 value, err))
545 }
546 },
547 std::result::Result::Err(e) => std::result::Result::Err(
548 format!("Unable to convert header: {:?} to string: {}",
549 hdr_value, e))
550 }
551 }
552}
553
554
555#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
556#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
557pub struct I2cBusOk {
558 #[serde(rename = "ok")]
559 #[serde(skip_serializing_if="Option::is_none")]
560 pub ok: Option<i32>,
561
562}
563
564impl I2cBusOk {
565 pub fn new() -> I2cBusOk {
566 I2cBusOk {
567 ok: None,
568 }
569 }
570}
571
572impl std::string::ToString for I2cBusOk {
576 fn to_string(&self) -> String {
577 let mut params: Vec<String> = vec![];
578
579 if let Some(ref ok) = self.ok {
580 params.push("ok".to_string());
581 params.push(ok.to_string());
582 }
583
584 params.join(",").to_string()
585 }
586}
587
588impl std::str::FromStr for I2cBusOk {
592 type Err = String;
593
594 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
595 #[derive(Default)]
596 struct IntermediateRep {
598 pub ok: Vec<i32>,
599 }
600
601 let mut intermediate_rep = IntermediateRep::default();
602
603 let mut string_iter = s.split(',').into_iter();
605 let mut key_result = string_iter.next();
606
607 while key_result.is_some() {
608 let val = match string_iter.next() {
609 Some(x) => x,
610 None => return std::result::Result::Err("Missing value while parsing I2cBusOk".to_string())
611 };
612
613 if let Some(key) = key_result {
614 match key {
615 "ok" => intermediate_rep.ok.push(i32::from_str(val).map_err(|x| format!("{}", x))?),
616 _ => return std::result::Result::Err("Unexpected key while parsing I2cBusOk".to_string())
617 }
618 }
619
620 key_result = string_iter.next();
622 }
623
624 std::result::Result::Ok(I2cBusOk {
626 ok: intermediate_rep.ok.into_iter().next(),
627 })
628 }
629}
630
631
632
633#[cfg(any(feature = "client", feature = "server"))]
637impl std::convert::TryFrom<header::IntoHeaderValue<I2cBusRead>> for hyper::header::HeaderValue {
638 type Error = String;
639
640 fn try_from(hdr_value: header::IntoHeaderValue<I2cBusRead>) -> std::result::Result<Self, Self::Error> {
641 let hdr_value = hdr_value.to_string();
642 match hyper::header::HeaderValue::from_str(&hdr_value) {
643 std::result::Result::Ok(value) => std::result::Result::Ok(value),
644 std::result::Result::Err(e) => std::result::Result::Err(
645 format!("Invalid header value for I2cBusRead - value: {} is invalid {}",
646 hdr_value, e))
647 }
648 }
649}
650
651#[cfg(any(feature = "client", feature = "server"))]
652impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<I2cBusRead> {
653 type Error = String;
654
655 fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
656 match hdr_value.to_str() {
657 std::result::Result::Ok(value) => {
658 match <I2cBusRead as std::str::FromStr>::from_str(value) {
659 std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
660 std::result::Result::Err(err) => std::result::Result::Err(
661 format!("Unable to convert header value '{}' into I2cBusRead - {}",
662 value, err))
663 }
664 },
665 std::result::Result::Err(e) => std::result::Result::Err(
666 format!("Unable to convert header: {:?} to string: {}",
667 hdr_value, e))
668 }
669 }
670}
671
672
673#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
674#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
675pub struct I2cBusRead {
676 #[serde(rename = "ok")]
677 #[serde(skip_serializing_if="Option::is_none")]
678 pub ok: Option<i32>,
679
680 #[serde(rename = "values")]
681 #[serde(skip_serializing_if="Option::is_none")]
682 pub values: Option<Vec<models::I2cByte>>,
683
684}
685
686impl I2cBusRead {
687 pub fn new() -> I2cBusRead {
688 I2cBusRead {
689 ok: None,
690 values: None,
691 }
692 }
693}
694
695impl std::string::ToString for I2cBusRead {
699 fn to_string(&self) -> String {
700 let mut params: Vec<String> = vec![];
701
702 if let Some(ref ok) = self.ok {
703 params.push("ok".to_string());
704 params.push(ok.to_string());
705 }
706
707
708 if let Some(ref values) = self.values {
709 params.push("values".to_string());
710 params.push(values.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(",").to_string());
711 }
712
713 params.join(",").to_string()
714 }
715}
716
717impl std::str::FromStr for I2cBusRead {
721 type Err = String;
722
723 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
724 #[derive(Default)]
725 struct IntermediateRep {
727 pub ok: Vec<i32>,
728 pub values: Vec<Vec<models::I2cByte>>,
729 }
730
731 let mut intermediate_rep = IntermediateRep::default();
732
733 let mut string_iter = s.split(',').into_iter();
735 let mut key_result = string_iter.next();
736
737 while key_result.is_some() {
738 let val = match string_iter.next() {
739 Some(x) => x,
740 None => return std::result::Result::Err("Missing value while parsing I2cBusRead".to_string())
741 };
742
743 if let Some(key) = key_result {
744 match key {
745 "ok" => intermediate_rep.ok.push(i32::from_str(val).map_err(|x| format!("{}", x))?),
746 "values" => return std::result::Result::Err("Parsing a container in this style is not supported in I2cBusRead".to_string()),
747 _ => return std::result::Result::Err("Unexpected key while parsing I2cBusRead".to_string())
748 }
749 }
750
751 key_result = string_iter.next();
753 }
754
755 std::result::Result::Ok(I2cBusRead {
757 ok: intermediate_rep.ok.into_iter().next(),
758 values: intermediate_rep.values.into_iter().next(),
759 })
760 }
761}
762
763
764
765#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
767#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
768pub struct I2cByte(i32);
769
770impl std::convert::From<i32> for I2cByte {
771 fn from(x: i32) -> Self {
772 I2cByte(x)
773 }
774}
775
776
777impl std::convert::From<I2cByte> for i32 {
778 fn from(x: I2cByte) -> Self {
779 x.0
780 }
781}
782
783impl std::ops::Deref for I2cByte {
784 type Target = i32;
785 fn deref(&self) -> &i32 {
786 &self.0
787 }
788}
789
790impl std::ops::DerefMut for I2cByte {
791 fn deref_mut(&mut self) -> &mut i32 {
792 &mut self.0
793 }
794}
795
796
797
798#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
800#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
801pub struct NumBytes(i32);
802
803impl std::convert::From<i32> for NumBytes {
804 fn from(x: i32) -> Self {
805 NumBytes(x)
806 }
807}
808
809
810impl std::convert::From<NumBytes> for i32 {
811 fn from(x: NumBytes) -> Self {
812 x.0
813 }
814}
815
816impl std::ops::Deref for NumBytes {
817 type Target = i32;
818 fn deref(&self) -> &i32 {
819 &self.0
820 }
821}
822
823impl std::ops::DerefMut for NumBytes {
824 fn deref_mut(&mut self) -> &mut i32 {
825 &mut self.0
826 }
827}
828
829
830
831#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
833#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
834pub struct Reg(i32);
835
836impl std::convert::From<i32> for Reg {
837 fn from(x: i32) -> Self {
838 Reg(x)
839 }
840}
841
842
843impl std::convert::From<Reg> for i32 {
844 fn from(x: Reg) -> Self {
845 x.0
846 }
847}
848
849impl std::ops::Deref for Reg {
850 type Target = i32;
851 fn deref(&self) -> &i32 {
852 &self.0
853 }
854}
855
856impl std::ops::DerefMut for Reg {
857 fn deref_mut(&mut self) -> &mut i32 {
858 &mut self.0
859 }
860}
861
862
863
864#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
866#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
867pub struct Value(i32);
868
869impl std::convert::From<i32> for Value {
870 fn from(x: i32) -> Self {
871 Value(x)
872 }
873}
874
875
876impl std::convert::From<Value> for i32 {
877 fn from(x: Value) -> Self {
878 x.0
879 }
880}
881
882impl std::ops::Deref for Value {
883 type Target = i32;
884 fn deref(&self) -> &i32 {
885 &self.0
886 }
887}
888
889impl std::ops::DerefMut for Value {
890 fn deref_mut(&mut self) -> &mut i32 {
891 &mut self.0
892 }
893}
894
895
896
897#[cfg(any(feature = "client", feature = "server"))]
901impl std::convert::TryFrom<header::IntoHeaderValue<Values>> for hyper::header::HeaderValue {
902 type Error = String;
903
904 fn try_from(hdr_value: header::IntoHeaderValue<Values>) -> std::result::Result<Self, Self::Error> {
905 let hdr_value = hdr_value.to_string();
906 match hyper::header::HeaderValue::from_str(&hdr_value) {
907 std::result::Result::Ok(value) => std::result::Result::Ok(value),
908 std::result::Result::Err(e) => std::result::Result::Err(
909 format!("Invalid header value for Values - value: {} is invalid {}",
910 hdr_value, e))
911 }
912 }
913}
914
915#[cfg(any(feature = "client", feature = "server"))]
916impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<Values> {
917 type Error = String;
918
919 fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
920 match hdr_value.to_str() {
921 std::result::Result::Ok(value) => {
922 match <Values as std::str::FromStr>::from_str(value) {
923 std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
924 std::result::Result::Err(err) => std::result::Result::Err(
925 format!("Unable to convert header value '{}' into Values - {}",
926 value, err))
927 }
928 },
929 std::result::Result::Err(e) => std::result::Result::Err(
930 format!("Unable to convert header: {:?} to string: {}",
931 hdr_value, e))
932 }
933 }
934}
935
936
937#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
938#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
939pub struct Values {
940 #[serde(rename = "values")]
941 #[serde(skip_serializing_if="Option::is_none")]
942 pub values: Option<Vec<models::I2cByte>>,
943
944}
945
946impl Values {
947 pub fn new() -> Values {
948 Values {
949 values: None,
950 }
951 }
952}
953
954impl std::string::ToString for Values {
958 fn to_string(&self) -> String {
959 let mut params: Vec<String> = vec![];
960
961 if let Some(ref values) = self.values {
962 params.push("values".to_string());
963 params.push(values.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(",").to_string());
964 }
965
966 params.join(",").to_string()
967 }
968}
969
970impl std::str::FromStr for Values {
974 type Err = String;
975
976 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
977 #[derive(Default)]
978 struct IntermediateRep {
980 pub values: Vec<Vec<models::I2cByte>>,
981 }
982
983 let mut intermediate_rep = IntermediateRep::default();
984
985 let mut string_iter = s.split(',').into_iter();
987 let mut key_result = string_iter.next();
988
989 while key_result.is_some() {
990 let val = match string_iter.next() {
991 Some(x) => x,
992 None => return std::result::Result::Err("Missing value while parsing Values".to_string())
993 };
994
995 if let Some(key) = key_result {
996 match key {
997 "values" => return std::result::Result::Err("Parsing a container in this style is not supported in Values".to_string()),
998 _ => return std::result::Result::Err("Unexpected key while parsing Values".to_string())
999 }
1000 }
1001
1002 key_result = string_iter.next();
1004 }
1005
1006 std::result::Result::Ok(Values {
1008 values: intermediate_rep.values.into_iter().next(),
1009 })
1010 }
1011}
1012
1013
1014
1015#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
1017#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
1018pub struct Yaml(String);
1019
1020impl std::convert::From<String> for Yaml {
1021 fn from(x: String) -> Self {
1022 Yaml(x)
1023 }
1024}
1025
1026impl std::string::ToString for Yaml {
1027 fn to_string(&self) -> String {
1028 self.0.to_string()
1029 }
1030}
1031
1032impl std::str::FromStr for Yaml {
1033 type Err = std::string::ParseError;
1034 fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
1035 std::result::Result::Ok(Yaml(x.to_string()))
1036 }
1037}
1038
1039impl std::convert::From<Yaml> for String {
1040 fn from(x: Yaml) -> Self {
1041 x.0
1042 }
1043}
1044
1045impl std::ops::Deref for Yaml {
1046 type Target = String;
1047 fn deref(&self) -> &String {
1048 &self.0
1049 }
1050}
1051
1052impl std::ops::DerefMut for Yaml {
1053 fn deref_mut(&mut self) -> &mut String {
1054 &mut self.0
1055 }
1056}
1057
1058