pub struct Body<'hir> {
pub params: &'hir [Param<'hir>],
pub value: &'hir Expr<'hir>,
pub generator_kind: Option<GeneratorKind>,
}
Expand description
The body of a function, closure, or constant value. In the case of a function, the body contains not only the function body itself (which is an expression), but also the argument patterns, since those are something that the caller doesn’t really care about.
Examples
fn foo((x, y): (u32, u32)) -> u32 {
x + y
}
Here, the Body
associated with foo()
would contain:
- an
params
array containing the(x, y)
pattern - a
value
containing thex + y
expression (maybe wrapped in a block) generator_kind
would beNone
All bodies have an owner, which can be accessed via the HIR
map using body_owner_def_id()
.
Fields
params: &'hir [Param<'hir>]
value: &'hir Expr<'hir>
generator_kind: Option<GeneratorKind>
Implementations
sourceimpl<'hir> Body<'hir>
impl<'hir> Body<'hir>
pub fn id(&self) -> BodyId
pub fn generator_kind(&self) -> Option<GeneratorKind>
Trait Implementations
sourceimpl<'tcx> ArenaAllocatable<'tcx, IsNotCopy> for Body<'tcx>
impl<'tcx> ArenaAllocatable<'tcx, IsNotCopy> for Body<'tcx>
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self
fn allocate_from_iter<'a>(
arena: &'a Arena<'tcx>,
iter: impl IntoIterator<Item = Self>
) -> &'a mut [Self]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
sourceimpl<'hir, __CTX> HashStable<__CTX> for Body<'hir>where
__CTX: HashStableContext,
impl<'hir, __CTX> HashStable<__CTX> for Body<'hir>where
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
Auto Trait Implementations
impl<'hir> RefUnwindSafe for Body<'hir>
impl<'hir> !Send for Body<'hir>
impl<'hir> !Sync for Body<'hir>
impl<'hir> Unpin for Body<'hir>
impl<'hir> UnwindSafe for Body<'hir>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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: 32 bytes