Trait

Struct Trait 

Source
pub struct Trait {
    pub supertraits: BTreeMap<Vec<Ident>, TokenStream>,
    pub tvs: BTreeMap<Ident, (Option<u32>, TokenStream)>,
    pub items: TokenStream,
}
Expand description

A representation of a trait definition that we will eventually emit. This is used to allow easily adding onto the trait each time we see an extern decl.

Fields§

§supertraits: BTreeMap<Vec<Ident>, TokenStream>

A set of supertrait constraints, each associated with a bindings module path

§tvs: BTreeMap<Ident, (Option<u32>, TokenStream)>

Keep track for each type variable of:

  • The identifier that we use for it in the generated source
  • Whether it comes from a component type variable, and if so, which one. (Most do; the I: Imports on the main component trait is the main one that doesn’t).
  • Whether there are any bounds on it
§items: TokenStream

Raw tokens of the contents of the trait

Implementations§

Source§

impl Trait

Source

pub fn new() -> Self

Source

pub fn tv_idxs(&self) -> Vec<u32>

Collect the component tyvar indices that correspond to the type variables on this trait.

Precondition: all of the type variables on this trait do correspond to component variables.

Source

pub fn adjust_vars(&mut self, n: u32)

Source

pub fn tv_toks_inner(&mut self) -> TokenStream

Build a token stream of all type variables and trait bounds on them, e.g. what you would put “inside” the <> in trait T<…>.

Source

pub fn tv_toks(&mut self) -> TokenStream

Build a token stream for the type variable part of the trait declaration

Source

pub fn into_tokens(&mut self, n: Ident) -> TokenStream

Build a token stream for this entire trait definition

Trait Implementations§

Source§

impl Debug for Trait

Source§

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

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

impl Default for Trait

Source§

fn default() -> Trait

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Trait

§

impl RefUnwindSafe for Trait

§

impl !Send for Trait

§

impl !Sync for Trait

§

impl Unpin for Trait

§

impl UnwindSafe for Trait

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