mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-19 17:58:29 +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 {
|
} else {
|
||||||
// NOTE: We want to pass the `user_data` to
|
// NOTE: We want to pass the `user_data` to
|
||||||
// `value_widget`, but we can't since that would require
|
// `value_widget`, but we can't since that would require
|
||||||
// borrowing the graph twice. Here, we take the
|
// borrowing the graph twice. Here, we make the
|
||||||
// assumption that the value is cheaply replace, and use
|
// assumption that the value is cheaply replaced, and
|
||||||
// `std::mem::take` to temporarily replace it with a
|
// use `std::mem::take` to temporarily replace it with a
|
||||||
// dummy value. This requires `ValueType` to implement
|
// dummy value. This requires `ValueType` to implement
|
||||||
// Default, but results in a totally safe alternative.
|
// Default, but results in a totally safe alternative.
|
||||||
let mut value = std::mem::take(&mut self.graph[param_id].value);
|
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
|
/// This trait must be implemented by the `ValueType` generic parameter of the
|
||||||
/// [`Graph`]. The trait allows drawing custom inline widgets for the different
|
/// [`Graph`]. The trait allows drawing custom inline widgets for the different
|
||||||
/// types of the node graph.
|
/// 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 {
|
pub trait WidgetValueTrait : Default {
|
||||||
type Response;
|
type Response;
|
||||||
type UserState;
|
type UserState;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user