diplomat_core::ast

Struct Method

source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

source

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.

source

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.

source

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.

source

pub fn has_writeable_param(&self) -> bool

Checks if any parameters are writeable (regardless of other compatibilities for writeable output)

source

pub fn docs(&self) -> &Docs

Returns the documentation block

Trait Implementations§

source§

impl Clone for Method

source§

fn clone(&self) -> Method

Returns a copy 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
source§

impl Hash for Method

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Method

source§

fn eq(&self, other: &Method) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Method

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Method

source§

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> 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.