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