Skip to content

Commit

Permalink
Improve docs, rename to fn_pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopap committed May 27, 2023
1 parent 896477a commit 90373ac
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions crates/bevy_ecs/src/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,21 @@ impl ReflectComponent {

/// The underlying function pointers implementing methods on `ReflectComponent`.
///
/// Prefer using the methods over fetching the function pointers.
/// However, this is useful if you want to cache the functions rather than
/// repetitively using `TypeRegistry::get()` followed by `data()`.
pub fn fn_pointer(&self) -> &ReflectComponentFns {
/// This is useful when you want to keep track locally of an individual
/// function pointer.
///
/// Calling [`TypeRegistry::get`] followed by
/// [`TypeRegistration::data::<ReflectComponent>`] can be costly if done several
/// times per frame. Consider cloning [`ReflectComponent`] and keeping it
/// between frames, cloning a `ReflectComponent` is very cheap.
///
/// If you only need a subset of the methods on `ReflectComponent`,
/// use `fn_pointers` to get the underlying [`ReflectComponentFns`]
/// and copy the subset of function pointers you care about.
///
/// [`TypeRegistration::data::<ReflectComponent>`]: bevy_reflect::TypeRegistration::data
/// [`TypeRegistry::get`]: bevy_reflect::TypeRegistry::get
pub fn fn_pointers(&self) -> &ReflectComponentFns {
&self.0
}
}
Expand Down Expand Up @@ -372,10 +383,21 @@ impl ReflectResource {

/// The underlying function pointers implementing methods on `ReflectResource`.
///
/// Prefer using the methods over fetching the function pointers.
/// However, this is useful if you want to cache the functions rather than
/// repetitively using `TypeRegistry::get()` followed by `data()`.
pub fn fn_pointer(&self) -> &ReflectResourceFns {
/// This is useful when you want to keep track locally of an individual
/// function pointer.
///
/// Calling [`TypeRegistry::get`] followed by
/// [`TypeRegistration::data::<ReflectResource>`] can be costly if done several
/// times per frame. Consider cloning [`ReflectResource`] and keeping it
/// between frames, cloning a `ReflectResource` is very cheap.
///
/// If you only need a subset of the methods on `ReflectResource`,
/// use `fn_pointers` to get the underlying [`ReflectResourceFns`]
/// and copy the subset of function pointers you care about.
///
/// [`TypeRegistration::data::<ReflectResource>`]: bevy_reflect::TypeRegistration::data
/// [`TypeRegistry::get`]: bevy_reflect::TypeRegistry::get
pub fn fn_pointers(&self) -> &ReflectResourceFns {
&self.0
}
}
Expand Down

0 comments on commit 90373ac

Please sign in to comment.