pub struct Ref<'a, T>where
T: ?Sized,{ /* private fields */ }
Expand description
Shared borrow of an entity’s component
Implementations§
Source§impl<'a, T> Ref<'a, T>where
T: ?Sized,
impl<'a, T> Ref<'a, T>where
T: ?Sized,
Sourcepub fn map<U, F>(orig: Ref<'a, T>, f: F) -> Ref<'a, U>
pub fn map<U, F>(orig: Ref<'a, T>, f: F) -> Ref<'a, U>
Transform the Ref<'_, T>
to point to a part of the borrowed data, e.g.
a struct field.
The Ref<'_, T>
is already borrowed, so this cannot fail.
§Examples
struct Component {
member: i32,
}
let component_ref = entity_ref.get::<&Component>()
.expect("Entity does not contain an instance of \"Component\"");
let member_ref = Ref::map(component_ref, |component| &component.member);
println!("member = {:?}", *member_ref);
Trait Implementations§
impl<T> Send for Ref<'_, T>
impl<T> Sync for Ref<'_, T>
Auto Trait Implementations§
impl<'a, T> Freeze for Ref<'a, T>where
T: ?Sized,
impl<'a, T> RefUnwindSafe for Ref<'a, T>where
T: RefUnwindSafe + ?Sized,
impl<'a, T> Unpin for Ref<'a, T>where
T: ?Sized,
impl<'a, T> UnwindSafe for Ref<'a, T>where
T: RefUnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more