Struct FnItem

Source
#[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>

Source

pub fn generics(&self) -> &GenericParams<'ast>

Source

pub fn body_id(&self) -> Option<BodyId>

The BodyId of this function. It can be None in trait definitions or for extern functions.

Source

pub fn constness(&self) -> Constness

Returns the Constness of this callable

Source

pub fn syncness(&self) -> Syncness

Returns the Syncness of this callable.

Use this to check if the function is async.

Source

pub fn safety(&self) -> Safety

Returns the Safety of this callable.

Use this to check if the function is unsafe.

Source

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.

Source

pub fn abi(&self) -> Abi

Returns the Abi of the callable.

Source

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().

Source

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.

Source

pub fn return_ty(&self) -> Option<&TyKind<'ast>>

The return type of this callable, if specified.

Trait Implementations§

Source§

impl<'ast> Debug for FnItem<'ast>

Source§

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

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

impl<'ast> From<&'ast FnItem<'ast>> for ItemKind<'ast>

Source§

fn from(value: &'ast FnItem<'ast>) -> Self

Converts to this type from the input type.
Source§

impl<'ast> HasNodeId for FnItem<'ast>

Source§

fn node_id(&self) -> NodeId

Returns the NodeId of the identifiable node
Source§

impl<'ast> HasSpan<'ast> for FnItem<'ast>

Source§

fn span(&self) -> &Span<'ast>

This returns the Span of the implementing AST node.
Source§

impl<'ast> ItemData<'ast> for FnItem<'ast>

Source§

fn id(&self) -> ItemId

Returns the 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>

The Visibility of this item.
Source§

fn ident(&self) -> Option<&Ident<'ast>>

This function can return None if the item was generated and has no real name
Source§

fn as_item(&'ast self) -> ItemKind<'ast>

Returns this item wrapped in it’s ExprKind variant. Read more
Source§

fn attrs(&self)

The attributes attached to this item. Read more

Auto Trait Implementations§

§

impl<'ast> Freeze for FnItem<'ast>

§

impl<'ast> RefUnwindSafe for FnItem<'ast>

§

impl<'ast> !Send for FnItem<'ast>

§

impl<'ast> !Sync for FnItem<'ast>

§

impl<'ast> Unpin for FnItem<'ast>

§

impl<'ast> UnwindSafe for FnItem<'ast>

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

impl<'ast, N> EmissionNode<'ast> for N
where N: Debug + HasSpan<'ast> + HasNodeId,