#[non_exhaustive]pub struct Method {
pub name: Ident,
pub docs: Docs,
pub full_path_name: Ident,
pub self_param: Option<SelfParam>,
pub params: Vec<Param>,
pub return_type: Option<TypeName>,
pub lifetime_env: LifetimeEnv,
pub attrs: Attrs,
}
Expand description
A method declared in the impl
associated with an FFI struct.
Includes both static and non-static methods, which can be distinguished
by inspecting Method::self_param
.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.name: Ident
The name of the method as initially declared.
docs: Docs
Lines of documentation for the method.
full_path_name: Ident
The name of the FFI function wrapping around the method.
self_param: Option<SelfParam>
The self
param of the method, if any.
params: Vec<Param>
All non-self
params taken by the method.
return_type: Option<TypeName>
The return type of the method, if any.
lifetime_env: LifetimeEnv
The lifetimes introduced in this method and surrounding impl block.
attrs: Attrs
The list of cfg
attributes (if any).
These are strings instead of syn::Attribute
or proc_macro2::TokenStream
because those types are not PartialEq
, Hash
, Serialize
, etc.
Implementations§
source§impl Method
impl Method
sourcepub fn from_syn(
m: &ImplItemFn,
self_path_type: PathType,
impl_generics: Option<&Generics>,
impl_attrs: &Attrs,
) -> Method
pub fn from_syn( m: &ImplItemFn, self_path_type: PathType, impl_generics: Option<&Generics>, impl_attrs: &Attrs, ) -> Method
Extracts a Method
from an AST node inside an impl
.
sourcepub fn borrowed_params(&self) -> BorrowedParams<'_>
pub fn borrowed_params(&self) -> BorrowedParams<'_>
Returns the parameters that the output is lifetime-bound to.
§Examples
Given the following method:
fn foo<'a, 'b: 'a, 'c>(&'a self, bar: Bar<'b>, baz: Baz<'c>) -> FooBar<'a> { ... }
Then this method would return the &'a self
and bar: Bar<'b>
params
because 'a
is in the return type, and 'b
must live at least as long
as 'a
. It wouldn’t include baz: Baz<'c>
though, because the return
type isn’t bound by 'c
in any way.
§Panics
This method may panic if TypeName::check_result_type_validity
(called by
Method::check_validity
) doesn’t pass first, since the result type may
contain elided lifetimes that we depend on for this method. The validity
checks ensure that the return type doesn’t elide any lifetimes, ensuring
that this method will produce correct results.
sourcepub fn is_writeable_out(&self) -> bool
pub fn is_writeable_out(&self) -> bool
Checks whether the method qualifies for special writeable handling. To qualify, a method must:
- not return any value
- have the last argument be an
&mut diplomat_runtime::DiplomatWriteable
Typically, methods of this form will be transformed in the bindings to a method that doesn’t take the writeable as an argument but instead creates one locally and just returns the final string.
sourcepub fn has_writeable_param(&self) -> bool
pub fn has_writeable_param(&self) -> bool
Checks if any parameters are writeable (regardless of other compatibilities for writeable output)
Trait Implementations§
impl Eq for Method
impl StructuralPartialEq for Method
Auto Trait Implementations§
impl Freeze for Method
impl RefUnwindSafe for Method
impl !Send for Method
impl !Sync for Method
impl Unpin for Method
impl UnwindSafe for Method
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)