Method

Struct Method 

Source
pub struct Method {
    pub name: String,
    pub signature: String,
    pub parsed_signature: FunctionSignature,
    pub body_source: Option<String>,
    pub is_unsafe: bool,
    pub is_const: bool,
    pub is_async: bool,
    pub docs: Option<String>,
    /* private fields */
}
Expand description

A method (from an impl block).

Provides method metadata including signature, source code, and the ability to navigate to parameter and return types.

§Example

ⓘ
let user = krate.get_struct("User")?;
for method in user.methods()? {
    println!("Method: {}", method.name);
    println!("  Signature: {}", method.signature);

    // Get return type
    if let Some(return_type) = method.return_type_def()? {
        println!("  Returns: {}", return_type.name());
    }

    // Get method body source
    if let Some(body) = &method.body_source {
        println!("  Body: {}", body);
    }
}

Fields§

§name: String

Method name

§signature: String

Full signature as a string

§parsed_signature: FunctionSignature

Parsed signature components

§body_source: Option<String>

Method body source code (if available)

§is_unsafe: bool

Whether this is an unsafe method

§is_const: bool

Whether this is a const method

§is_async: bool

Whether this is an async method

§docs: Option<String>

Doc comments

Implementations§

Source§

impl Method

Source

pub fn return_type_def(&self) -> Result<Option<Item>>

Navigate to the return type definition.

Returns an Item representing the method’s return type definition, if it can be resolved. Returns None if the method returns (), or if the type is primitive or external.

§Example
ⓘ
let user = krate.get_struct("User")?;
for method in user.methods()? {
    if let Some(return_type) = method.return_type_def()? {
        println!("{} returns {}", method.name, return_type.name());
    }
}
§Returns
  • Ok(Some(Item)) - The return type definition was found
  • Ok(None) - No return type, or primitive/external type
  • Err(_) - An error occurred querying the daemon
Source

pub fn param_types(&self) -> Result<Vec<Option<Item>>>

Navigate to parameter type definitions.

Returns a vector of optional Items, one for each parameter. Each entry is Some(Item) if the type can be resolved, or None for primitive/external types.

§Example
ⓘ
let user = krate.get_struct("User")?;
for method in user.methods()? {
    println!("Method: {}", method.name);
    for (i, param_type) in method.param_types()?.into_iter().enumerate() {
        if let Some(ptype) = param_type {
            println!("  Param {}: {}", i, ptype.name());
        }
    }
}
§Returns

A vector where each element corresponds to a parameter:

  • Some(Item) - The parameter type was found
  • None - The type is primitive or external

Trait Implementations§

Source§

impl Clone for Method

Source§

fn clone(&self) -> Method

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 Method

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