Skip to main content

TraitMethod

Struct TraitMethod 

Source
pub struct TraitMethod {
    pub name: String,
    pub params: Vec<Ty>,
    pub ret: Ty,
    pub has_self: bool,
    pub mut_self: bool,
    pub generics: u32,
    pub bounds: Vec<Vec<DefId>>,
    pub default_def: Option<DefId>,
}
Expand description

One method of a trait. In params/ret, Ty::Param(0) denotes Self and Ty::Param(1..=generics) the method’s own generic parameters (a generic method like fn map<U>(self, …)). params never itself contains a self entry: when the method declares a self receiver it is implicit rather than stored here, but a trait method need not declare one at all (e.g. fn zero() -> Int), in which case params is just its declared parameters.

Fields§

§name: String§params: Vec<Ty>§ret: Ty§has_self: bool

Whether the method declares a self receiver. A method without one is an associated function, called as Type::name(…) with no receiver — never as value.name(…). params looks the same either way (self is never stored in it), so this flag is the only record of the difference, and dispatch that ignores it lowers a receiver argument into a callee that has no slot for it.

§mut_self: bool

Whether the self receiver is declared mut, i.e. whether the method is a mutator whose callers must supply a mutable receiver place (E0060, ADR 0005 §1). Meaningless when has_self is false, and the conformance check that compares this against the impl’s own mut runs only after the two agree about has_self at all.

It has to live here rather than being read off the impl: trait dispatch resolves to (trait_id, method_index), and for a generic receiver (fn f<T: Tr>(mut x: T) { x.m() }) there is no single impl whose receiver declaration could be consulted. params cannot carry it either — method_sig_parts strips a self parameter whether or not it is mut, so the flag is the only record, exactly as has_self is the only record of the receiver’s presence.

§generics: u32

Number of the method’s own generic parameters (not counting Self).

§bounds: Vec<Vec<DefId>>

Trait bounds per method generic parameter (indexed 0..generics).

§default_def: Option<DefId>

The compiled default-body function, if the trait provides a default.

Trait Implementations§

Source§

impl Clone for TraitMethod

Source§

fn clone(&self) -> Self

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 TraitMethod

Source§

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

Formats the value using the given formatter. Read more

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.