pub struct UnitsError {
pub code: c_int,
}Expand description
UnitsError wraps a raw error code returned by the GNU units C library.
Every fallible operation in this crate returns Result<T>, which resolves
to Err(UnitsError) when the underlying C function signals failure. Inspect
code against the E_* constants re-exported from
gnu_units_sys to identify the specific error kind.
§Examples
use gnu_units::Unit;
match Unit::parse(")") {
Ok(_) => {}
Err(e) => println!("parse failed: {e}"),
}Fields§
§code: c_intRaw error code from the GNU units C library.
Compare against the E_* constants exported by gnu_units_sys
(e.g. gnu_units_sys::E_PARSE, gnu_units_sys::E_BADSUM) to identify
the failure mode.
Implementations§
Source§impl UnitsError
impl UnitsError
Sourcepub fn is_not_dimensionless(&self) -> bool
pub fn is_not_dimensionless(&self) -> bool
Returns true when the error indicates that a unit is not
dimensionless (it still carries base dimensions after reduction).
This error typically arises in two scenarios:
- A failed
Unit::convert_towhere the source and target have incompatible dimensions (conformability mismatch). - A
Unit::to_numbercall on a unit that still has dimensions.
Sourcepub fn is_invalid_unit(&self) -> bool
pub fn is_invalid_unit(&self) -> bool
Returns true when the error indicates that the input could not
be resolved to a valid unit, either because parsing failed
(E_PARSE) or because the unit name is not in the database
(E_UNKNOWNUNIT).
Trait Implementations§
Source§impl Clone for UnitsError
impl Clone for UnitsError
Source§fn clone(&self) -> UnitsError
fn clone(&self) -> UnitsError
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 UnitsError
impl Debug for UnitsError
Source§impl Display for UnitsError
impl Display for UnitsError
Source§impl Error for UnitsError
impl Error for UnitsError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for UnitsError
impl PartialEq for UnitsError
Source§fn eq(&self, other: &UnitsError) -> bool
fn eq(&self, other: &UnitsError) -> bool
self and other values to be equal, and is used by ==.