Skip to main content

Preferences

Struct Preferences 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn speed_kn(&self, kn: f64) -> f64

kn in the preferred speed unit, or unchanged with no preference.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Preferences

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Preferences

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Preferences

Source§

fn default() -> Preferences

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Preferences

Source§

fn eq(&self, other: &Preferences) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Preferences

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.