#[repr(C)]pub struct FnItem<'ast> { /* private fields */ }
Expand description
A function item like:
// A function with a parameter and a body
pub fn foo(bot: u32) {}
impl SomeItem {
// A function as an associated item, with a body
pub fn bar(&self) {}
}
pub trait SomeTrait {
// A function without a body
fn baz(_: i32);
}
// An async function.
async fn foo_async() -> u8 {
// ...
}
Async functions in Rustc actually return a future with the defined output type.
The return type -> u8
gets desugared to impl Future<Output = u8>
. Marker will
resugar the type to what the user had originally written. In this case it would
just return u8
. The semantic return type of an async function can be retrieved
from the expression of the Body
.
See: https://doc.rust-lang.org/reference/items/functions.html
Implementations§
Source§impl<'ast> FnItem<'ast>
impl<'ast> FnItem<'ast>
pub fn generics(&self) -> &GenericParams<'ast>
Sourcepub fn body_id(&self) -> Option<BodyId>
pub fn body_id(&self) -> Option<BodyId>
The BodyId
of this function. It can be None
in trait definitions
or for extern functions.
Sourcepub fn syncness(&self) -> Syncness
pub fn syncness(&self) -> Syncness
Returns the Syncness
of this callable.
Use this to check if the function is async.
Sourcepub fn safety(&self) -> Safety
pub fn safety(&self) -> Safety
Returns the Safety
of this callable.
Use this to check if the function is unsafe.
Sourcepub fn is_extern(&self) -> bool
pub fn is_extern(&self) -> bool
Returns true
, if this callable is marked as extern
. Bare functions
only use the extern
keyword to specify the ABI. These will currently
still return false
even if the keyword is present. In those cases,
please refer to the abi()
instead.
Defaults to false
if unspecified.
Sourcepub fn has_self(&self) -> bool
pub fn has_self(&self) -> bool
Returns true
, if this callable has a specified self
argument. The
type of self
can be retrieved from the first element of
params()
.
Sourcepub fn params(&self) -> &[FnParam<'ast>]
pub fn params(&self) -> &[FnParam<'ast>]
Returns the parameters, that this callable accepts. The self
argument
of methods, will be the first element of this slice. Use
has_self()
to determine if the first argument is self
.
Trait Implementations§
Source§impl<'ast> ItemData<'ast> for FnItem<'ast>
impl<'ast> ItemData<'ast> for FnItem<'ast>
Source§fn id(&self) -> ItemId
fn id(&self) -> ItemId
ItemId
of this item. This is a unique identifier used for comparison
and to request items from the MarkerContext
.Source§fn visibility(&self) -> &Visibility<'ast>
fn visibility(&self) -> &Visibility<'ast>
Visibility
of this item.Source§fn ident(&self) -> Option<&Ident<'ast>>
fn ident(&self) -> Option<&Ident<'ast>>
None
if the item was generated and has no real name