1
0
Эх сурвалжийг харах

fmt: apply formatting just to tests

Jonathan Kelley 3 жил өмнө
parent
commit
00aa0e5e86

+ 3 - 1
packages/core/src/events.rs

@@ -12,7 +12,9 @@ pub(crate) struct BubbleState {
 
 impl BubbleState {
     pub fn new() -> Self {
-        Self { canceled: Cell::new(false) }
+        Self {
+            canceled: Cell::new(false),
+        }
     }
 }
 

+ 22 - 5
packages/core/src/lazynodes.rs

@@ -55,7 +55,9 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
             fac.map(inner)
         };
 
-        Self { inner: StackNodeStorage::Heap(Box::new(val)) }
+        Self {
+            inner: StackNodeStorage::Heap(Box::new(val)),
+        }
     }
 
     pub fn new(_val: impl FnOnce(NodeFactory<'a>) -> VNode<'a> + 'b) -> Self {
@@ -69,7 +71,9 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
 
         // miri does not know how to work with mucking directly into bytes
         if cfg!(miri) {
-            Self { inner: StackNodeStorage::Heap(Box::new(val)) }
+            Self {
+                inner: StackNodeStorage::Heap(Box::new(val)),
+            }
         } else {
             unsafe { LazyNodes::new_inner(val) }
         }
@@ -113,7 +117,9 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
         let max_size = mem::size_of::<StackHeapSize>();
 
         if stored_size > max_size {
-            Self { inner: StackNodeStorage::Heap(Box::new(val)) }
+            Self {
+                inner: StackNodeStorage::Heap(Box::new(val)),
+            }
         } else {
             let mut buf: StackHeapSize = StackHeapSize::default();
 
@@ -137,7 +143,13 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
 
             std::mem::forget(val);
 
-            Self { inner: StackNodeStorage::Stack(LazyStack { _align: [], buf, dropped: false }) }
+            Self {
+                inner: StackNodeStorage::Stack(LazyStack {
+                    _align: [],
+                    buf,
+                    dropped: false,
+                }),
+            }
         }
     }
 
@@ -286,7 +298,12 @@ mod tests {
         }
 
         let inner = Rc::new(0);
-        let mut dom = VirtualDom::new_with_props(app, AppProps { inner: inner.clone() });
+        let mut dom = VirtualDom::new_with_props(
+            app,
+            AppProps {
+                inner: inner.clone(),
+            },
+        );
         dom.rebuild();
 
         drop(dom);

+ 27 - 7
packages/core/src/mutations.rs

@@ -115,7 +115,11 @@ use DomEdit::*;
 
 impl<'a> Mutations<'a> {
     pub(crate) fn new() -> Self {
-        Self { edits: Vec::new(), refs: Vec::new(), diffed_scopes: Default::default() }
+        Self {
+            edits: Vec::new(),
+            refs: Vec::new(),
+            diffed_scopes: Default::default(),
+        }
     }
 
     // Navigation
@@ -174,12 +178,19 @@ impl<'a> Mutations<'a> {
 
     // events
     pub(crate) fn new_event_listener(&mut self, listener: &Listener, scope: ScopeId) {
-        let Listener { event, mounted_node, .. } = listener;
+        let Listener {
+            event,
+            mounted_node,
+            ..
+        } = listener;
 
         let element_id = mounted_node.get().unwrap().as_u64();
 
-        self.edits
-            .push(NewEventListener { scope, event_name: event, root: element_id });
+        self.edits.push(NewEventListener {
+            scope,
+            event_name: event,
+            root: element_id,
+        });
     }
     pub(crate) fn remove_event_listener(&mut self, event: &'static str, root: u64) {
         self.edits.push(RemoveEventListener { event, root });
@@ -191,10 +202,19 @@ impl<'a> Mutations<'a> {
     }
 
     pub(crate) fn set_attribute(&mut self, attribute: &'a Attribute, root: u64) {
-        let Attribute { name, value, namespace, .. } = attribute;
+        let Attribute {
+            name,
+            value,
+            namespace,
+            ..
+        } = attribute;
 
-        self.edits
-            .push(SetAttribute { field: name, value, ns: *namespace, root });
+        self.edits.push(SetAttribute {
+            field: name,
+            value,
+            ns: *namespace,
+            root,
+        });
     }
 
     pub(crate) fn remove_attribute(&mut self, attribute: &Attribute, root: u64) {

+ 41 - 17
packages/core/src/nodes.rs

@@ -365,7 +365,9 @@ pub struct EventHandler<'bump, T = ()> {
 
 impl<'a, T> Default for EventHandler<'a, T> {
     fn default() -> Self {
-        Self { callback: RefCell::new(None) }
+        Self {
+            callback: RefCell::new(None),
+        }
     }
 }
 
@@ -440,7 +442,10 @@ pub struct NodeFactory<'a> {
 
 impl<'a> NodeFactory<'a> {
     pub fn new(scope: &'a ScopeState) -> NodeFactory<'a> {
-        NodeFactory { scope, bump: &scope.wip_frame().bump }
+        NodeFactory {
+            scope,
+            bump: &scope.wip_frame().bump,
+        }
     }
 
     #[inline]
@@ -450,10 +455,11 @@ impl<'a> NodeFactory<'a> {
 
     /// Directly pass in text blocks without the need to use the format_args macro.
     pub fn static_text(&self, text: &'static str) -> VNode<'a> {
-        VNode::Text(
-            self.bump
-                .alloc(VText { id: empty_cell(), text, is_static: true }),
-        )
+        VNode::Text(self.bump.alloc(VText {
+            id: empty_cell(),
+            text,
+            is_static: true,
+        }))
     }
 
     /// Parses a lazy text Arguments and returns a string and a flag indicating if the text is 'static
@@ -476,7 +482,11 @@ impl<'a> NodeFactory<'a> {
     pub fn text(&self, args: Arguments) -> VNode<'a> {
         let (text, is_static) = self.raw_text(args);
 
-        VNode::Text(self.bump.alloc(VText { text, is_static, id: empty_cell() }))
+        VNode::Text(self.bump.alloc(VText {
+            text,
+            is_static,
+            id: empty_cell(),
+        }))
     }
 
     pub fn element(
@@ -534,7 +544,13 @@ impl<'a> NodeFactory<'a> {
         is_volatile: bool,
     ) -> Attribute<'a> {
         let (value, is_static) = self.raw_text(val);
-        Attribute { name, value, is_static, namespace, is_volatile }
+        Attribute {
+            name,
+            value,
+            is_static,
+            namespace,
+            is_volatile,
+        }
     }
 
     pub fn component<P>(
@@ -578,7 +594,11 @@ impl<'a> NodeFactory<'a> {
     }
 
     pub fn listener(self, event: &'static str, callback: InternalHandler<'a>) -> Listener<'a> {
-        Listener { event, mounted_node: Cell::new(None), callback }
+        Listener {
+            event,
+            mounted_node: Cell::new(None),
+            callback,
+        }
     }
 
     pub fn fragment_root<'b, 'c>(
@@ -594,10 +614,10 @@ impl<'a> NodeFactory<'a> {
         if nodes.is_empty() {
             VNode::Placeholder(self.bump.alloc(VPlaceholder { id: empty_cell() }))
         } else {
-            VNode::Fragment(
-                self.bump
-                    .alloc(VFragment { children: nodes.into_bump_slice(), key: None }),
-            )
+            VNode::Fragment(self.bump.alloc(VFragment {
+                children: nodes.into_bump_slice(),
+                key: None,
+            }))
         }
     }
 
@@ -633,7 +653,10 @@ impl<'a> NodeFactory<'a> {
                 );
             }
 
-            VNode::Fragment(self.bump.alloc(VFragment { children, key: None }))
+            VNode::Fragment(self.bump.alloc(VFragment {
+                children,
+                key: None,
+            }))
         }
     }
 
@@ -656,9 +679,10 @@ impl<'a> NodeFactory<'a> {
         } else {
             let children = nodes.into_bump_slice();
 
-            Some(VNode::Fragment(
-                self.bump.alloc(VFragment { children, key: None }),
-            ))
+            Some(VNode::Fragment(self.bump.alloc(VFragment {
+                children,
+                key: None,
+            })))
         }
     }
 

+ 22 - 7
packages/core/src/scopes.rs

@@ -315,9 +315,11 @@ impl ScopeArena {
             frame.node.set(unsafe { extend_vnode(node) });
         } else {
             let frame = scope.wip_frame();
-            let node = frame.bump.alloc(VNode::Placeholder(
-                frame.bump.alloc(VPlaceholder { id: Default::default() }),
-            ));
+            let node = frame
+                .bump
+                .alloc(VNode::Placeholder(frame.bump.alloc(VPlaceholder {
+                    id: Default::default(),
+                })));
             frame.node.set(unsafe { extend_vnode(node) });
         }
 
@@ -427,7 +429,10 @@ pub struct Scope<'a, P = ()> {
 impl<P> Copy for Scope<'_, P> {}
 impl<P> Clone for Scope<'_, P> {
     fn clone(&self) -> Self {
-        Self { scope: self.scope, props: self.props }
+        Self {
+            scope: self.scope,
+            props: self.props,
+        }
     }
 }
 
@@ -789,7 +794,10 @@ impl ScopeState {
     /// }
     ///```
     pub fn render<'src>(&'src self, rsx: LazyNodes<'src, '_>) -> Option<VNode<'src>> {
-        Some(rsx.call(NodeFactory { scope: self, bump: &self.wip_frame().bump }))
+        Some(rsx.call(NodeFactory {
+            scope: self,
+            bump: &self.wip_frame().bump,
+        }))
     }
 
     /// Store a value between renders
@@ -896,7 +904,10 @@ impl ScopeState {
         self.shared_contexts.get_mut().clear();
 
         // next: reset the node data
-        let SelfReferentialItems { borrowed_props, listeners } = self.items.get_mut();
+        let SelfReferentialItems {
+            borrowed_props,
+            listeners,
+        } = self.items.get_mut();
         borrowed_props.clear();
         listeners.clear();
         self.frames[0].reset();
@@ -954,7 +965,11 @@ pub(crate) struct TaskQueue {
 pub(crate) type InnerTask = Pin<Box<dyn Future<Output = ()>>>;
 impl TaskQueue {
     fn new(sender: UnboundedSender<SchedulerMsg>) -> Rc<Self> {
-        Rc::new(Self { tasks: RefCell::new(FxHashMap::default()), gen: Cell::new(0), sender })
+        Rc::new(Self {
+            tasks: RefCell::new(FxHashMap::default()),
+            gen: Cell::new(0),
+            sender,
+        })
     }
     fn push_fut(&self, task: impl Future<Output = ()> + 'static) -> TaskId {
         let pinned = Box::pin(task);

+ 4 - 1
packages/core/src/util.rs

@@ -10,7 +10,10 @@ pub struct ElementIdIterator<'a> {
 
 impl<'a> ElementIdIterator<'a> {
     pub fn new(vdom: &'a VirtualDom, node: &'a VNode<'a>) -> Self {
-        Self { vdom, stack: smallvec::smallvec![(0, node)] }
+        Self {
+            vdom,
+            stack: smallvec::smallvec![(0, node)],
+        }
     }
 }
 

+ 0 - 0
packages/core/.rustfmt.toml → packages/core/tests/.rustfmt.toml