Skip to main content

ParseMoneyError

Enum ParseMoneyError 

Source
#[non_exhaustive]
pub enum ParseMoneyError { MissingCurrency { text: String, at: Range<usize>, }, UnknownCurrency { text: String, token: String, at: Range<usize>, }, ConflictingCurrencies { text: String, first: Range<usize>, second: Range<usize>, }, InvalidAmount { text: String, at: Range<usize>, }, }
Expand description

An error from reading a monetary amount from text.

Every variant keeps the text the Parser read and points into it by byte range. The ranges count from the start of that text, leading whitespace included, so they index it as it was handed in.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

MissingCurrency

The text named no currency, and the Parser assumes none.

Fields

§text: String

The text the Parser read.

§at: Range<usize>

Covers the text without its surrounding whitespace.

§

UnknownCurrency

The text named a currency that matches no ISO code and no symbol of the currency that applies.

Fields

§text: String

The text the Parser read.

§token: String

The part that matched nothing.

§at: Range<usize>

Covers token.

§

ConflictingCurrencies

The text named two different currencies.

Fields

§text: String

The text the Parser read.

§first: Range<usize>

Covers the currency written first.

§second: Range<usize>

Covers the currency written second.

§

InvalidAmount

The digits are missing, malformed, or too large for a Decimal.

Fields

§text: String

The text the Parser read.

§at: Range<usize>

Covers the character at fault. Covers every digit when the amount is too large, and the text without its surrounding whitespace when the text holds no digits.

Implementations§

Source§

impl ParseMoneyError

Source

pub fn text(&self) -> &str

The text the Parser read.

§Example
use lucre::Money;

let error = "  1.50 ZZZ".parse::<Money>().unwrap_err();

assert_eq!(error.text(), "  1.50 ZZZ");
assert_eq!(&error.text()[error.span()], "ZZZ");
Source

pub fn span(&self) -> Range<usize>

The byte range the error points at.

ConflictingCurrencies names two currencies. This returns the first of them.

§Example
use lucre::Money;

let error = "1.50 ZZZ".parse::<Money>().unwrap_err();

assert_eq!(error.span(), 5..8);

Trait Implementations§

Source§

impl Clone for ParseMoneyError

Source§

fn clone(&self) -> ParseMoneyError

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 ParseMoneyError

Source§

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

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

impl Diagnostic for ParseMoneyError

Source§

fn code(&self) -> Option<Box<dyn Display + '_>>

Unique diagnostic code that can be used to look up more information about this Diagnostic. Ideally also globally unique, and documented in the toplevel crate’s documentation for easy searching. Rust path format (foo::bar::baz) is recommended, but more classic codes like E0123 or enums will work just fine.
Source§

fn help(&self) -> Option<Box<dyn Display + '_>>

Additional help text related to this Diagnostic. Do you have any advice for the poor soul who’s just run into this issue?
Source§

fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>

Labels to apply to this Diagnostic’s Diagnostic::source_code
Source§

fn source_code(&self) -> Option<&dyn SourceCode>

Source code to apply this Diagnostic’s Diagnostic::labels to.
Source§

fn url(&self) -> Option<Box<dyn Display + '_>>

URL to visit for a more detailed explanation/help about this Diagnostic.
Source§

fn severity(&self) -> Option<Severity>

Diagnostic severity. This may be used by ReportHandlers to change the display format of this diagnostic. Read more
Source§

fn related<'a>( &'a self, ) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>>

Additional related Diagnostics.
Source§

fn diagnostic_source(&self) -> Option<&dyn Diagnostic>

The cause of the error.
Source§

impl Display for ParseMoneyError

Source§

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

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

impl Eq for ParseMoneyError

Source§

impl Error for ParseMoneyError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for ParseMoneyError

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ParseMoneyError

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.