|
5 | 5 | //! satellite can send out multiple signals. |
6 | 6 |
|
7 | 7 | use crate::c_bindings; |
| 8 | +use std::borrow::Cow; |
8 | 9 | use std::ffi; |
9 | 10 | use std::str::Utf8Error; |
10 | 11 |
|
@@ -41,10 +42,23 @@ impl Constellation { |
41 | 42 | } |
42 | 43 | } |
43 | 44 |
|
| 45 | + pub(crate) fn to_constellation_t(&self) -> c_bindings::constellation_t { |
| 46 | + *self as c_bindings::constellation_t |
| 47 | + } |
| 48 | + |
44 | 49 | /// Gets the specified maximum number of active satellites for the constellation |
45 | 50 | pub fn sat_count(&self) -> u16 { |
46 | 51 | unsafe { c_bindings::constellation_to_sat_count(*self as c_bindings::constellation_t) } |
47 | 52 | } |
| 53 | + |
| 54 | + pub fn to_str(&self) -> Cow<'static, str> { |
| 55 | + let c_str = unsafe { |
| 56 | + ffi::CStr::from_ptr(c_bindings::constellation_to_string( |
| 57 | + self.to_constellation_t(), |
| 58 | + )) |
| 59 | + }; |
| 60 | + c_str.to_string_lossy() |
| 61 | + } |
48 | 62 | } |
49 | 63 |
|
50 | 64 | /// Code identifiers |
@@ -150,7 +164,7 @@ pub enum Code { |
150 | 164 | } |
151 | 165 |
|
152 | 166 | impl Code { |
153 | | - fn from_code_t(value: c_bindings::code_t) -> Option<Code> { |
| 167 | + pub(crate) fn from_code_t(value: c_bindings::code_t) -> Option<Code> { |
154 | 168 | match value { |
155 | 169 | c_bindings::code_e_CODE_GPS_L1CA => Some(Code::GpsL1ca), |
156 | 170 | c_bindings::code_e_CODE_GPS_L2CM => Some(Code::GpsL2cm), |
@@ -225,11 +239,9 @@ impl Code { |
225 | 239 | Self::from_code_t(unsafe { c_bindings::code_string_to_enum(s.as_ptr()) }) |
226 | 240 | } |
227 | 241 |
|
228 | | - /// Makes a string representation of a `Code` |
229 | | - pub fn to_string(&self) -> Result<String, Utf8Error> { |
| 242 | + pub fn to_str(&self) -> Cow<'static, str> { |
230 | 243 | let c_str = unsafe { ffi::CStr::from_ptr(c_bindings::code_to_string(self.to_code_t())) }; |
231 | | - |
232 | | - Ok(c_str.to_str()?.to_owned()) |
| 244 | + c_str.to_string_lossy() |
233 | 245 | } |
234 | 246 |
|
235 | 247 | /// Gets the corresponding `Constellation` |
|
0 commit comments