fmt: apply cargofmt with new rules for lit structs
This commit is contained in:
1 parent
11f6b93889
commit
5bffbba682
11 files changed
+54
-195
No files matched your search
@@ -12,9 +12,7 @@ pub(crate) struct BubbleState {
|
||||
|
||||
impl BubbleState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
canceled: Cell::new(false),
|
||||
}
|
||||
Self { canceled: Cell::new(false) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,9 +55,7 @@ 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 {
|
||||
@@ -71,9 +69,7 @@ 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) }
|
||||
}
|
||||
@@ -117,9 +113,7 @@ 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();
|
||||
|
||||
@@ -143,13 +137,7 @@ 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 }) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,12 +286,7 @@ 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);
|
||||
|
||||
@@ -115,11 +115,7 @@ 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
|
||||
@@ -178,19 +174,12 @@ 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 });
|
||||
@@ -202,19 +191,10 @@ 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) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! cheap and *very* fast to construct - building a full tree should be quick.
|
||||
|
||||
use crate::{
|
||||
innerlude::{Element, FcSlot, Properties, Scope, ScopeId, ScopeState},
|
||||
innerlude::{ComponentPtr, Element, Properties, Scope, ScopeId, ScopeState},
|
||||
lazynodes::LazyNodes,
|
||||
AnyEvent, Component,
|
||||
};
|
||||
@@ -390,7 +390,7 @@ pub struct VComponent<'src> {
|
||||
pub originator: ScopeId,
|
||||
pub scope: Cell<Option<ScopeId>>,
|
||||
pub can_memoize: bool,
|
||||
pub user_fc: FcSlot,
|
||||
pub user_fc: ComponentPtr,
|
||||
pub fn_name: &'static str,
|
||||
pub props: RefCell<Option<Box<dyn AnyProps + 'src>>>,
|
||||
}
|
||||
@@ -551,7 +551,7 @@ impl<'a> NodeFactory<'a> {
|
||||
key: key.map(|f| self.raw_text(f).0),
|
||||
scope: Default::default(),
|
||||
can_memoize: P::IS_STATIC,
|
||||
user_fc: component as *mut std::os::raw::c_void,
|
||||
user_fc: component as ComponentPtr,
|
||||
originator: self.scope.scope_id(),
|
||||
fn_name,
|
||||
props: RefCell::new(Some(Box::new(VComponentProps {
|
||||
|
||||
@@ -14,8 +14,8 @@ use std::{
|
||||
};
|
||||
|
||||
/// for traceability, we use the raw fn pointer to identify the function
|
||||
/// we can use this with the traceback crate to resolve funciton names
|
||||
pub(crate) type FcSlot = *mut std::os::raw::c_void;
|
||||
/// we also get the component name, but that's not necessarily unique in the app
|
||||
pub(crate) type ComponentPtr = *mut std::os::raw::c_void;
|
||||
|
||||
pub(crate) struct Heuristic {
|
||||
hook_arena_size: usize,
|
||||
@@ -30,7 +30,7 @@ pub(crate) struct ScopeArena {
|
||||
pub scope_gen: Cell<usize>,
|
||||
pub bump: Bump,
|
||||
pub scopes: RefCell<FxHashMap<ScopeId, *mut ScopeState>>,
|
||||
pub heuristics: RefCell<FxHashMap<FcSlot, Heuristic>>,
|
||||
pub heuristics: RefCell<FxHashMap<ComponentPtr, Heuristic>>,
|
||||
pub free_scopes: RefCell<Vec<*mut ScopeState>>,
|
||||
pub nodes: RefCell<Slab<*const VNode<'static>>>,
|
||||
pub tasks: Rc<TaskQueue>,
|
||||
@@ -84,7 +84,7 @@ impl ScopeArena {
|
||||
|
||||
pub(crate) fn new_with_key(
|
||||
&self,
|
||||
fc_ptr: FcSlot,
|
||||
fc_ptr: ComponentPtr,
|
||||
vcomp: Box<dyn AnyProps>,
|
||||
parent_scope: Option<ScopeId>,
|
||||
container: ElementId,
|
||||
@@ -469,7 +469,7 @@ pub struct ScopeState {
|
||||
pub(crate) container: ElementId,
|
||||
pub(crate) our_arena_idx: ScopeId,
|
||||
pub(crate) height: u32,
|
||||
pub(crate) fnptr: FcSlot,
|
||||
pub(crate) fnptr: ComponentPtr,
|
||||
|
||||
// todo: subtrees
|
||||
pub(crate) is_subtree_root: Cell<bool>,
|
||||
|
||||
@@ -10,10 +10,7 @@ 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)] }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,18 +36,9 @@ fn test_original_diff() {
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement {
|
||||
root: 1,
|
||||
tag: "div"
|
||||
},
|
||||
CreateElement {
|
||||
root: 2,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 3,
|
||||
text: "Hello, world!"
|
||||
},
|
||||
CreateElement { root: 1, tag: "div" },
|
||||
CreateElement { root: 2, tag: "div" },
|
||||
CreateTextNode { root: 3, text: "Hello, world!" },
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 1 },
|
||||
@@ -81,34 +72,13 @@ fn create() {
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement {
|
||||
root: 1,
|
||||
tag: "div"
|
||||
},
|
||||
CreateElement {
|
||||
root: 2,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 3,
|
||||
text: "Hello, world!"
|
||||
},
|
||||
CreateElement {
|
||||
root: 4,
|
||||
tag: "div"
|
||||
},
|
||||
CreateElement {
|
||||
root: 5,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 6,
|
||||
text: "hello"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 7,
|
||||
text: "world"
|
||||
},
|
||||
CreateElement { root: 1, tag: "div" },
|
||||
CreateElement { root: 2, tag: "div" },
|
||||
CreateTextNode { root: 3, text: "Hello, world!" },
|
||||
CreateElement { root: 4, tag: "div" },
|
||||
CreateElement { root: 5, tag: "div" },
|
||||
CreateTextNode { root: 6, text: "hello" },
|
||||
CreateTextNode { root: 7, text: "world" },
|
||||
AppendChildren { many: 2 },
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 2 },
|
||||
@@ -135,32 +105,14 @@ fn create_list() {
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement {
|
||||
root: 1,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 2,
|
||||
text: "hello"
|
||||
},
|
||||
CreateElement { root: 1, tag: "div" },
|
||||
CreateTextNode { root: 2, text: "hello" },
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement {
|
||||
root: 3,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 4,
|
||||
text: "hello"
|
||||
},
|
||||
CreateElement { root: 3, tag: "div" },
|
||||
CreateTextNode { root: 4, text: "hello" },
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement {
|
||||
root: 5,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 6,
|
||||
text: "hello"
|
||||
},
|
||||
CreateElement { root: 5, tag: "div" },
|
||||
CreateTextNode { root: 6, text: "hello" },
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 3 },
|
||||
]
|
||||
@@ -185,22 +137,10 @@ fn create_simple() {
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement {
|
||||
root: 1,
|
||||
tag: "div"
|
||||
},
|
||||
CreateElement {
|
||||
root: 2,
|
||||
tag: "div"
|
||||
},
|
||||
CreateElement {
|
||||
root: 3,
|
||||
tag: "div"
|
||||
},
|
||||
CreateElement {
|
||||
root: 4,
|
||||
tag: "div"
|
||||
},
|
||||
CreateElement { root: 1, tag: "div" },
|
||||
CreateElement { root: 2, tag: "div" },
|
||||
CreateElement { root: 3, tag: "div" },
|
||||
CreateElement { root: 4, tag: "div" },
|
||||
AppendChildren { many: 4 },
|
||||
]
|
||||
);
|
||||
@@ -235,36 +175,18 @@ fn create_components() {
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement { root: 1, tag: "h1" },
|
||||
CreateElement {
|
||||
root: 2,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 3,
|
||||
text: "abc1"
|
||||
},
|
||||
CreateElement { root: 2, tag: "div" },
|
||||
CreateTextNode { root: 3, text: "abc1" },
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement { root: 4, tag: "p" },
|
||||
CreateElement { root: 5, tag: "h1" },
|
||||
CreateElement {
|
||||
root: 6,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 7,
|
||||
text: "abc2"
|
||||
},
|
||||
CreateElement { root: 6, tag: "div" },
|
||||
CreateTextNode { root: 7, text: "abc2" },
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement { root: 8, tag: "p" },
|
||||
CreateElement { root: 9, tag: "h1" },
|
||||
CreateElement {
|
||||
root: 10,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 11,
|
||||
text: "abc3"
|
||||
},
|
||||
CreateElement { root: 10, tag: "div" },
|
||||
CreateTextNode { root: 11, text: "abc3" },
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement { root: 12, tag: "p" },
|
||||
AppendChildren { many: 9 },
|
||||
@@ -285,14 +207,8 @@ fn anchors() {
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement {
|
||||
root: 1,
|
||||
tag: "div"
|
||||
},
|
||||
CreateTextNode {
|
||||
root: 2,
|
||||
text: "hello"
|
||||
},
|
||||
CreateElement { root: 1, tag: "div" },
|
||||
CreateTextNode { root: 2, text: "hello" },
|
||||
AppendChildren { many: 1 },
|
||||
CreatePlaceholder { root: 3 },
|
||||
AppendChildren { many: 2 },
|
||||
|
||||
@@ -580,7 +580,6 @@ fn keyed_diffing_additions_and_moves_in_middle() {
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
// LIS: 4, 5, 6
|
||||
let (_, change) = dom.diff_lazynodes(left, right);
|
||||
log::debug!("{:#?}", change);
|
||||
|
||||
@@ -152,12 +152,7 @@ fn free_works_on_root_props() {
|
||||
}
|
||||
}
|
||||
|
||||
let mut dom = new_dom(
|
||||
app,
|
||||
Custom {
|
||||
val: String::from("asd"),
|
||||
},
|
||||
);
|
||||
let mut dom = new_dom(app, Custom { val: String::from("asd") });
|
||||
dom.rebuild();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,7 @@ fn shared_state_test() {
|
||||
assert_eq!(
|
||||
edits,
|
||||
[
|
||||
CreateTextNode {
|
||||
root: 1,
|
||||
text: "Hello, world!"
|
||||
},
|
||||
CreateTextNode { root: 1, text: "Hello, world!" },
|
||||
AppendChildren { many: 1 },
|
||||
]
|
||||
);
|
||||
|
||||
@@ -68,15 +68,9 @@ fn conditional_rendering() {
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement { root: 1, tag: "h1" },
|
||||
CreateTextNode {
|
||||
root: 2,
|
||||
text: "hello"
|
||||
},
|
||||
CreateTextNode { root: 2, text: "hello" },
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement {
|
||||
root: 3,
|
||||
tag: "span"
|
||||
},
|
||||
CreateElement { root: 3, tag: "span" },
|
||||
CreateTextNode { root: 4, text: "a" },
|
||||
AppendChildren { many: 1 },
|
||||
CreatePlaceholder { root: 5 },
|
||||
|
||||
Reference in new issue
Block a user