[][src]Struct lenient_semver_parser::Error

pub struct Error<'input> { /* fields omitted */ }

Possible errors that happen during parsing and the location of the token where the error occurred.

Example

use semver::Version;

let error = lenient_semver_parser::parse::<Version>("1+").unwrap_err();
assert_eq!(error.to_string(), "Could not parse the build identifier: No input");

let error = lenient_semver_parser::parse::<Version>("1!").unwrap_err();
assert_eq!(error.to_string(), "Unexpected `!`");

Implementations

impl<'input> Error<'input>[src]

pub fn owned(&self) -> OwnedError[src]

Creates a new OwnedError out of this Error.

This is specialized version of Clone which returns a different type.

pub fn input(&self) -> &'input str[src]

Returns the original input line.

Examples

let error = lenient_semver_parser::parse::<semver::Version>("1+").unwrap_err();
assert_eq!(error.input(), "1+");

pub fn error_span(&self) -> Range<usize>[src]

Returns range into the input string that points to the erroneous input.

Examples

let error = lenient_semver_parser::parse::<semver::Version>("1!").unwrap_err();
assert_eq!(error.error_span(), 1..2);

pub fn error_kind(&self) -> ErrorKind[src]

Returns the kind of error.

Examples

assert_eq!(
    lenient_semver_parser::parse::<semver::Version>("").unwrap_err().error_kind(),
    lenient_semver_parser::ErrorKind::MissingMajorNumber
);
assert_eq!(
    lenient_semver_parser::parse::<semver::Version>("1.").unwrap_err().error_kind(),
    lenient_semver_parser::ErrorKind::MissingMinorNumber
);
assert_eq!(
    lenient_semver_parser::parse::<semver::Version>("1.2.").unwrap_err().error_kind(),
    lenient_semver_parser::ErrorKind::MissingPatchNumber
);
assert_eq!(
    lenient_semver_parser::parse::<semver::Version>("1-").unwrap_err().error_kind(),
    lenient_semver_parser::ErrorKind::MissingPreRelease
);
assert_eq!(
    lenient_semver_parser::parse::<semver::Version>("1+").unwrap_err().error_kind(),
    lenient_semver_parser::ErrorKind::MissingBuild
);
assert_eq!(
    lenient_semver_parser::parse::<semver::Version>("1!").unwrap_err().error_kind(),
    lenient_semver_parser::ErrorKind::UnexpectedInput
);

pub fn erroneous_input(&self) -> &'input str[src]

Returns a slice from the original input line that triggered the error.

Examples

let error = lenient_semver_parser::parse::<semver::Version>("1!").unwrap_err();
assert_eq!(error.erroneous_input(), "!");

pub fn error_line(&self) -> String[src]

Returns a text representation of the error.

Examples

let error = lenient_semver_parser::parse::<semver::Version>("1.").unwrap_err();
assert_eq!(error.error_line(), String::from("Could not parse the minor identifier: No input"));

This is equivalent to the Display implementation, which can be further customized with format specifiers.

let error = lenient_semver_parser::parse::<semver::Version>("1?").unwrap_err();
assert_eq!(format!("{:!^42}", error), String::from("!!!!!!!!!!!!!!Unexpected `?`!!!!!!!!!!!!!!"));

pub fn indicate_erroneous_input(&self) -> String[src]

Returns a caret line indication the erroneous input if it was written under the original input line.

Examples

let error = lenient_semver_parser::parse::<semver::Version>("foo").unwrap_err();
assert_eq!(error.indicate_erroneous_input(), "^");

let error = lenient_semver_parser::parse::<semver::Version>("1.2.3 bar").unwrap_err();
assert_eq!(error.indicate_erroneous_input(), "~~~~~~^");

Trait Implementations

impl<'input> Debug for Error<'input>[src]

impl<'_> Display for Error<'_>[src]

impl<'input> Eq for Error<'input>[src]

impl<'_> Error for Error<'_>[src]

impl<'_> Ord for Error<'_>[src]

impl<'input> PartialEq<Error<'input>> for Error<'input>[src]

impl<'_> PartialOrd<Error<'_>> for Error<'_>[src]

impl<'input> StructuralEq for Error<'input>[src]

impl<'input> StructuralPartialEq for Error<'input>[src]

Auto Trait Implementations

impl<'input> RefUnwindSafe for Error<'input>

impl<'input> Send for Error<'input>

impl<'input> Sync for Error<'input>

impl<'input> Unpin for Error<'input>

impl<'input> UnwindSafe for Error<'input>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.