Context

Struct Context 

Source
pub struct Context<'c> {
    pub top: &'c DeriveInput,
    pub template_crate: &'c Path,
    pub template_name: Option<&'c Path>,
    pub pmetas: &'c Vec<PreprocessedValueList>,
    pub variant: Option<&'c WithinVariant<'c>>,
    pub field: Option<&'c WithinField<'c>>,
    pub within_loop: WithinLoop,
    pub pvariants: &'c [PreprocessedVariant<'c>],
    pub defs: DefinitionsContext<'c>,
}
Expand description

Context during expansion

References the driver, and digested information about it. Also represents where in the driver we are, including repetition context.

Fields§

§top: &'c DeriveInput§template_crate: &'c Path§template_name: Option<&'c Path>§pmetas: &'c Vec<PreprocessedValueList>§variant: Option<&'c WithinVariant<'c>>§field: Option<&'c WithinField<'c>>§within_loop: WithinLoop§pvariants: &'c [PreprocessedVariant<'c>]§defs: DefinitionsContext<'c>

Implementations§

Source§

impl<'c> Context<'c>

Source

pub fn is_enum(&self) -> bool

Source

pub fn expansion_description(&self) -> impl Display

Description of the whole expansion, suitable for dbg option, etc.

Source§

impl<'c> Context<'c>

Source

pub fn display_for_dbg(&self) -> impl Display + '_

Source§

impl<'c> Context<'c>

Source

pub fn as_general(&'c self) -> GeneralContext<'c>

Source§

impl<'c> Context<'c>

Source

pub fn decode_update_metas_used(&self, input: ParseStream<'_>) -> Result<()>

Source§

impl<'c> Context<'c>

Source

pub fn encode_metas_used(&self) -> Group

Returns [::Variant .field () ...]

Source§

impl<'c> Context<'c>

Source

pub(crate) fn check_metas_used( &self, errors: &mut ErrorAccumulator, recog: &Recognised, )

Source§

impl<'c> Context<'c>

Source

pub fn error_loc(&self) -> (Span, &'static str)

Returns an ErrorLoc for the current part of the driver

Source

pub fn for_with_within<'w, W, F, E>(&'c self, call: F) -> Result<(), E>
where W: WithinRepeatLevel<'w>, F: FnMut(&Context<'_>, &W) -> Result<(), E>, 'c: 'w,

Obtains the relevant Within(s), and calls call for each one

If there is a current W, simply calls call. Otherwise, iterates over all of them and calls call for each one.

Source

fn within_level<W>(&'c self, why: &dyn Spanned) -> Result<&'c W>
where W: WithinRepeatLevel<'c>,

Obtains the current Within of type W

Demands that there actually is a current container W. If we aren’t, calls it an error.

Source

pub fn field(&self, why: &dyn Spanned) -> Result<&WithinField<'_>>

Obtains the current field (or calls it an error)

Source

pub fn variant(&self, why: &dyn Spanned) -> Result<&WithinVariant<'_>>

Obtains the current variant (or calls it an error)

Source

pub fn syn_variant(&self, why: &dyn Spanned) -> Result<&Variant>

Obtains the current variant as a syn::Variant

Source§

impl<'c> Context<'c>

Source

pub fn call<T>( driver: &DeriveInput, template_crate: &Path, template_name: Option<&Path>, f: impl FnOnce(Context<'_>) -> Result<T>, ) -> Result<T, Error>

Calls f with a top-level Context for a syn::DeriveInput

Context has multiple levels of references to values created here, so we can’t easily provide Context::new().

Trait Implementations§

Source§

impl<'c> Clone for Context<'c>

Source§

fn clone(&self) -> Context<'c>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'c> Debug for Context<'c>

Source§

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

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

impl<'c> Copy for Context<'c>

Auto Trait Implementations§

§

impl<'c> Freeze for Context<'c>

§

impl<'c> !RefUnwindSafe for Context<'c>

§

impl<'c> !Send for Context<'c>

§

impl<'c> !Sync for Context<'c>

§

impl<'c> Unpin for Context<'c>

§

impl<'c> !UnwindSafe for Context<'c>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.