MCPcopy Create free account
hub / github.com/SSheldon/rust-objc / get_ivar

Method get_ivar

src/runtime.rs:472–488  ·  view source on GitHub ↗

Returns a reference to the ivar of self with the given name. Panics if self has no ivar with the given name. Unsafe because the caller must ensure that the ivar is actually of type `T`.

(&self, name: &str)

Source from the content-addressed store, hash-verified

470 /// Unsafe because the caller must ensure that the ivar is actually
471 /// of type `T`.
472 pub unsafe fn get_ivar<T>(&self, name: &str) -> &T where T: Encode {
473 let offset = {
474 let cls = self.class();
475 match cls.instance_variable(name) {
476 Some(ivar) => {
477 assert!(ivar.type_encoding() == T::encode());
478 ivar.offset()
479 }
480 None => panic!("Ivar {} not found on class {:?}", name, cls),
481 }
482 };
483 let ptr = {
484 let self_ptr: *const Object = self;
485 (self_ptr as *const u8).offset(offset) as *const T
486 };
487 &*ptr
488 }
489
490 /// Returns a mutable reference to the ivar of self with the given name.
491 /// Panics if self has no ivar with the given name.

Callers 2

test_objectFunction · 0.80
mainFunction · 0.80

Calls 3

classMethod · 0.80
instance_variableMethod · 0.80
offsetMethod · 0.80

Tested by 1

test_objectFunction · 0.64