Struct rune::ast::ItemFn[][src]

pub struct ItemFn {
    pub id: Option<Id>,
    pub attributes: Vec<Attribute>,
    pub visibility: Visibility,
    pub const_token: Option<Const>,
    pub async_token: Option<Async>,
    pub fn_token: Fn,
    pub name: Ident,
    pub args: Parenthesized<FnArg, Comma>,
    pub body: Block,
}

A function item.

Examples

use rune::{testing, ast, parse_all};

testing::roundtrip::<ast::ItemFn>("async fn hello() {}");
assert!(parse_all::<ast::ItemFn>("fn async hello() {}").is_err());

let item = testing::roundtrip::<ast::ItemFn>("fn hello() {}");
assert_eq!(item.args.len(), 0);

let item = testing::roundtrip::<ast::ItemFn>("fn hello(foo, bar) {}");
assert_eq!(item.args.len(), 2);

testing::roundtrip::<ast::ItemFn>("pub fn hello(foo, bar) {}");
testing::roundtrip::<ast::ItemFn>("pub async fn hello(foo, bar) {}");
testing::roundtrip::<ast::ItemFn>("#[inline] fn hello(foo, bar) {}");

let item = testing::roundtrip::<ast::ItemFn>("#[inline] pub async fn hello(foo, bar) {}");
assert!(matches!(item.visibility, ast::Visibility::Public(..)));

assert_eq!(item.args.len(), 2);
assert_eq!(item.attributes.len(), 1);
assert!(item.async_token.is_some());
assert!(item.const_token.is_none());

let item = testing::roundtrip::<ast::ItemFn>("#[inline] pub const fn hello(foo, bar) {}");
assert!(matches!(item.visibility, ast::Visibility::Public(..)));

assert_eq!(item.args.len(), 2);
assert_eq!(item.attributes.len(), 1);
assert!(item.async_token.is_none());
assert!(item.const_token.is_some());

Fields

id: Option<Id>

Opaque identifier for fn item.

attributes: Vec<Attribute>

The attributes for the fn

visibility: Visibility

The visibility of the fn item

const_token: Option<Const>

The optional const keyword.

async_token: Option<Async>

The optional async keyword.

fn_token: Fn

The fn token.

name: Ident

The name of the function.

args: Parenthesized<FnArg, Comma>

The arguments of the function.

body: Block

The body of the function.

Implementations

impl ItemFn[src]

pub fn parse_with_meta(
    parser: &mut Parser<'_>,
    attributes: Vec<Attribute>,
    visibility: Visibility,
    const_token: Option<Const>,
    async_token: Option<Async>
) -> Result<Self, ParseError>
[src]

Parse #ident and attach the given meta

impl ItemFn[src]

pub fn descriptive_span(&self) -> Span[src]

Get the descriptive span of this item, e.g. pub fn foo() instead of the span for the whole function declaration, body included.

pub fn is_instance(&self) -> bool[src]

Test if function is an instance fn.

Trait Implementations

impl Clone for ItemFn[src]

impl Debug for ItemFn[src]

impl Eq for ItemFn[src]

impl Parse for ItemFn[src]

impl PartialEq<ItemFn> for ItemFn[src]

impl Peek for ItemFn[src]

impl Spanned for ItemFn[src]

impl StructuralEq for ItemFn[src]

impl StructuralPartialEq for ItemFn[src]

impl ToTokens for ItemFn[src]

Auto Trait Implementations

impl RefUnwindSafe for ItemFn

impl Send for ItemFn

impl Sync for ItemFn

impl Unpin for ItemFn

impl UnwindSafe for ItemFn

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.