#[repr(C)]pub struct Method(/* private fields */);
Expand description
A type that represents a method in a class definition.
Implementations§
source§impl Method
impl Method
sourcepub fn return_type(
&self
) -> impl Deref<Target = str> + AsRef<str> + Debug + Display
pub fn return_type( &self ) -> impl Deref<Target = str> + AsRef<str> + Debug + Display
Returns the Encoding
of self’s return type.
sourcepub fn argument_type(
&self,
index: usize
) -> Option<impl Deref<Target = str> + AsRef<str> + Debug + Display>
pub fn argument_type( &self, index: usize ) -> Option<impl Deref<Target = str> + AsRef<str> + Debug + Display>
Returns the Encoding
of a single parameter type of self, or
None
if self has no parameter at the given index.
sourcepub fn arguments_count(&self) -> usize
pub fn arguments_count(&self) -> usize
Returns the number of arguments accepted by self.
sourcepub fn implementation(&self) -> Imp
pub fn implementation(&self) -> Imp
Returns the implementation of this method.
sourcepub unsafe fn set_implementation(&self, imp: Imp) -> Imp
pub unsafe fn set_implementation(&self, imp: Imp) -> Imp
Set the implementation of this method.
Note that any thread may at any point be changing method
implementations, so if you intend to call the previous method as
returned by e.g. Self::implementation
, beware that that may now be
stale.
The previous implementation is returned from this function though, so you can call that instead.
§Safety
The given implementation function pointer must:
-
Have the signature expected by the Objective-C runtime and callers of this method.
-
Be at least as safe as the existing method, i.e. by overriding the previous method, it should not be possible for the program to cause UB.
A common mistake would be expecting e.g. a pointer to not be null, where the null case was handled before.
sourcepub unsafe fn exchange_implementation(&self, other: &Self)
pub unsafe fn exchange_implementation(&self, other: &Self)
Exchange the implementation of two methods.
§Safety
The two methods must be perfectly compatible, both in signature, and in expected (in terms of safety, not necessarily behaviour) input and output.
§Example
This is an atomic version of the following:
use objc2::runtime::Method;
let m1: &Method;
let m2: &Method;
unsafe {
let imp = m2.set_implementation(m1.implementation());
m1.set_implementation(imp);
}