pub struct Preferences { /* private fields */ }Expand description
What a server’s unitpreferences states, as far as this crate reads
it – every category category_base_unit names a Signal K base unit
for, present once the server has stated a target unit this crate
converts (see this module’s own top doc for the two kinds of target
that leaves out), absent otherwise. Default is every category
absent, which is exactly the state a caller should fall back to its
own default unit for – the same value Self::parse returns for an
unreadable answer.
Implementations§
Source§impl Preferences
impl Preferences
Sourcepub fn parse(value: &Value) -> Self
pub fn parse(value: &Value) -> Self
Reads GET /signalk/v1/unitpreferences/active’s own JSON body.
Never fails: an answer this crate cannot make sense of – the wrong shape, every category naming a target unit it does not know, or a category it has never heard of – reads the same as no preference stated at all, since a caller reacts to both by falling back to its own default unit regardless of which it was.
Sourcepub fn convert(
&self,
category: &str,
si_value: f64,
) -> Option<(f64, Option<&str>)>
pub fn convert( &self, category: &str, si_value: f64, ) -> Option<(f64, Option<&str>)>
si_value, in category‘s own Signal K base unit (its own SI
unit for everything but Self::distance_nm’s and its three
siblings’ own nautical-mile/knot/metre convention – see
category_base_unit for which is which), converted into
whatever a mariner’s preference asks for, with the label to show
beside it. None when category names nothing
category_base_unit recognises, or nothing was stated (or
understood) for it – the same two cases Self::parse’s own doc
gives.
This is the one path every category not among nav-core’s own four
canonical units goes through – a mariner’s chosen pressure unit,
say, has no pressure_pa accessor of its own here for the same
reason nav-math itself never grew a pressure type: nothing in
this workspace holds a pressure reading yet. A future one that
does calls this directly rather than this crate growing an
accessor speculatively.
Sourcepub fn symbol(&self, category: &str) -> Option<&str>
pub fn symbol(&self, category: &str) -> Option<&str>
The label category converts to, when a preference states one
this crate reads and the server put a word to it – see
Resolved::symbol’s own doc for why the two are not the same
question.
Sourcepub fn distance_nm(&self, nm: f64) -> f64
pub fn distance_nm(&self, nm: f64) -> f64
nm in the preferred distance unit, or unchanged with no
preference stated – nautical miles already being nav-math’s own
unit, that is a caller’s correct fallback regardless. Also what a
closest point of approach converts through: a CPA is a distance.
Sourcepub fn distance_symbol(&self) -> Option<&str>
pub fn distance_symbol(&self) -> Option<&str>
The distance unit’s own symbol – see Self::symbol’s own doc
for exactly when this is None.
Sourcepub fn speed_kn(&self, kn: f64) -> f64
pub fn speed_kn(&self, kn: f64) -> f64
kn in the preferred speed unit, or unchanged with no preference.
Sourcepub fn speed_symbol(&self) -> Option<&str>
pub fn speed_symbol(&self) -> Option<&str>
The speed unit’s own symbol – see Self::symbol’s own doc for
exactly when this is None.
Sourcepub fn length_m(&self, metres: f64) -> f64
pub fn length_m(&self, metres: f64) -> f64
metres in the preferred length unit, or unchanged with no
preference – metres already being the wire’s own unit for a
length or a depth, and this crate’s own throughout.
Sourcepub fn length_symbol(&self) -> Option<&str>
pub fn length_symbol(&self) -> Option<&str>
The length unit’s own symbol – see Self::symbol’s own doc for
exactly when this is None.
Sourcepub fn depth_m(&self, metres: f64) -> f64
pub fn depth_m(&self, metres: f64) -> f64
metres in the preferred depth unit, or unchanged with no
preference – see Self::length_m’s own doc, and this module’s
own for why depth is not simply length_m under another name.
Sourcepub fn depth_symbol(&self) -> Option<&str>
pub fn depth_symbol(&self) -> Option<&str>
The depth unit’s own symbol – see Self::symbol’s own doc for
exactly when this is None.
Trait Implementations§
Source§impl Clone for Preferences
impl Clone for Preferences
Source§fn clone(&self) -> Preferences
fn clone(&self) -> Preferences
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Preferences
impl Debug for Preferences
Source§impl Default for Preferences
impl Default for Preferences
Source§fn default() -> Preferences
fn default() -> Preferences
Source§impl PartialEq for Preferences
impl PartialEq for Preferences
Source§fn eq(&self, other: &Preferences) -> bool
fn eq(&self, other: &Preferences) -> bool
self and other values to be equal, and is used by ==.