mirror of
https://github.com/danbulant/cushy
synced 2026-07-06 11:40:37 +00:00
Added ForEach::for_each_subsequent
Refs #153 This turned out to be "needed" by the debug window due to how dynamic locking was nested when a for_each call was being invoked. To keep the code simple, for_each_subsequent was added.
This commit is contained in:
parent
7bd13e2a0a
commit
a6d5b078f5
2 changed files with 24 additions and 3 deletions
|
|
@ -211,7 +211,7 @@ impl DebugSection {
|
||||||
if let Some(parent) = parent.clone() {
|
if let Some(parent) = parent.clone() {
|
||||||
let label = label.clone();
|
let label = label.clone();
|
||||||
(&children, &values)
|
(&children, &values)
|
||||||
.for_each({
|
.for_each_subsequent({
|
||||||
move |(children, values)| {
|
move |(children, values)| {
|
||||||
if children.is_empty() && values.is_empty() {
|
if children.is_empty() && values.is_empty() {
|
||||||
Self::remove_child_section(&parent, &label);
|
Self::remove_child_section(&parent, &label);
|
||||||
|
|
|
||||||
25
src/value.rs
25
src/value.rs
|
|
@ -2981,10 +2981,19 @@ pub trait ForEach<T> {
|
||||||
/// The borrowed representation of T to pass into the `for_each` function.
|
/// The borrowed representation of T to pass into the `for_each` function.
|
||||||
type Ref<'a>;
|
type Ref<'a>;
|
||||||
|
|
||||||
/// Apply `for_each` to each value contained within `self`.
|
/// Invokes `for_each` with the current contents and each time this source's
|
||||||
|
/// contents are updated.
|
||||||
fn for_each<F>(&self, for_each: F) -> CallbackHandle
|
fn for_each<F>(&self, for_each: F) -> CallbackHandle
|
||||||
where
|
where
|
||||||
F: for<'a> FnMut(Self::Ref<'a>) + Send + 'static;
|
F: for<'a> FnMut(Self::Ref<'a>) + Send + 'static;
|
||||||
|
|
||||||
|
/// Attaches `for_each` to this value so that it is invoked each time the
|
||||||
|
/// source's contents are updated.
|
||||||
|
///
|
||||||
|
/// `for_each` will not be invoked with the currently stored value.
|
||||||
|
fn for_each_subsequent<F>(&self, for_each: F) -> CallbackHandle
|
||||||
|
where
|
||||||
|
F: for<'a> FnMut(Self::Ref<'a>) + Send + 'static;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_tuple_for_each {
|
macro_rules! impl_tuple_for_each {
|
||||||
|
|
@ -3000,6 +3009,18 @@ macro_rules! impl_tuple_for_each {
|
||||||
|
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
fn for_each<F>(&self, mut for_each: F) -> CallbackHandle
|
fn for_each<F>(&self, mut for_each: F) -> CallbackHandle
|
||||||
|
where
|
||||||
|
F: for<'a> FnMut(Self::Ref<'a>) + Send + 'static,
|
||||||
|
{
|
||||||
|
{
|
||||||
|
$(let $var = self.$field.read();)+
|
||||||
|
for_each(($(&$var,)+));
|
||||||
|
};
|
||||||
|
self.for_each_subsequent(for_each)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_mut)]
|
||||||
|
fn for_each_subsequent<F>(&self, mut for_each: F) -> CallbackHandle
|
||||||
where
|
where
|
||||||
F: for<'a> FnMut(Self::Ref<'a>) + Send + 'static,
|
F: for<'a> FnMut(Self::Ref<'a>) + Send + 'static,
|
||||||
{
|
{
|
||||||
|
|
@ -3070,7 +3091,7 @@ macro_rules! impl_tuple_for_each {
|
||||||
// The list of tuple fields excluding the one being invoked.
|
// The list of tuple fields excluding the one being invoked.
|
||||||
[$($rtype:ident $rfield:tt $rvar:ident),+]
|
[$($rtype:ident $rfield:tt $rvar:ident),+]
|
||||||
) => {
|
) => {
|
||||||
$handles += $var.for_each((&$for_each, $(&$rvar,)+).with_clone(|(for_each, $($rvar,)+)| {
|
$handles += $var.for_each_subsequent((&$for_each, $(&$rvar,)+).with_clone(|(for_each, $($rvar,)+)| {
|
||||||
move |$var: &$type| {
|
move |$var: &$type| {
|
||||||
$(let $rvar = $rvar.read();)+
|
$(let $rvar = $rvar.read();)+
|
||||||
let mut for_each =
|
let mut for_each =
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue