diff --git a/.vscode/.gitignore b/.vscode/.gitignore index e38da2008..e69de29bb 100644 --- a/.vscode/.gitignore +++ b/.vscode/.gitignore @@ -1 +0,0 @@ -settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..a3b8a0b79 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "rust-analyzer.inlayHints.enable": false, + "rust-analyzer.cargo.allFeatures": true +} diff --git a/examples/calculator.rs b/examples/calculator.rs index eb1adc645..13b1cc865 100644 --- a/examples/calculator.rs +++ b/examples/calculator.rs @@ -1,12 +1,9 @@ //! Example: Calculator //! ------------------------- -// use dioxus::events::on::*; -// use dioxus::prelude::*; - fn main() { env_logger::init(); - dioxus::desktop::launch(App, |cfg| cfg); + dioxus::desktop::launch(App, |cfg| cfg).unwrap(); } use dioxus::events::on::*; @@ -97,10 +94,10 @@ const App: FC<()> = |cx, props| { } div { class: "digit-keys" CalculatorKey { name: "key-0", onclick: move |_| input_digit(0), "0" } - CalculatorKey { name: "key-dot", onclick: move |_| input_dot(), "●" } + CalculatorKey { name: "key-dot", onclick: move |_| input_dot(), "●" } - {(1..9).map(move |k| rsx!{ - CalculatorKey { key: "{k}", name: "key-{k}", onclick: move |_| input_digit(k), "{k}" } + {(1..9).map(|k| rsx!{ + CalculatorKey { key: "{k}", name: "key-{k}", onclick: move |_| input_digit(k), "{k}" } })} } div { class: "operator-keys" diff --git a/examples/manually.rs b/examples/manually.rs index 6bf3fb85d..9dd760bf7 100644 --- a/examples/manually.rs +++ b/examples/manually.rs @@ -17,6 +17,7 @@ fn main() { AppendChildren { many: 1 }, // ReplaceWith { many: 1 }, ]; + dioxus_desktop::WebviewRenderer::run_with_edits(App, (), |c| c, Some(edits)).expect("failed"); } diff --git a/packages/core-macro/src/ifmt.rs b/packages/core-macro/src/ifmt.rs index 816c1f400..5bac539d2 100644 --- a/packages/core-macro/src/ifmt.rs +++ b/packages/core-macro/src/ifmt.rs @@ -237,8 +237,8 @@ where // # Safety // // - This is the canonical example of using `ManuallyDrop`. - let value = ManuallyDrop::into_inner(ptr::read(&mut self.0)); - let drop = ManuallyDrop::into_inner(ptr::read(&mut self.1)); + let value = ManuallyDrop::into_inner(ptr::read(&self.0)); + let drop = ManuallyDrop::into_inner(ptr::read(&self.1)); drop(value); } } diff --git a/packages/core-macro/src/rsx/ambiguous.rs b/packages/core-macro/src/rsx/ambiguous.rs index bfcfbc374..ad535ef31 100644 --- a/packages/core-macro/src/rsx/ambiguous.rs +++ b/packages/core-macro/src/rsx/ambiguous.rs @@ -86,11 +86,11 @@ impl Parse for AmbiguousElement { if first_char.is_ascii_uppercase() { input .parse::>() - .map(|c| AmbiguousElement::Component(c)) + .map(AmbiguousElement::Component) } else { input .parse::>() - .map(|c| AmbiguousElement::Element(c)) + .map(AmbiguousElement::Element) } } else { Err(Error::new(input.span(), "Not a valid Html tag")) diff --git a/packages/core-macro/src/rsx/element.rs b/packages/core-macro/src/rsx/element.rs index 4d9a2f09e..451a3d1f9 100644 --- a/packages/core-macro/src/rsx/element.rs +++ b/packages/core-macro/src/rsx/element.rs @@ -270,7 +270,7 @@ fn parse_rsx_element_field( name, value: ty, namespace: None, - element_name: element_name.clone(), + element_name, }); return Ok(()); } diff --git a/packages/core/src/childiter.rs b/packages/core/src/childiter.rs index db3b19b62..e7032e939 100644 --- a/packages/core/src/childiter.rs +++ b/packages/core/src/childiter.rs @@ -39,7 +39,7 @@ impl<'a> Iterator for RealChildIterator<'a> { // We've recursed INTO an element/text // We need to recurse *out* of it and move forward to the next should_pop = true; - returned_node = Some(&*node); + returned_node = Some(node); } // If we get a fragment we push the next child diff --git a/packages/core/src/component.rs b/packages/core/src/component.rs index d19ec6581..0ec306229 100644 --- a/packages/core/src/component.rs +++ b/packages/core/src/component.rs @@ -29,7 +29,7 @@ use crate::innerlude::{Context, DomTree, LazyNodes, FC}; /// You want to use this free-function when your fragment needs a key and simply returning multiple nodes from rsx! won't cut it. /// #[allow(non_upper_case_globals, non_snake_case)] -pub fn Fragment<'a>(cx: Context<'a>, props: &'a ()) -> DomTree<'a> { +pub fn Fragment<'a>(cx: Context<'a>, _: &'a ()) -> DomTree<'a> { cx.render(LazyNodes::new(|f| f.fragment_from_iter(cx.children()))) } @@ -91,9 +91,7 @@ impl Properties for () { pub struct EmptyBuilder; impl EmptyBuilder { #[inline] - pub fn build(self) -> () { - () - } + pub fn build(self) {} } /// This utility function launches the builder method so rsx! and html! macros can use the typed-builder pattern diff --git a/packages/core/src/context.rs b/packages/core/src/context.rs index 991352c5f..9d16c9c01 100644 --- a/packages/core/src/context.rs +++ b/packages/core/src/context.rs @@ -34,10 +34,7 @@ pub struct Context<'src> { impl<'src> Copy for Context<'src> {} impl<'src> Clone for Context<'src> { fn clone(&self) -> Self { - Self { - // props: self.props, - scope: self.scope, - } + Self { scope: self.scope } } } @@ -202,16 +199,18 @@ impl<'src> Context<'src> { ); if !is_initialized { - self.scope - .shared_contexts - .borrow_mut() - .insert(TypeId::of::(), Rc::new(init())) - .map(|_| { + let existing = self + .scope + .shared_contexts + .borrow_mut() + .insert(TypeId::of::(), Rc::new(init())); + + if existing.is_some() { log::warn!( "A shared state was replaced with itself. \ This is does not result in a panic, but is probably not what you are trying to do" ); - }); + } } self.use_consume_state().unwrap() @@ -244,12 +243,15 @@ impl<'src> Context<'src> { /// - Runner: closure used to output a value every time the hook is used /// - Cleanup: closure used to teardown the hook once the dom is cleaned up /// + /// + /// # Example + /// /// ```ignore /// // use_ref is the simplest way of storing a value between renders - /// pub fn use_ref(initial_value: impl FnOnce() -> T + 'static) -> Rc> { + /// fn use_ref(initial_value: impl FnOnce() -> T) -> &RefCell { /// use_hook( /// || Rc::new(RefCell::new(initial_value())), - /// |state| state.clone(), + /// |state| state, /// |_| {}, /// ) /// } @@ -275,14 +277,14 @@ impl<'src> Context<'src> { ); } - const ERR_MSG: &str = r###" + runner(self.scope.hooks.next::().expect(HOOK_ERR_MSG)) + } +} + +const HOOK_ERR_MSG: &str = r###" Unable to retrive the hook that was initialized in this index. Consult the `rules of hooks` to understand how to use hooks properly. You likely used the hook in a conditional. Hooks rely on consistent ordering between renders. Any function prefixed with "use" should not be called conditionally. "###; - - runner(self.scope.hooks.next::().expect(ERR_MSG)) - } -} diff --git a/packages/core/src/diff.rs b/packages/core/src/diff.rs index 2da69817d..9dea0c71a 100644 --- a/packages/core/src/diff.rs +++ b/packages/core/src/diff.rs @@ -328,8 +328,8 @@ impl<'bump> DiffMachine<'bump> { self.mutations.set_attribute(attr); } - if children.len() > 0 { - self.stack.element_id_stack.push(real_id);; + if children.is_empty() { + self.stack.element_id_stack.push(real_id); // push our element_id onto the stack // drop our element off the stack self.stack.create_children(children, MountType::Append); @@ -341,7 +341,7 @@ impl<'bump> DiffMachine<'bump> { } fn create_component_node(&mut self, vcomponent: &'bump VComponent<'bump>) { - let caller = vcomponent.caller.clone(); + let caller = vcomponent.caller; let parent_idx = self.stack.current_scope().unwrap(); @@ -546,13 +546,15 @@ impl<'bump> DiffMachine<'bump> { // make sure the component's caller function is up to date let scope = self.vdom.get_scope_mut(scope_addr).unwrap(); - scope.update_scope_dependencies(new.caller.clone(), ScopeChildren(new.children)); + scope.update_scope_dependencies(new.caller, ScopeChildren(new.children)); // React doesn't automatically memoize, but we do. let props_are_the_same = old.comparator.unwrap(); if self.cfg.force_diff || !props_are_the_same(new) { - if scope.run_scope(self.vdom) { + let succeeded = scope.run_scope(self.vdom); + + if succeeded { self.diff_node(scope.frames.wip_head(), scope.frames.fin_head()); } } @@ -664,16 +666,20 @@ impl<'bump> DiffMachine<'bump> { self.stack.push(DiffInstruction::Diff { new, old }); } - if old.len() > new.len() { - self.remove_nodes(&old[new.len()..]); - } else if new.len() > old.len() { - log::debug!("Calling create children on array differences"); - self.stack.create_children( - &new[old.len()..], - MountType::InsertAfter { - other_node: old.last().unwrap(), - }, - ); + use std::cmp::Ordering; + match old.len().cmp(&new.len()) { + Ordering::Greater => self.remove_nodes(&old[new.len()..]), + Ordering::Less => { + self.stack.create_children( + &new[old.len()..], + MountType::InsertAfter { + other_node: old.last().unwrap(), + }, + ); + } + Ordering::Equal => { + // nothing - they're the same size + } } } @@ -922,7 +928,7 @@ impl<'bump> DiffMachine<'bump> { // for each spacing, generate a mount instruction let mut lis_iter = lis_sequence.iter().rev(); let mut last = *lis_iter.next().unwrap(); - while let Some(&next) = lis_iter.next() { + for next in lis_iter { if last - next > 1 { self.stack.push_nodes_created(0); self.stack.push(DiffInstruction::Mount { @@ -934,7 +940,7 @@ impl<'bump> DiffMachine<'bump> { apply(idx + next + 1, new_node, &mut self.stack); } } - last = next; + last = *next; } // add mount instruction for the first items not covered by the lis @@ -1036,25 +1042,27 @@ impl<'bump> DiffMachine<'bump> { for node in nodes { match node { VNode::Text(t) => { - t.dom_id.get().map(|id| { + if let Some(id) = t.dom_id.get() { self.mutations.remove(id.as_u64()); self.vdom.collect_garbage(id); - }); + } } VNode::Suspended(s) => { - s.dom_id.get().map(|id| { + if let Some(id) = s.dom_id.get() { self.mutations.remove(id.as_u64()); self.vdom.collect_garbage(id); - }); + } } VNode::Anchor(a) => { - a.dom_id.get().map(|id| { + if let Some(id) = a.dom_id.get() { self.mutations.remove(id.as_u64()); self.vdom.collect_garbage(id); - }); + } } VNode::Element(e) => { - e.dom_id.get().map(|id| self.mutations.remove(id.as_u64())); + if let Some(id) = e.dom_id.get() { + self.mutations.remove(id.as_u64()); + } } VNode::Fragment(f) => { self.remove_nodes(f.children); diff --git a/packages/core/src/diff_stack.rs b/packages/core/src/diff_stack.rs index 2e6479b2b..aa9716cb6 100644 --- a/packages/core/src/diff_stack.rs +++ b/packages/core/src/diff_stack.rs @@ -72,7 +72,7 @@ impl<'bump> DiffStack<'bump> { self.nodes_created_stack.push(0); self.instructions.push(DiffInstruction::Mount { and }); - for child in children.into_iter().rev() { + for child in children.iter().rev() { self.instructions .push(DiffInstruction::Create { node: child }); } @@ -82,7 +82,7 @@ impl<'bump> DiffStack<'bump> { self.nodes_created_stack.push(count); } - pub fn push_element_id(&mut self, id: ElementId) { + pub fn _push_element_id(&mut self, id: ElementId) { self.element_id_stack.push(id); } @@ -101,7 +101,7 @@ impl<'bump> DiffStack<'bump> { } pub fn current_scope(&self) -> Option { - self.scope_stack.last().map(|f| f.clone()) + self.scope_stack.last().copied() } pub fn create_component(&mut self, idx: ScopeId, node: &'bump VNode<'bump>) { diff --git a/packages/core/src/hooklist.rs b/packages/core/src/hooklist.rs index bea11a82a..2f68be3b8 100644 --- a/packages/core/src/hooklist.rs +++ b/packages/core/src/hooklist.rs @@ -52,8 +52,11 @@ impl HookList { pub(crate) fn at_end(&self) -> bool { self.cur_idx() >= self.len() } +} - pub(crate) fn cleanup_hooks(&mut self) { +// When the scope is dropped, we want to call the cleanup function for each of the hooks +impl Drop for HookList { + fn drop(&mut self) { self.vals .borrow_mut() .drain(..) diff --git a/packages/core/src/hooks.rs b/packages/core/src/hooks.rs index fcbf640d1..a0d12609e 100644 --- a/packages/core/src/hooks.rs +++ b/packages/core/src/hooks.rs @@ -11,13 +11,7 @@ use crate::innerlude::*; use futures_util::FutureExt; -use std::{ - any::{Any, TypeId}, - cell::RefCell, - future::Future, - ops::Deref, - rc::Rc, -}; +use std::{any::Any, cell::RefCell, future::Future, ops::Deref, rc::Rc}; /// Awaits the given task, forcing the component to re-render when the value is ready. /// @@ -104,11 +98,10 @@ where - if it doesn't, then we render a suspended node along with with the callback and task id */ cx.use_hook( - move |hook_idx| { + move |_| { let value = Rc::new(RefCell::new(None)); let slot = value.clone(); - - let originator = cx.scope.our_arena_idx.clone(); + let originator = cx.scope.our_arena_idx; let handle = cx.submit_task(Box::pin(task_initializer().then( move |output| async move { @@ -176,9 +169,7 @@ impl<'src> SuspendedContext<'src> { self, lazy_nodes: LazyNodes<'src, F>, ) -> DomTree<'src> { - let scope_ref = self.inner.scope; let bump = &self.inner.scope.frames.wip_frame().bump; - Some(lazy_nodes.into_vnode(NodeFactory { bump })) } } @@ -194,14 +185,5 @@ impl<'a, T> Deref for NodeRef<'a, T> { } pub fn use_node_ref(cx: Context) -> NodeRef { - cx.use_hook( - |f| {}, - |f| { - // - todo!() - }, - |f| { - // - }, - ) + cx.use_hook(|_| RefCell::new(None), |f| NodeRef { 0: f }, |_| {}) } diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index 555a9c285..926a36d46 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -307,7 +307,7 @@ impl<'a> NodeFactory<'a> { #[inline] pub fn bump(&self) -> &'a bumpalo::Bump { - &self.bump + self.bump } pub fn render_directly(&self, lazy_nodes: LazyNodes<'a, F>) -> DomTree<'a> @@ -466,12 +466,12 @@ impl<'a> NodeFactory<'a> { // - This comparator is only called on a corresponding set of bumpframes let props_memoized = unsafe { let real_other: &P = &*(other.raw_props as *const _ as *const P); - props.memoize(&real_other) + props.memoize(real_other) }; // It's only okay to memoize if there are no children and the props can be memoized // Implementing memoize is unsafe and done automatically with the props trait - match (props_memoized, children.len() == 0) { + match (props_memoized, children.is_empty()) { (true, true) => true, _ => false, } @@ -504,7 +504,7 @@ impl<'a> NodeFactory<'a> { RefCell::new(Some(drop_props)) }; - let is_static = children.len() == 0 && P::IS_STATIC && key.is_none(); + let is_static = children.is_empty() && P::IS_STATIC && key.is_none(); let key = key.map(|f| self.raw_text(f).0); @@ -515,7 +515,7 @@ impl<'a> NodeFactory<'a> { unsafe { std::mem::transmute(res) } }); - let can_memoize = children.len() == 0 && P::IS_STATIC; + let can_memoize = children.is_empty() && P::IS_STATIC; VNode::Component(bump.alloc(VComponent { user_fc, @@ -596,7 +596,7 @@ where nodes.push(node.into_vnode(cx)); } - if nodes.len() == 0 { + if nodes.is_empty() { nodes.push(VNode::Anchor(VAnchor { dom_id: empty_cell(), })); @@ -716,14 +716,14 @@ where // Conveniently, we also support "null" (nothing) passed in impl IntoVNode<'_> for () { - fn into_vnode<'a>(self, cx: NodeFactory<'a>) -> VNode<'a> { + fn into_vnode(self, cx: NodeFactory) -> VNode { cx.fragment_from_iter(None as Option) } } // Conveniently, we also support "None" impl IntoVNode<'_> for Option<()> { - fn into_vnode<'a>(self, cx: NodeFactory<'a>) -> VNode<'a> { + fn into_vnode(self, cx: NodeFactory) -> VNode { cx.fragment_from_iter(None as Option) } } @@ -738,12 +738,12 @@ impl<'a> IntoVNode<'a> for Option> { } impl IntoVNode<'_> for &'static str { - fn into_vnode<'a>(self, cx: NodeFactory<'a>) -> VNode<'a> { + fn into_vnode(self, cx: NodeFactory) -> VNode { cx.static_text(self) } } impl IntoVNode<'_> for Arguments<'_> { - fn into_vnode<'a>(self, cx: NodeFactory<'a>) -> VNode<'a> { + fn into_vnode(self, cx: NodeFactory) -> VNode { cx.text(self) } } diff --git a/packages/core/src/scheduler.rs b/packages/core/src/scheduler.rs index 8c69e081b..542b28e01 100644 --- a/packages/core/src/scheduler.rs +++ b/packages/core/src/scheduler.rs @@ -88,9 +88,11 @@ pub(crate) struct EventChannel { pub sender: UnboundedSender, pub schedule_any_immediate: Rc, pub submit_task: Rc TaskHandle>, - pub get_shared_context: Rc Option>>, + pub get_shared_context: GetSharedContext, } +pub type GetSharedContext = Rc Option>>; + pub enum SchedulerMsg { // events from the host UiEvent(UserEvent), @@ -175,7 +177,6 @@ impl Scheduler { Rc::new(move |id| sender.unbounded_send(SchedulerMsg::Immediate(id)).unwrap()) }, submit_task: { - let sender = sender.clone(); Rc::new(move |fiber_task| { let task_id = task_counter.get(); task_counter.set(task_id + 1); @@ -206,7 +207,7 @@ impl Scheduler { }; let pool = ResourcePool { - components: components.clone(), + components, raw_elements, channel, }; @@ -295,7 +296,7 @@ impl Scheduler { } pub fn has_pending_events(&self) -> bool { - self.ui_events.len() > 0 + !self.ui_events.is_empty() } /// re-balance the work lanes, ensuring high-priority work properly bumps away low priority work @@ -550,6 +551,6 @@ impl PriorityLane { } fn has_work(&self) -> bool { - self.dirty_scopes.len() > 0 || self.in_progress == true + !self.dirty_scopes.is_empty() || self.in_progress } } diff --git a/packages/core/src/scope.rs b/packages/core/src/scope.rs index b696a96cd..4ae5d0d1a 100644 --- a/packages/core/src/scope.rs +++ b/packages/core/src/scope.rs @@ -190,7 +190,7 @@ impl Scope { self.child_nodes = child_nodes; } - pub(crate) fn child_nodes<'a>(&'a self) -> ScopeChildren { + pub(crate) fn child_nodes(&self) -> ScopeChildren { unsafe { self.child_nodes.shorten_lifetime() } } @@ -246,10 +246,7 @@ impl Scope { let search_id = search.mounted_node.get(); // this assumes the node might not be mounted - should we assume that though? - match search_id.map(|f| f == element) { - Some(same) => same, - None => false, - } + search_id.map(|f| f == element).unwrap_or(false) }); if let Some(raw_listener) = raw_listener { @@ -356,11 +353,11 @@ impl<'a> ScopeRenderer<'a> { match &node { VNode::Text(text) => { write_indent(f, il); - write!(f, "\"{}\"\n", text.text)? + writeln!(f, "\"{}\"", text.text)? } VNode::Anchor(_anchor) => { write_indent(f, il); - write!(f, "Anchor {{}}\n")?; + writeln!(f, "Anchor {{}}")?; } VNode::Element(el) => { write_indent(f, il); @@ -373,7 +370,7 @@ impl<'a> ScopeRenderer<'a> { None => { // write_indent(f, il + 1); - write!(f, "{}: \"{}\"\n", attr.name, attr.value)? + writeln!(f, "{}: \"{}\"", attr.name, attr.value)? } Some(ns) => { @@ -401,17 +398,17 @@ impl<'a> ScopeRenderer<'a> { } write_indent(f, il); - write!(f, "}}\n")?; + writeln!(f, "}}")?; } VNode::Fragment(frag) => { if self.show_fragments { write_indent(f, il); - write!(f, "Fragment {{\n")?; + writeln!(f, "Fragment {{")?; for child in frag.children { self.render(vdom, child, f, il + 1)?; } write_indent(f, il); - write!(f, "}}\n")?; + writeln!(f, "}}")?; } else { for child in frag.children { self.render(vdom, child, f, il)?; diff --git a/packages/core/src/test_dom.rs b/packages/core/src/test_dom.rs index 6e89e817f..60d2de9b8 100644 --- a/packages/core/src/test_dom.rs +++ b/packages/core/src/test_dom.rs @@ -16,7 +16,7 @@ impl TestDom { TestDom { bump, scheduler } } - pub fn new_factory<'a>(&'a self) -> NodeFactory<'a> { + pub fn new_factory(&self) -> NodeFactory { NodeFactory::new(&self.bump) } @@ -87,6 +87,12 @@ impl TestDom { } } +impl Default for TestDom { + fn default() -> Self { + Self::new() + } +} + impl VirtualDom { pub fn simulate(&mut self) { // diff --git a/packages/core/src/util.rs b/packages/core/src/util.rs index d516761db..63962d792 100644 --- a/packages/core/src/util.rs +++ b/packages/core/src/util.rs @@ -1,8 +1,6 @@ use std::cell::Cell; use std::fmt::Display; -use crate::innerlude::*; - // create a cell with a "none" value #[inline] pub fn empty_cell() -> Cell> { diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 849b1f7cf..6c2233f13 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -20,6 +20,7 @@ //! Additional functionality is defined in the respective files. use crate::innerlude::*; +use futures_util::Future; use std::any::Any; /// An integrated virtual node system that progresses events and diffs UI trees. @@ -186,7 +187,10 @@ impl VirtualDom { /// /// let mutations = dom.update_root_props(AppProps { route: "end" }).unwrap(); /// ``` - pub fn update_root_props<'s, P: 'static>(&'s mut self, root_props: P) -> Option> { + pub fn update_root_props

