polish: examples
This commit is contained in:
1 parent
4b6ca05f2c
commit
1a2f91ed91
19 files changed
+327
-183
No files matched your search
+15
-17
@@ -1,20 +1,18 @@
|
||||
#![allow(non_snake_case)]
|
||||
//! Example: Extremely nested borrowing
|
||||
//! -----------------------------------
|
||||
//!
|
||||
//! Dioxus manages borrow lifetimes for you. This means any child may borrow from its parent. However, it is not possible
|
||||
//! to hand out an &mut T to children - all props are consumed by &P, so you'd only get an &&mut T.
|
||||
//!
|
||||
//! How does it work?
|
||||
//!
|
||||
//! Dioxus will manually drop closures and props - things that borrow data before the component is ran again. This is done
|
||||
//! "bottom up" from the lowest child all the way to the initiating parent. As it traverses each listener and prop, the
|
||||
//! drop implementation is manually called, freeing any memory and ensuring that memory is not leaked.
|
||||
//!
|
||||
//! We cannot drop from the parent to the children - if the drop implementation modifies the data, downstream references
|
||||
//! might be broken since we take an &mut T and and &T to the data. Instead, we work bottom up, making sure to remove any
|
||||
//! potential references to the data before finally giving out an &mut T. This prevents us from mutably aliasing the data,
|
||||
//! and is proven to be safe with MIRI.
|
||||
/*
|
||||
Dioxus manages borrow lifetimes for you. This means any child may borrow from its parent. However, it is not possible
|
||||
to hand out an &mut T to children - all props are consumed by &P, so you'd only get an &&mut T.
|
||||
|
||||
How does it work?
|
||||
|
||||
Dioxus will manually drop closures and props - things that borrow data before the component is ran again. This is done
|
||||
"bottom up" from the lowest child all the way to the initiating parent. As it traverses each listener and prop, the
|
||||
drop implementation is manually called, freeing any memory and ensuring that memory is not leaked.
|
||||
|
||||
We cannot drop from the parent to the children - if the drop implementation modifies the data, downstream references
|
||||
might be broken since we take an &mut T and and &T to the data. Instead, we work bottom up, making sure to remove any
|
||||
potential references to the data before finally giving out an &mut T. This prevents us from mutably aliasing the data,
|
||||
and is proven to be safe with MIRI.
|
||||
*/
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
|
||||
Reference in new issue
Block a user