Better documentation for the new Default trait bound

This commit is contained in:
Setzer22 2022-10-29 18:29:57 +02:00
parent d6c1b324ee
commit 3fd60c532b
2 changed files with 9 additions and 3 deletions

View File

@ -473,9 +473,9 @@ where
} else {
// NOTE: We want to pass the `user_data` to
// `value_widget`, but we can't since that would require
// borrowing the graph twice. Here, we take the
// assumption that the value is cheaply replace, and use
// `std::mem::take` to temporarily replace it with a
// borrowing the graph twice. Here, we make the
// assumption that the value is cheaply replaced, and
// use `std::mem::take` to temporarily replace it with a
// dummy value. This requires `ValueType` to implement
// Default, but results in a totally safe alternative.
let mut value = std::mem::take(&mut self.graph[param_id].value);

View File

@ -3,6 +3,12 @@ use super::*;
/// This trait must be implemented by the `ValueType` generic parameter of the
/// [`Graph`]. The trait allows drawing custom inline widgets for the different
/// types of the node graph.
///
/// The [`Default`] trait bound is required to circumvent borrow checker issues
/// using `std::mem::take` Otherwise, it would be impossible to pass the
/// `node_data` parameter during `value_widget`. The default value is never
/// used, so the implementation is not important, but it should be reasonably
/// cheap to construct.
pub trait WidgetValueTrait : Default {
type Response;
type UserState;