Struct Function

Source
pub struct Function { /* private fields */ }
Expand description

defines a C function

Implementations§

Source§

impl Function

Source

pub fn new(name: &str, ret: Type) -> Self

Creates a new function

Source

pub fn with_string(name: String, ret: Type) -> Self

creates a new function with the given name and return type

Source

pub fn name(&self) -> &str

returns the name of the method

Source

pub fn to_type(&self) -> Type

obtains the type for this function

Source

pub fn ret_type(&self) -> &Type

obtains a type reference of the return type

Source

pub fn doc(&mut self, doc: Doc) -> &mut Self

Adds a new documentation to the function

Source

pub fn push_doc_str(&mut self, doc: &str) -> &mut Self

Adds a new doc string to the function

Source

pub fn new_param(&mut self, name: &str, ty: Type) -> &mut FunctionParam

creates a new parameter for the function

Source

pub fn push_param(&mut self, item: FunctionParam) -> &mut Self

Push a param to the function’s parameters

Source

pub fn param_by_name(&self, name: &str) -> Option<&FunctionParam>

obtains a reference to the param with the given name

Source

pub fn param_by_name_mut(&mut self, name: &str) -> Option<&mut FunctionParam>

obtains a mutable reference to the param with the given name

Source

pub fn param_by_idx(&self, idx: usize) -> Option<&FunctionParam>

obtains a reference to the param with the given index (starting at 0)

Source

pub fn param_by_idx_mut(&mut self, idx: usize) -> Option<&mut FunctionParam>

obtains a mutable reference to the param with the given index mut

Source

pub fn push_attribute(&mut self, attr: &str) -> &mut Self

adds a new attribute to the function

Source

pub fn toggle_static(&mut self, val: bool) -> &mut Self

sets the function to be static

§Example

void foo() -> static void foo()

Source

pub fn set_static(&mut self) -> &mut Self

sets the function to be static

Source

pub fn toggle_inline(&mut self, val: bool) -> &mut Self

sets the function to be inline

§Example

void foo() -> inline void foo()

Source

pub fn set_inline(&mut self) -> &mut Self

makes the function to be an inline method

Source

pub fn toggle_extern(&mut self, val: bool) -> &mut Self

sets the function to be extern

§Example

void foo() -> extern void foo()

Source

pub fn set_extern(&mut self) -> &mut Self

makes the function to be an inline method

Source

pub fn set_body(&mut self, body: Block) -> &mut Self

sets the body for the function

Source

pub fn body(&mut self) -> &mut Block

obtains a reference to the body of the function

Source

pub fn do_fmt(&self, fmt: &mut Formatter<'_>, decl_only: bool) -> Result

Source

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

formats the function definitions

Source

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

formats only the function declaration

Source

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

formats only the function definition

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Function

Source§

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

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

impl Display for Function

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.