Struct rune::ast::ItemFn [−][src]
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]
parser: &mut Parser<'_>,
attributes: Vec<Attribute>,
visibility: Visibility,
const_token: Option<Const>,
async_token: Option<Async>
) -> Result<Self, ParseError>
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]
fn parse(p: &mut Parser<'_>) -> Result<Self, ParseError>
[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]
fn to_tokens(&self, context: &MacroContext, stream: &mut TokenStream)
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,