Struct objc2::runtime::Method

source ·
#[repr(C)]
pub struct Method(/* private fields */);
Expand description

A type that represents a method in a class definition.

See Apple’s documentation.

Implementations§

source§

impl Method

source

pub fn name(&self) -> Sel

Returns the name of self.

source

pub fn return_type( &self ) -> impl Deref<Target = str> + AsRef<str> + Debug + Display

Returns the Encoding of self’s return type.

source

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.

source

pub fn arguments_count(&self) -> usize

Returns the number of arguments accepted by self.

source

pub fn implementation(&self) -> Imp

Returns the implementation of this method.

source

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.

See Apple’s documentation.

§Safety

The given implementation function pointer must:

  1. Have the signature expected by the Objective-C runtime and callers of this method.

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

source

pub unsafe fn exchange_implementation(&self, other: &Self)

Exchange the implementation of two methods.

See Apple’s documentation.

§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);
}

Trait Implementations§

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: &Self) -> bool

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

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

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

impl Eq for Method

source§

impl RefUnwindSafe for Method

source§

impl Send for Method

source§

impl Sync for Method

source§

impl UnwindSafe for Method

Auto Trait Implementations§

§

impl !Freeze for Method

§

impl !Unpin 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.
source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,