pub(crate) struct MethodDef<'a> {
pub name: Symbol,
pub generics: Generics,
pub args: ThinVec<Param>,
pub ret_ty: Box<Ty>,
pub attributes: AttrVec,
pub body: MethodBody<'a>,
}Fields§
§name: Symbolname of the method
generics: GenericsList of generics, e.g., R: rand::Rng
args: ThinVec<Param>§ret_ty: Box<Ty>Returns type
attributes: AttrVec§body: MethodBody<'a>Implementations§
Source§impl<'a> MethodDef<'a>
impl<'a> MethodDef<'a>
fn create_method( self, cx: &ExtCtxt<'_>, span: Span, body: BlockOrExpr, ) -> Option<Box<AssocItem>>
Sourcefn expand_struct_method_body<'b>(
&self,
cx: &ExtCtxt<'_>,
span: Span,
struct_def: &'b VariantData,
is_packed: bool,
) -> BlockOrExpr
fn expand_struct_method_body<'b>( &self, cx: &ExtCtxt<'_>, span: Span, struct_def: &'b VariantData, is_packed: bool, ) -> BlockOrExpr
The normal case uses field access.
#[derive(PartialEq)]
struct A { x: u8, y: u8 }
// equivalent to:
impl PartialEq for A {
fn eq(&self, other: &A) -> bool {
self.x == other.x && self.y == other.y
}
}But if the struct is repr(packed), we can’t use something like
&self.x because that might cause an unaligned ref. So for any trait
method that takes a reference, we use a local block to force a copy.
This requires that the field impl Copy.
impl PartialEq for A {
fn eq(&self, other: &A) -> bool {
// Desugars to `{ self.x }.eq(&{ other.y }) && ...`
{ self.x } == { other.y } && { self.y } == { other.y }
}
}
impl Hash for A {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&{ self.x }, state);
::core::hash::Hash::hash(&{ self.y }, state);
}
}Sourcefn expand_enum_method_body<'b>(
&self,
cx: &ExtCtxt<'_>,
span: Span,
enum_def: &'b EnumDef,
) -> BlockOrExpr
fn expand_enum_method_body<'b>( &self, cx: &ExtCtxt<'_>, span: Span, enum_def: &'b EnumDef, ) -> BlockOrExpr
#[derive(PartialEq)]
enum A {
A1,
A2(i32)
}is equivalent to:
#![feature(core_intrinsics)]
enum A {
A1,
A2(i32)
}
impl ::core::cmp::PartialEq for A {
#[inline]
fn eq(&self, other: &A) -> bool {
::core::intrinsics::discriminant_value(self) == ::core::intrinsics::discriminant_value(other)
&& match (self, other) {
(A::A2(__self_0), A::A2(__arg1_0)) => *__self_0 == *__arg1_0,
_ => true,
}
}
}Creates a discriminant check combined with a match for a tuple of all
selflike_args, with an arm for each variant with fields, possibly an
arm for each fieldless variant (if unify_fieldless_variants is not
Unify), and possibly a default arm.
Auto Trait Implementations§
impl<'a> !DynSend for MethodDef<'a>
impl<'a> !DynSync for MethodDef<'a>
impl<'a> !RefUnwindSafe for MethodDef<'a>
impl<'a> !Send for MethodDef<'a>
impl<'a> !Sync for MethodDef<'a>
impl<'a> !UnwindSafe for MethodDef<'a>
impl<'a> Forget for MethodDef<'a>
impl<'a> Freeze for MethodDef<'a>
impl<'a> Move for MethodDef<'a>
impl<'a> Unpin for MethodDef<'a>
impl<'a> UnsafeUnpin for MethodDef<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
Source§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 96 bytes