fuchsia_bluetooth/
types.rs
1use fidl_fuchsia_bluetooth_sys as sys;
6use std::fmt;
7
8mod address;
9pub use address::*;
10
11pub mod bonding_data;
14pub use bonding_data::*;
15
16#[cfg(target_os = "fuchsia")]
18mod channel;
19#[cfg(target_os = "fuchsia")]
20pub use channel::*;
21
22pub mod host_info;
23pub use host_info::*;
24
25mod id;
26pub use id::*;
27
28pub mod io_capabilities;
29
30pub mod le;
32
33pub mod pairing_options;
35
36mod peer;
37pub use peer::*;
38
39mod uuid;
40pub use uuid::*;
41
42macro_rules! bt_fidl_wrap {
43 ($outer:ident) => {
44 pub struct $outer(fidl_fuchsia_bluetooth::$outer);
45
46 impl From<fidl_fuchsia_bluetooth::$outer> for $outer {
47 fn from(b: fidl_fuchsia_bluetooth::$outer) -> $outer {
48 $outer(b)
49 }
50 }
51
52 impl Into<fidl_fuchsia_bluetooth::$outer> for $outer {
53 fn into(self) -> fidl_fuchsia_bluetooth::$outer {
54 self.0
55 }
56 }
57 };
58}
59
60bt_fidl_wrap!(Status);
61bt_fidl_wrap!(Bool);
62bt_fidl_wrap!(Int8);
63bt_fidl_wrap!(UInt16);
64
65impl fmt::Display for Bool {
66 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
67 write!(fmt, "{}", self.0.value)
68 }
69}
70
71impl fmt::Display for Status {
72 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
73 write!(fmt, "{:?}", self.0.error)
74 }
75}
76
77#[derive(Clone, Debug, PartialEq)]
82pub enum OneOrBoth<L, R> {
83 Left(L),
84 Both(L, R),
85 Right(R),
86}
87
88impl<L, R> OneOrBoth<L, R> {
89 pub fn left(&self) -> Option<&L> {
90 match &self {
91 OneOrBoth::Left(l) => Some(l),
92 OneOrBoth::Both(l, _) => Some(l),
93 OneOrBoth::Right(_) => None,
94 }
95 }
96 pub fn right(&self) -> Option<&R> {
97 match &self {
98 OneOrBoth::Left(_) => None,
99 OneOrBoth::Both(_, r) => Some(r),
100 OneOrBoth::Right(r) => Some(r),
101 }
102 }
103}
104
105#[derive(Clone, Copy, Debug, PartialEq)]
106pub enum Technology {
107 LE,
108 Classic,
109 DualMode,
110}
111
112impl From<sys::TechnologyType> for Technology {
113 fn from(tech: sys::TechnologyType) -> Self {
114 match tech {
115 sys::TechnologyType::LowEnergy => Technology::LE,
116 sys::TechnologyType::Classic => Technology::Classic,
117 sys::TechnologyType::DualMode => Technology::DualMode,
118 }
119 }
120}
121
122impl From<Technology> for sys::TechnologyType {
123 fn from(tech: Technology) -> Self {
124 match tech {
125 Technology::LE => sys::TechnologyType::LowEnergy,
126 Technology::Classic => sys::TechnologyType::Classic,
127 Technology::DualMode => sys::TechnologyType::DualMode,
128 }
129 }
130}