mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-11 22:08:28 +00:00
Better documentation for the new Default trait bound
This commit is contained in:
parent
d6c1b324ee
commit
3fd60c532b
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user