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: StringMethod name
signature: StringFull signature as a string
parsed_signature: FunctionSignatureParsed signature components
body_source: Option<String>Method body source code (if available)
is_unsafe: boolWhether this is an unsafe method
is_const: boolWhether this is a const method
is_async: boolWhether this is an async method
docs: Option<String>Doc comments
Implementations§
Source§impl Method
impl Method
Sourcepub fn return_type_def(&self) -> Result<Option<Item>>
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 foundOk(None)- No return type, or primitive/external typeErr(_)- An error occurred querying the daemon
Sourcepub fn param_types(&self) -> Result<Vec<Option<Item>>>
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 foundNone- The type is primitive or external