Struct objc2::runtime::Ivar

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

A type that represents an instance variable.

See Apple’s documentation.

Implementations§

source§

impl Ivar

source

pub fn name(&self) -> &str

Returns the instance variable’s name.

See Apple’s documentation.

source

pub fn offset(&self) -> isize

Returns the instance variable’s offset from the object base.

See Apple’s documentation.

source

pub fn type_encoding(&self) -> &str

Returns the instance variable’s @encode(type) string.

See Apple’s documentation.

source

pub unsafe fn load_ptr<T: Encode>(&self, obj: &AnyObject) -> *mut T

Returns a pointer to the instance variable / ivar on the given object.

This is similar to UnsafeCell::get, see that for more information on what is and isn’t safe to do.

Usually you will have defined the instance variable yourself with ClassBuilder::add_ivar, the type of the ivar T must match the type used in that.

Library implementors are strongly encouraged to expose a safe interface to the ivar.

§Panics

Panics when debug_assertions are enabled if the type encoding of the ivar differs from the type encoding of T.

§Safety

The object must have the given instance variable on it, and it must be of type T. Any invariants that the object have assumed about the value of the instance variable must not be violated.

Note that an object can have multiple instance variables with the same name; you must ensure that when the instance variable was retrieved, was retrieved from the class that it was defined on. In particular, getting a class dynamically using e.g. AnyObject::class, and using an instance variable from that here is not sound in general.

No thread syncronization is done on accesses to the variable, so you must ensure that any access to the returned pointer do not cause data races, and that Rust’s mutability rules are not otherwise violated.

source

pub unsafe fn load<'obj, T: Encode>(&self, obj: &'obj AnyObject) -> &'obj T

Returns a reference to the instance variable with the given name.

See Ivar::load_ptr for more information.

§Panics

Panics when debug_assertions are enabled if the type encoding of the ivar differs from the type encoding of T.

§Safety

The object must have the given instance variable on it, and it must be of type T.

No thread syncronization is done, so you must ensure that no other thread is concurrently mutating the variable. This requirement can be considered upheld if all mutation happens through Ivar::load_mut (since that takes the object mutably).

source

pub unsafe fn load_mut<'obj, T: Encode>( &self, obj: &'obj mut AnyObject ) -> &'obj mut T

Returns a mutable reference to the ivar with the given name.

See Ivar::load_ptr for more information.

§Panics

Panics when debug_assertions are enabled if the type encoding of the ivar differs from the type encoding of T.

§Safety

The object must have an instance variable with the given name, and it must be of type T.

This access happens through &mut, which means we know it to be the only reference, hence you do not need to do any work to ensure that data races do not happen.

Trait Implementations§

source§

impl Debug for Ivar

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for Ivar

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 Ivar

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 Ivar

source§

impl RefUnwindSafe for Ivar

source§

impl Send for Ivar

source§

impl Sync for Ivar

source§

impl UnwindSafe for Ivar

Auto Trait Implementations§

§

impl !Freeze for Ivar

§

impl !Unpin for Ivar

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,