@@ -45,6 +45,43 @@ impl FunctionRegistry {
4545 /// This method is a convenience around calling [`IntoFunction::into_function`] and [`DynamicFunction::with_name`]
4646 /// on the function and inserting it into the registry using the [`register_dynamic`] method.
4747 ///
48+ /// # Examples
49+ ///
50+ /// ```
51+ /// # use bevy_reflect::func::{FunctionRegistrationError, FunctionRegistry};
52+ /// fn mul(a: i32, b: i32) -> i32 {
53+ /// a * b
54+ /// }
55+ ///
56+ /// # fn main() -> Result<(), FunctionRegistrationError> {
57+ /// let mut registry = FunctionRegistry::default();
58+ /// registry
59+ /// // Registering an anonymous function with a unique name
60+ /// .register("my_crate::add", |a: i32, b: i32| {
61+ /// a + b
62+ /// })?
63+ /// // Registering an existing function with its type name
64+ /// .register(std::any::type_name_of_val(&mul), mul)?
65+ /// // Registering an existing function with a custom name
66+ /// .register("my_crate::mul", mul)?;
67+ /// # Ok(())
68+ /// # }
69+ /// ```
70+ ///
71+ /// Names must be unique.
72+ ///
73+ /// ```should_panic
74+ /// # use bevy_reflect::func::FunctionRegistry;
75+ /// fn one() {}
76+ /// fn two() {}
77+ ///
78+ /// let mut registry = FunctionRegistry::default();
79+ /// registry.register("my_function", one).unwrap();
80+ ///
81+ /// // Panic! A function has already been registered with the name "my_function"
82+ /// registry.register("my_function", two).unwrap();
83+ /// ```
84+ ///
4885 /// [name]: DynamicFunction::name
4986 /// [`overwrite_registration`]: Self::overwrite_registration
5087 /// [type name]: std::any::type_name
@@ -70,6 +107,42 @@ impl FunctionRegistry {
70107 ///
71108 /// You can change the name of the function using [`DynamicFunction::with_name`].
72109 ///
110+ /// # Examples
111+ ///
112+ /// ```
113+ /// # use bevy_reflect::func::{DynamicFunction, FunctionRegistrationError, FunctionRegistry, IntoFunction};
114+ /// fn add(a: i32, b: i32) -> i32 {
115+ /// a + b
116+ /// }
117+ ///
118+ /// # fn main() -> Result<(), FunctionRegistrationError> {
119+ /// let mut registry = FunctionRegistry::default();
120+ ///
121+ /// // Register a `DynamicFunction` directly
122+ /// let function: DynamicFunction = add.into_function();
123+ /// registry.register_dynamic(function)?;
124+ ///
125+ /// // Register a `DynamicFunction` with a custom name
126+ /// let function: DynamicFunction = add.into_function().with_name("my_crate::add");
127+ /// registry.register_dynamic(function)?;
128+ /// # Ok(())
129+ /// # }
130+ /// ```
131+ ///
132+ /// Names must be unique.
133+ ///
134+ /// ```should_panic
135+ /// # use bevy_reflect::func::{DynamicFunction, FunctionRegistry, IntoFunction};
136+ /// fn one() {}
137+ /// fn two() {}
138+ ///
139+ /// let mut registry = FunctionRegistry::default();
140+ /// registry.register_dynamic(one.into_function().with_name("my_function")).unwrap();
141+ ///
142+ /// // Panic! A function has already been registered with the name "my_function"
143+ /// registry.register_dynamic(two.into_function().with_name("my_function")).unwrap();
144+ /// ```
145+ ///
73146 /// [name]: DynamicFunction::name
74147 /// [`overwrite_registration_dynamic`]: Self::overwrite_registration_dynamic
75148 pub fn register_dynamic (
0 commit comments