(&mut self, root_props: P) -> Option + where + P: 'static, + { let root_scope = self.scheduler.pool.get_scope_mut(self.base_scope).unwrap(); // Pre-emptively drop any downstream references of the old props @@ -233,7 +237,7 @@ impl VirtualDom { /// /// apply_edits(edits); /// ``` - pub fn rebuild<'s>(&'s mut self) -> Mutations<'s> { + pub fn rebuild(&mut self) -> Mutations { self.scheduler.rebuild(self.base_scope) } @@ -271,7 +275,7 @@ impl VirtualDom { /// /// let edits = dom.diff(); /// ``` - pub fn diff<'s>(&'s mut self) -> Mutations<'s> { + pub fn diff(&mut self) -> Mutations { self.scheduler.hard_diff(self.base_scope) } @@ -279,7 +283,7 @@ impl VirtualDom { /// /// This method will not wait for any suspended nodes to complete. If there is no pending work, then this method will /// return "None" - pub fn run_immediate<'s>(&'s mut self) -> Option>> { + pub fn run_immediate(&mut self) -> Option> { if self.scheduler.has_any_work() { Some(self.scheduler.work_sync()) } else { @@ -330,10 +334,10 @@ impl VirtualDom { /// applied the edits. /// /// Mutations are the only link between the RealDOM and the VirtualDOM. - pub async fn run_with_deadline<'s>( - &'s mut self, - deadline: impl std::future::Future, - ) -> Vec> { + pub async fn run_with_deadline( + &mut self, + deadline: impl Future, + ) -> Vec> { self.scheduler.work_with_deadline(deadline).await } @@ -380,8 +384,3 @@ impl std::fmt::Display for VirtualDom { renderer.render(self, root, f, 0) } } - -pub struct VirtualDomConfig { - component_slab_size: usize, - element_slab_size: usize, -} diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index c9c7153b4..436103a70 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -64,10 +64,12 @@ impl WebviewRenderer { Self::run_with_edits(root, props, user_builder, None) } - pub fn run_with_edits( + pub fn run_with_edits< + F: for<'a, 'b> FnOnce(&'a mut DesktopConfig<'b>) -> &'a mut DesktopConfig<'b>, + >( root: FC, props: T, - user_builder: impl for<'a, 'b> FnOnce(&'a mut DesktopConfig<'b>) -> &'a mut DesktopConfig<'b>, + user_builder: F, redits: Option>>, ) -> anyhow::Result<()> { log::info!("hello edits");