Enum virtue::Error

source ·
pub enum Error {
    UnknownDataType(Span),
    InvalidRustSyntax {
        span: Span,
        expected: String,
    },
    ExpectedIdent(Span),
    PushParse {
        span: Option<Span>,
        error: PushParseError,
    },
    Custom {
        error: String,
        span: Option<Span>,
    },
}
Expand description

Errors that can occur while parsing or generator your derive macro.

Variants§

§

UnknownDataType(Span)

The data type at Span is unknown. This will be called when Parse::new is called on anything that is not a struct or enum.

§

InvalidRustSyntax

The rust syntax is invalid. This can be returned while parsing the Enum or Struct.

This error is assumed to not appear as rustc will do syntax checking before virtue gets access to the TokenStream. However this error could still be returned.

Fields

§span: Span

The span at which the invalid syntax is found

§expected: String

The expected rust syntax when this parsing occured

§

ExpectedIdent(Span)

Expected an ident at the given span.

§

PushParse

Failed to parse the code passed to StreamBuilder::push_parsed.

Fields

§span: Option<Span>

An optional span. Normally this is None, unless .with_span is called.

§error: PushParseError

The internal parse error

§

Custom

A custom error thrown by the developer

Fields

§error: String

The error message

§span: Option<Span>

Optionally the position that the error occurred at

Implementations§

source§

impl Error

source

pub fn custom(s: impl Into<String>) -> Self

Throw a custom error

source

pub fn custom_at(s: impl Into<String>, span: Span) -> Self

Throw a custom error at a given location

source

pub fn custom_at_token(s: impl Into<String>, token: TokenTree) -> Self

Throw a custom error at a given token

source

pub fn custom_at_opt_token( s: impl Into<String>, token: Option<TokenTree> ) -> Self

Throw a custom error at a given Option<TokenTree>

source

pub fn with_span(self, new_span: Span) -> Self

Return a new error that is located at the given span

source§

impl Error

source

pub fn into_token_stream(self) -> TokenStream

Turn this error into a TokenStream so it shows up as a compile_error for the user.

source

pub fn throw_with_span(self, span: Span) -> TokenStream

Turn this error into a TokenStream so it shows up as a compile_error for the user. The error will be shown at the given span.

Trait Implementations§

source§

impl Debug for Error

source§

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

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

impl Display for Error

source§

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

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

impl From<PushParseError> for Error

source§

fn from(e: PushParseError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl !Send for Error

§

impl !Sync for Error

§

impl Unpin for Error

§

impl UnwindSafe for Error

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

source§

default 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>,

§

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>,

§

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.