pass clippy (#575)

This commit is contained in:
Demonthos authored and GitHub committed 2022-10-02 14:12:24 -07:00
1 parent 047ed1e553
commit daeffd4149
20 files changed
+259 -345

No files matched your search

+1 -1
View File
@@ -781,7 +781,7 @@ Finally, call `.build()` to create the instance of `{name}`.
let arg_type = if field.builder_attr.strip_option { let arg_type = if field.builder_attr.strip_option {
field.type_from_inside_option(false).ok_or_else(|| { field.type_from_inside_option(false).ok_or_else(|| {
Error::new_spanned( Error::new_spanned(
&field_type, field_type,
"can't `strip_option` - field is not `Option<...>`", "can't `strip_option` - field is not `Option<...>`",
) )
})? })?
+93 -92
View File
@@ -157,7 +157,7 @@ impl<'b> DiffState<'b> {
} }
(Component(old), Component(new)) => { (Component(old), Component(new)) => {
self.diff_component_nodes(*old, *new, old_node, new_node); self.diff_component_nodes(old, new, old_node, new_node);
} }
(Fragment(old), Fragment(new)) => { (Fragment(old), Fragment(new)) => {
@@ -181,8 +181,8 @@ impl<'b> DiffState<'b> {
VNode::Placeholder(anchor) => self.create_anchor_node(anchor, node), VNode::Placeholder(anchor) => self.create_anchor_node(anchor, node),
VNode::Element(element) => self.create_element_node(element, node), VNode::Element(element) => self.create_element_node(element, node),
VNode::Fragment(frag) => self.create_fragment_node(frag), VNode::Fragment(frag) => self.create_fragment_node(frag),
VNode::Component(component) => self.create_component_node(*component), VNode::Component(component) => self.create_component_node(component),
VNode::TemplateRef(temp) => self.create_template_ref_node(*temp, node), VNode::TemplateRef(temp) => self.create_template_ref_node(temp, node),
} }
} }
@@ -572,6 +572,7 @@ impl<'b> DiffState<'b> {
self.diff_children(old.children, new.children); self.diff_children(old.children, new.children);
} }
#[allow(clippy::too_many_lines)]
fn diff_template_ref_nodes( fn diff_template_ref_nodes(
&mut self, &mut self,
old: &'b VTemplateRef<'b>, old: &'b VTemplateRef<'b>,
@@ -579,6 +580,94 @@ impl<'b> DiffState<'b> {
old_node: &'b VNode<'b>, old_node: &'b VNode<'b>,
new_node: &'b VNode<'b>, new_node: &'b VNode<'b>,
) { ) {
fn diff_attributes<'b, Nodes, Attributes, V, Children, Listeners, TextSegments, Text>(
nodes: &Nodes,
ctx: (
&mut Mutations<'b>,
&'b Bump,
&VTemplateRef<'b>,
&Template,
usize,
),
) where
Nodes: AsRef<[TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>]>,
Attributes: AsRef<[TemplateAttribute<V>]>,
V: TemplateValue,
Children: AsRef<[TemplateNodeId]>,
Listeners: AsRef<[usize]>,
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
Text: AsRef<str>,
{
let (mutations, scope_bump, new, template, idx) = ctx;
for (node_id, attr_idx) in template.get_dynamic_nodes_for_attribute_index(idx) {
if let TemplateNodeType::Element(el) = &nodes.as_ref()[node_id.0].node_type {
let TemplateElement { attributes, .. } = el;
let attr = &attributes.as_ref()[*attr_idx];
let attribute = Attribute {
attribute: attr.attribute,
value: new.dynamic_context.resolve_attribute(idx).clone(),
is_static: false,
};
mutations.set_attribute(scope_bump.alloc(attribute), *node_id);
} else {
panic!("expected element node");
}
}
}
fn set_attribute<'b, Attributes, V, Children, Listeners, TextSegments, Text>(
node: &TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>,
ctx: (&mut Mutations<'b>, &'b Bump, &VTemplateRef<'b>, usize),
) where
Attributes: AsRef<[TemplateAttribute<V>]>,
V: TemplateValue,
Children: AsRef<[TemplateNodeId]>,
Listeners: AsRef<[usize]>,
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
Text: AsRef<str>,
{
let (mutations, scope_bump, new, template_attr_idx) = ctx;
if let TemplateNodeType::Element(el) = &node.node_type {
let TemplateElement { attributes, .. } = el;
let attr = &attributes.as_ref()[template_attr_idx];
let value = match &attr.value {
TemplateAttributeValue::Dynamic(idx) => {
new.dynamic_context.resolve_attribute(*idx).clone()
}
TemplateAttributeValue::Static(value) => value.allocate(scope_bump),
};
let attribute = Attribute {
attribute: attr.attribute,
value,
is_static: false,
};
mutations.set_attribute(scope_bump.alloc(attribute), node.id);
} else {
panic!("expected element node");
}
}
fn diff_dynamic_node<'b, Attributes, V, Children, Listeners, TextSegments, Text>(
node: &TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>,
ctx: (&mut DiffState<'b>, &'b VNode<'b>, &'b VNode<'b>, ElementId),
) where
Attributes: AsRef<[TemplateAttribute<V>]>,
V: TemplateValue,
Children: AsRef<[TemplateNodeId]>,
Listeners: AsRef<[usize]>,
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
Text: AsRef<str>,
{
let (diff, old_node, new_node, root) = ctx;
if let TemplateNodeType::Element { .. } = node.node_type {
diff.element_stack.push(GlobalNodeId::VNodeId(root));
diff.diff_node(old_node, new_node);
diff.element_stack.pop();
} else {
diff.diff_node(old_node, new_node);
}
}
if std::ptr::eq(old, new) { if std::ptr::eq(old, new) {
return; return;
} }
@@ -617,41 +706,6 @@ impl<'b> DiffState<'b> {
}; };
let template = template.borrow(); let template = template.borrow();
fn diff_attributes<'b, Nodes, Attributes, V, Children, Listeners, TextSegments, Text>(
nodes: &Nodes,
ctx: (
&mut Mutations<'b>,
&'b Bump,
&VTemplateRef<'b>,
&Template,
usize,
),
) where
Nodes: AsRef<[TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>]>,
Attributes: AsRef<[TemplateAttribute<V>]>,
V: TemplateValue,
Children: AsRef<[TemplateNodeId]>,
Listeners: AsRef<[usize]>,
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
Text: AsRef<str>,
{
let (mutations, scope_bump, new, template, idx) = ctx;
for (node_id, attr_idx) in template.get_dynamic_nodes_for_attribute_index(idx) {
if let TemplateNodeType::Element(el) = &nodes.as_ref()[node_id.0].node_type {
let TemplateElement { attributes, .. } = el;
let attr = &attributes.as_ref()[*attr_idx];
let attribute = Attribute {
attribute: attr.attribute,
value: new.dynamic_context.resolve_attribute(idx).clone(),
is_static: false,
};
mutations.set_attribute(scope_bump.alloc(attribute), *node_id);
} else {
panic!("expected element node");
}
}
}
// diff dynamic attributes // diff dynamic attributes
for (idx, (old_attr, new_attr)) in old for (idx, (old_attr, new_attr)) in old
.dynamic_context .dynamic_context
@@ -669,38 +723,6 @@ impl<'b> DiffState<'b> {
} }
} }
fn set_attribute<'b, Attributes, V, Children, Listeners, TextSegments, Text>(
node: &TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>,
ctx: (&mut Mutations<'b>, &'b Bump, &VTemplateRef<'b>, usize),
) where
Attributes: AsRef<[TemplateAttribute<V>]>,
V: TemplateValue,
Children: AsRef<[TemplateNodeId]>,
Listeners: AsRef<[usize]>,
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
Text: AsRef<str>,
{
let (mutations, scope_bump, new, template_attr_idx) = ctx;
if let TemplateNodeType::Element(el) = &node.node_type {
let TemplateElement { attributes, .. } = el;
let attr = &attributes.as_ref()[template_attr_idx];
let value = match &attr.value {
TemplateAttributeValue::Dynamic(idx) => {
new.dynamic_context.resolve_attribute(*idx).clone()
}
TemplateAttributeValue::Static(value) => value.allocate(scope_bump),
};
let attribute = Attribute {
attribute: attr.attribute,
value,
is_static: false,
};
mutations.set_attribute(scope_bump.alloc(attribute), node.id);
} else {
panic!("expected element node");
}
}
// set all volatile attributes // set all volatile attributes
for (id, idx) in template.volatile_attributes() { for (id, idx) in template.volatile_attributes() {
template.with_node( template.with_node(
@@ -708,28 +730,7 @@ impl<'b> DiffState<'b> {
set_attribute, set_attribute,
set_attribute, set_attribute,
(&mut self.mutations, scope_bump, new, idx), (&mut self.mutations, scope_bump, new, idx),
) );
}
fn diff_dynamic_node<'b, Attributes, V, Children, Listeners, TextSegments, Text>(
node: &TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>,
ctx: (&mut DiffState<'b>, &'b VNode<'b>, &'b VNode<'b>, ElementId),
) where
Attributes: AsRef<[TemplateAttribute<V>]>,
V: TemplateValue,
Children: AsRef<[TemplateNodeId]>,
Listeners: AsRef<[usize]>,
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
Text: AsRef<str>,
{
let (diff, old_node, new_node, root) = ctx;
if let TemplateNodeType::Element { .. } = node.node_type {
diff.element_stack.push(GlobalNodeId::VNodeId(root));
diff.diff_node(old_node, new_node);
diff.element_stack.pop();
} else {
diff.diff_node(old_node, new_node);
}
} }
// diff dynmaic nodes // diff dynmaic nodes
@@ -26,7 +26,7 @@ impl<T> PartialEq for LazyStaticVec<T> {
/// Stores what nodes depend on specific dynamic parts of the template to allow the diffing algorithm to jump to that part of the template instead of travering it /// Stores what nodes depend on specific dynamic parts of the template to allow the diffing algorithm to jump to that part of the template instead of travering it
/// This makes adding constant template nodes add no additional cost to diffing. /// This makes adding constant template nodes add no additional cost to diffing.
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct DynamicNodeMapping< pub struct DynamicNodeMapping<
Nodes, Nodes,
@@ -97,7 +97,7 @@ where
} }
} }
pub(crate) fn all_dynamic<'a>(&'a self) -> impl Iterator<Item = TemplateNodeId> + 'a { pub(crate) fn all_dynamic(&self) -> impl Iterator<Item = TemplateNodeId> + '_ {
self.nodes self.nodes
.as_ref() .as_ref()
.iter() .iter()
@@ -106,16 +106,14 @@ where
self.text self.text
.as_ref() .as_ref()
.iter() .iter()
.map(|ids| ids.as_ref().iter()) .flat_map(|ids| ids.as_ref().iter()),
.flatten(),
) )
.copied() .copied()
.chain( .chain(
self.attributes self.attributes
.as_ref() .as_ref()
.iter() .iter()
.map(|ids| ids.as_ref().iter()) .flat_map(|ids| ids.as_ref().iter())
.flatten()
.map(|dynamic| dynamic.0), .map(|dynamic| dynamic.0),
) )
.chain(self.nodes_with_listeners.as_ref().iter().copied()) .chain(self.nodes_with_listeners.as_ref().iter().copied())
+6 -6
View File
@@ -37,9 +37,9 @@ pub enum GlobalNodeId {
VNodeId(ElementId), VNodeId(ElementId),
} }
impl Into<GlobalNodeId> for ElementId { impl From<ElementId> for GlobalNodeId {
fn into(self) -> GlobalNodeId { fn from(id: ElementId) -> GlobalNodeId {
GlobalNodeId::VNodeId(self) GlobalNodeId::VNodeId(id)
} }
} }
@@ -279,9 +279,9 @@ impl ElementId {
} }
} }
impl Into<u64> for ElementId { impl From<ElementId> for u64 {
fn into(self) -> u64 { fn from(el: ElementId) -> u64 {
self.0 as u64 el.0 as u64
} }
} }
+1 -1
View File
@@ -357,7 +357,7 @@ impl ScopeArena {
( (
&nodes, &nodes,
&template_ref.dynamic_context, &template_ref.dynamic_context,
&event, event,
&state, &state,
template_ref_id, template_ref_id,
), ),
+24 -32
View File
@@ -264,9 +264,9 @@ pub struct TemplateId(pub CodeLocation);
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct RendererTemplateId(pub usize); pub struct RendererTemplateId(pub usize);
impl Into<u64> for RendererTemplateId { impl From<RendererTemplateId> for u64 {
fn into(self) -> u64 { fn from(id: RendererTemplateId) -> u64 {
self.0 as u64 id.0 as u64
} }
} }
@@ -278,9 +278,9 @@ impl Into<u64> for RendererTemplateId {
#[cfg_attr(feature = "serialize", serde(transparent))] #[cfg_attr(feature = "serialize", serde(transparent))]
pub struct TemplateNodeId(pub usize); pub struct TemplateNodeId(pub usize);
impl Into<u64> for TemplateNodeId { impl From<TemplateNodeId> for u64 {
fn into(self) -> u64 { fn from(id: TemplateNodeId) -> u64 {
JS_MAX_INT / 2 + self.0 as u64 JS_MAX_INT / 2 + id.0 as u64
} }
} }
@@ -434,7 +434,7 @@ impl Template {
mutations.append_children(children_created); mutations.append_children(children_created);
} }
TemplateNodeType::Text(text) => { TemplateNodeType::Text(text) => {
let mut text_iter = text.segments.as_ref().into_iter(); let mut text_iter = text.segments.as_ref().iter();
if let (Some(TextTemplateSegment::Static(txt)), None) = if let (Some(TextTemplateSegment::Static(txt)), None) =
(text_iter.next(), text_iter.next()) (text_iter.next(), text_iter.next())
{ {
@@ -550,23 +550,20 @@ impl Template {
} }
} }
pub(crate) fn get_dynamic_nodes_for_text_index<'a>( pub(crate) fn get_dynamic_nodes_for_text_index(&self, idx: usize) -> &[TemplateNodeId] {
&'a self,
idx: usize,
) -> &'a [TemplateNodeId] {
match self { match self {
Template::Static(s) => s.dynamic_mapping.text[idx].as_ref(), Template::Static(s) => s.dynamic_mapping.text[idx],
#[cfg(any(feature = "hot-reload", debug_assertions))] #[cfg(any(feature = "hot-reload", debug_assertions))]
Template::Owned(o) => o.dynamic_mapping.text[idx].as_ref(), Template::Owned(o) => o.dynamic_mapping.text[idx].as_ref(),
} }
} }
pub(crate) fn get_dynamic_nodes_for_attribute_index<'a>( pub(crate) fn get_dynamic_nodes_for_attribute_index(
&'a self, &self,
idx: usize, idx: usize,
) -> &'a [(TemplateNodeId, usize)] { ) -> &[(TemplateNodeId, usize)] {
match self { match self {
Template::Static(s) => s.dynamic_mapping.attributes[idx].as_ref(), Template::Static(s) => s.dynamic_mapping.attributes[idx],
#[cfg(any(feature = "hot-reload", debug_assertions))] #[cfg(any(feature = "hot-reload", debug_assertions))]
Template::Owned(o) => o.dynamic_mapping.attributes[idx].as_ref(), Template::Owned(o) => o.dynamic_mapping.attributes[idx].as_ref(),
} }
@@ -610,7 +607,7 @@ pub type OwnedRootNodes = Vec<TemplateNodeId>;
/// Templates can only contain a limited subset of VNodes and keys are not needed, as diffing will be skipped. /// Templates can only contain a limited subset of VNodes and keys are not needed, as diffing will be skipped.
/// Dynamic parts of the Template are inserted into the VNode using the `TemplateContext` by traversing the tree in order and filling in dynamic parts /// Dynamic parts of the Template are inserted into the VNode using the `TemplateContext` by traversing the tree in order and filling in dynamic parts
/// This template node is generic over the storage of the nodes to allow for owned and &'static versions. /// This template node is generic over the storage of the nodes to allow for owned and &'static versions.
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr( #[cfg_attr(
all(feature = "serialize", any(feature = "hot-reload", debug_assertions)), all(feature = "serialize", any(feature = "hot-reload", debug_assertions)),
derive(serde::Serialize, serde::Deserialize) derive(serde::Serialize, serde::Deserialize)
@@ -697,10 +694,9 @@ where
.set_text(scope_bump.alloc(new_text), self.id) .set_text(scope_bump.alloc(new_text), self.id)
} }
TemplateNodeType::DynamicNode(idx) => { TemplateNodeType::DynamicNode(idx) => {
drop(self);
// this will only be triggered for root elements // this will only be triggered for root elements
let created = let created =
diff_state.create_node(&template_ref.dynamic_context.resolve_node(*idx)); diff_state.create_node(template_ref.dynamic_context.resolve_node(*idx));
diff_state.mutations.replace_with(self.id, created as u32); diff_state.mutations.replace_with(self.id, created as u32);
} }
} }
@@ -710,7 +706,7 @@ where
} }
/// A template for an attribute /// A template for an attribute
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr( #[cfg_attr(
all(feature = "serialize", any(feature = "hot-reload", debug_assertions)), all(feature = "serialize", any(feature = "hot-reload", debug_assertions)),
derive(serde::Serialize, serde::Deserialize) derive(serde::Serialize, serde::Deserialize)
@@ -723,7 +719,7 @@ pub struct TemplateAttribute<V: TemplateValue> {
} }
/// A template attribute value that is either dynamic or static /// A template attribute value that is either dynamic or static
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr( #[cfg_attr(
all(feature = "serialize", any(feature = "hot-reload", debug_assertions)), all(feature = "serialize", any(feature = "hot-reload", debug_assertions)),
derive(serde::Serialize, serde::Deserialize) derive(serde::Serialize, serde::Deserialize)
@@ -744,9 +740,9 @@ pub trait TemplateValue {
impl TemplateValue for StaticAttributeValue { impl TemplateValue for StaticAttributeValue {
fn allocate<'b>(&self, bump: &'b Bump) -> AttributeValue<'b> { fn allocate<'b>(&self, bump: &'b Bump) -> AttributeValue<'b> {
match self.clone() { match self.clone() {
StaticAttributeValue::Text(txt) => AttributeValue::Text(bump.alloc_str(&txt)), StaticAttributeValue::Text(txt) => AttributeValue::Text(bump.alloc_str(txt)),
StaticAttributeValue::Bytes(bytes) => { StaticAttributeValue::Bytes(bytes) => {
AttributeValue::Bytes(bump.alloc_slice_copy(&bytes)) AttributeValue::Bytes(bump.alloc_slice_copy(bytes))
} }
StaticAttributeValue::Float32(f) => AttributeValue::Float32(f), StaticAttributeValue::Float32(f) => AttributeValue::Float32(f),
StaticAttributeValue::Float64(f) => AttributeValue::Float64(f), StaticAttributeValue::Float64(f) => AttributeValue::Float64(f),
@@ -799,7 +795,7 @@ impl TemplateValue for OwnedAttributeValue {
} }
/// The kind of node the template is. /// The kind of node the template is.
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr( #[cfg_attr(
all(feature = "serialize", any(feature = "hot-reload", debug_assertions)), all(feature = "serialize", any(feature = "hot-reload", debug_assertions)),
derive(serde::Serialize, serde::Deserialize) derive(serde::Serialize, serde::Deserialize)
@@ -867,7 +863,7 @@ where
type StaticStr = &'static str; type StaticStr = &'static str;
/// A element template /// A element template
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr( #[cfg_attr(
all(feature = "serialize", any(feature = "hot-reload", debug_assertions)), all(feature = "serialize", any(feature = "hot-reload", debug_assertions)),
derive(serde::Serialize, serde::Deserialize) derive(serde::Serialize, serde::Deserialize)
@@ -931,7 +927,7 @@ where
} }
/// A template for some text that may contain dynamic segments for example "Hello {name}" contains the static segment "Hello " and the dynamic segment "{name}". /// A template for some text that may contain dynamic segments for example "Hello {name}" contains the static segment "Hello " and the dynamic segment "{name}".
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr( #[cfg_attr(
all(feature = "serialize", any(feature = "hot-reload", debug_assertions)), all(feature = "serialize", any(feature = "hot-reload", debug_assertions)),
derive(serde::Serialize, serde::Deserialize) derive(serde::Serialize, serde::Deserialize)
@@ -961,7 +957,7 @@ where
} }
/// A segment of a text template that may be dynamic or static. /// A segment of a text template that may be dynamic or static.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr( #[cfg_attr(
all(feature = "serialize", any(feature = "hot-reload", debug_assertions)), all(feature = "serialize", any(feature = "hot-reload", debug_assertions)),
derive(serde::Serialize, serde::Deserialize) derive(serde::Serialize, serde::Deserialize)
@@ -1019,11 +1015,7 @@ impl TemplateResolver {
} }
pub fn is_dirty(&self, id: &TemplateId) -> bool { pub fn is_dirty(&self, id: &TemplateId) -> bool {
if let Some((_, true)) = self.template_id_mapping.get(id) { matches!(self.template_id_mapping.get(id), Some((_, true)))
true
} else {
false
}
} }
// returns (id, if the id was created) // returns (id, if the id was created)
+1 -1
View File
@@ -727,7 +727,7 @@ impl VirtualDom {
.borrow() .borrow()
.get(id) .get(id)
.map(|inner| { .map(|inner| {
let borrow = &*inner; let borrow = inner;
f(&borrow.borrow()) f(&borrow.borrow())
}) })
.unwrap() .unwrap()
+1 -1
View File
@@ -189,7 +189,7 @@ pub(super) fn handler(
MaximizeToggle => window.set_maximized(!window.is_maximized()), MaximizeToggle => window.set_maximized(!window.is_maximized()),
Fullscreen(state) => { Fullscreen(state) => {
if let Some(handle) = window.current_monitor() { if let Some(handle) = window.current_monitor() {
window.set_fullscreen(state.then(|| WryFullscreen::Borderless(Some(handle)))); window.set_fullscreen(state.then_some(WryFullscreen::Borderless(Some(handle))));
} }
} }
FocusWindow => window.set_focus(), FocusWindow => window.set_focus(),
+1 -1
View File
@@ -113,7 +113,7 @@ fn get_mime_from_path(trimmed: &str) -> Result<&str> {
return Ok("image/svg+xml"); return Ok("image/svg+xml");
} }
let res = match infer::get_from_path(&trimmed)?.map(|f| f.mime_type()) { let res = match infer::get_from_path(trimmed)?.map(|f| f.mime_type()) {
Some(t) if t == "text/plain" => get_mime_by_ext(trimmed), Some(t) if t == "text/plain" => get_mime_by_ext(trimmed),
Some(f) => f, Some(f) => f,
None => get_mime_by_ext(trimmed), None => get_mime_by_ext(trimmed),
@@ -146,7 +146,7 @@ impl NodeDepState<()> for NodeStateTester {
iter.map(|a| { iter.map(|a| {
( (
a.attribute.name.to_string(), a.attribute.name.to_string(),
format!("{}", a.value.as_text().unwrap()), a.value.as_text().unwrap().to_string(),
) )
}) })
.collect() .collect()
+4 -4
View File
@@ -30,7 +30,7 @@ impl<'a> NodeView<'a> {
pub fn tag(&self) -> Option<&'a str> { pub fn tag(&self) -> Option<&'a str> {
self.mask self.mask
.tag .tag
.then(|| match &self.inner.node_type { .then_some(match &self.inner.node_type {
NodeType::Element { tag, .. } => Some(&**tag), NodeType::Element { tag, .. } => Some(&**tag),
_ => None, _ => None,
}) })
@@ -41,8 +41,8 @@ impl<'a> NodeView<'a> {
pub fn namespace(&self) -> Option<&'a str> { pub fn namespace(&self) -> Option<&'a str> {
self.mask self.mask
.namespace .namespace
.then(|| match &self.inner.node_type { .then_some(match &self.inner.node_type {
NodeType::Element { namespace, .. } => namespace.map(|s| &*s), NodeType::Element { namespace, .. } => *namespace,
_ => None, _ => None,
}) })
.flatten() .flatten()
@@ -68,7 +68,7 @@ impl<'a> NodeView<'a> {
pub fn text(&self) -> Option<&str> { pub fn text(&self) -> Option<&str> {
self.mask self.mask
.text .text
.then(|| match &self.inner.node_type { .then_some(match &self.inner.node_type {
NodeType::Text { text } => Some(&**text), NodeType::Text { text } => Some(&**text),
_ => None, _ => None,
}) })
+15 -23
View File
@@ -449,11 +449,10 @@ impl<S: State> RealDom<S> {
} => self } => self
.nodes .nodes
.get(template_ref_id.0) .get(template_ref_id.0)
.map(|o| o.as_ref()) .and_then(|o| o.as_ref())
.flatten()
.and_then(|t| match &**t { .and_then(|t| match &**t {
TemplateRefOrNode::Ref { nodes, .. } => { TemplateRefOrNode::Ref { nodes, .. } => {
nodes.get(template_node_id.0).map(|o| o.as_ref()).flatten() nodes.get(template_node_id.0).and_then(|o| o.as_ref())
} }
TemplateRefOrNode::Node(_) => None, TemplateRefOrNode::Node(_) => None,
}) })
@@ -461,8 +460,7 @@ impl<S: State> RealDom<S> {
GlobalNodeId::VNodeId(n) => self GlobalNodeId::VNodeId(n) => self
.nodes .nodes
.get(n.0) .get(n.0)
.map(|o| o.as_ref()) .and_then(|o| o.as_ref())
.flatten()
.and_then(|n| match &**n { .and_then(|n| match &**n {
TemplateRefOrNode::Ref { .. } => None, TemplateRefOrNode::Ref { .. } => None,
TemplateRefOrNode::Node(_) => Some(n), TemplateRefOrNode::Node(_) => Some(n),
@@ -522,6 +520,7 @@ impl<S: State> RealDom<S> {
} }
let mut created = false; let mut created = false;
if let GlobalNodeId::VNodeId(id) = child_id { if let GlobalNodeId::VNodeId(id) = child_id {
#[allow(clippy::transmute_ptr_to_ref)]
let unbounded_self: &mut Self = unsafe { std::mem::transmute(&*self as *const Self) }; let unbounded_self: &mut Self = unsafe { std::mem::transmute(&*self as *const Self) };
if let TemplateRefOrNode::Ref { roots, .. } = &**self.nodes[id.0].as_mut()? { if let TemplateRefOrNode::Ref { roots, .. } = &**self.nodes[id.0].as_mut()? {
// this is safe because we know that no parent will be it's own child // this is safe because we know that no parent will be it's own child
@@ -569,8 +568,7 @@ impl<S: State> RealDom<S> {
}; };
nodes nodes
.get_mut(template_node_id.0) .get_mut(template_node_id.0)
.map(|n| n.as_mut()) .and_then(|n| n.as_mut())
.flatten()
.map(|n| n.as_mut()) .map(|n| n.as_mut())
.unwrap() .unwrap()
}; };
@@ -624,8 +622,7 @@ impl<S: State> RealDom<S> {
}; };
nodes nodes
.get_mut(template_node_id.0) .get_mut(template_node_id.0)
.map(|n| n.as_mut()) .and_then(|n| n.as_mut())
.flatten()
.map(|n| n.as_mut()) .map(|n| n.as_mut())
.unwrap() .unwrap()
}; };
@@ -764,7 +761,7 @@ impl<S: State> RealDom<S> {
&& self[GlobalNodeId::VNodeId(c.mounted_id())] && self[GlobalNodeId::VNodeId(c.mounted_id())]
.node_data .node_data
.parent .parent
== e.id.get().map(|id| GlobalNodeId::VNodeId(id)) == e.id.get().map(GlobalNodeId::VNodeId)
}) })
&& attributes && attributes
.iter() .iter()
@@ -880,11 +877,11 @@ impl<S: State> RealDom<S> {
} }
} }
pub fn split<'a>( pub fn split(
&'a mut self, &mut self,
) -> ( ) -> (
impl Traversable<Id = GlobalNodeId, Node = S> + 'a, impl Traversable<Id = GlobalNodeId, Node = S> + '_,
impl Traversable<Id = GlobalNodeId, Node = NodeData> + 'a, impl Traversable<Id = GlobalNodeId, Node = NodeData> + '_,
) { ) {
let raw = self as *mut Self; let raw = self as *mut Self;
// this is safe beacuse the traversable trait does not allow mutation of the position of elements, and within elements the access is disjoint. // this is safe beacuse the traversable trait does not allow mutation of the position of elements, and within elements the access is disjoint.
@@ -1055,8 +1052,7 @@ impl<T: State> Traversable for RealDom<T> {
nodes nodes
.get(template_node_id.0) .get(template_node_id.0)
.map(|n| n.as_ref()) .and_then(|n| n.as_ref())
.flatten()
.map(|n| n.as_ref()) .map(|n| n.as_ref())
} }
} }
@@ -1086,8 +1082,7 @@ impl<T: State> Traversable for RealDom<T> {
nodes nodes
.get_mut(template_node_id.0) .get_mut(template_node_id.0)
.map(|n| n.as_mut()) .and_then(|n| n.as_mut())
.flatten()
.map(|n| n.as_mut()) .map(|n| n.as_mut())
} }
} }
@@ -1097,7 +1092,7 @@ impl<T: State> Traversable for RealDom<T> {
fn children(&self, id: Self::Id) -> &[Self::Id] { fn children(&self, id: Self::Id) -> &[Self::Id] {
if let Some(node) = <Self as Traversable>::get(self, id) { if let Some(node) = <Self as Traversable>::get(self, id) {
match &node.node_data.node_type { match &node.node_data.node_type {
NodeType::Element { children, .. } => &children, NodeType::Element { children, .. } => children,
_ => &[], _ => &[],
} }
} else { } else {
@@ -1123,10 +1118,7 @@ impl<T: State> Traversable for RealDom<T> {
TemplateRefOrNode::Node(_) => panic!("Expected template ref"), TemplateRefOrNode::Node(_) => panic!("Expected template ref"),
}; };
nodes nodes.get(template_node_id.0).and_then(|n| n.as_deref())
.get(template_node_id.0)
.map(|n| n.as_deref())
.flatten()
}? }?
.node_data .node_data
.parent .parent
+3 -5
View File
@@ -242,11 +242,9 @@ impl Parse for ComponentField {
let forked = input.fork(); let forked = input.fork();
let t: LitStr = forked.parse()?; let t: LitStr = forked.parse()?;
// the string literal must either be the end of the input or a followed by a comma // the string literal must either be the end of the input or a followed by a comma
if forked.is_empty() || forked.peek(Token![,]) { if (forked.is_empty() || forked.peek(Token![,])) && is_literal_foramtted(&t) {
if is_literal_foramtted(&t) { let content = ContentField::Formatted(input.parse()?);
let content = ContentField::Formatted(input.parse()?); return Ok(Self { name, content });
return Ok(Self { name, content });
}
} }
} }
+3 -1
View File
@@ -66,8 +66,10 @@ macro_rules! builder_constructors {
}; };
} }
type MappedAttributes = &'static [(&'static str, &'static [(&'static str, &'static str, bool)])];
/// All attributes that are tied to a specific element that either have a different name, or are volitile /// All attributes that are tied to a specific element that either have a different name, or are volitile
pub const ELEMENTS_WITH_MAPPED_ATTRIBUTES: &[(&str, &[(&str, &str, bool)])] = &[ pub const ELEMENTS_WITH_MAPPED_ATTRIBUTES: MappedAttributes = &[
( (
"script", "script",
&[("r#type", "type", false), ("r#script", "script", false)], &[("r#type", "type", false), ("r#script", "script", false)],
+5 -5
View File
@@ -12,11 +12,11 @@ pub enum Error {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub enum RecompileReason { pub enum RecompileReason {
CapturedVariable(String), Variable(String),
CapturedExpression(String), Expression(String),
CapturedComponent(String), Component(String),
CapturedListener(String), Listener(String),
CapturedAttribute(String), Attribute(String),
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
+59 -89
View File
@@ -21,7 +21,7 @@ pub fn try_parse_template(
template_builder = template_builder template_builder = template_builder
.try_switch_dynamic_context(prev) .try_switch_dynamic_context(prev)
.ok_or_else(|| { .ok_or_else(|| {
Error::RecompileRequiredError(RecompileReason::CapturedVariable( Error::RecompileRequiredError(RecompileReason::Variable(
"dynamic context updated".to_string(), "dynamic context updated".to_string(),
)) ))
})?; })?;
@@ -57,20 +57,17 @@ struct TemplateElementBuilder {
parent: Option<TemplateNodeId>, parent: Option<TemplateNodeId>,
} }
#[cfg(any(feature = "hot-reload", debug_assertions))]
type OwndedTemplateElement = TemplateElement<
Vec<TemplateAttribute<OwnedAttributeValue>>,
OwnedAttributeValue,
Vec<TemplateNodeId>,
Vec<usize>,
>;
impl TemplateElementBuilder { impl TemplateElementBuilder {
#[cfg(any(feature = "hot-reload", debug_assertions))] #[cfg(any(feature = "hot-reload", debug_assertions))]
fn try_into_owned( fn try_into_owned(self, location: &OwnedCodeLocation) -> Result<OwndedTemplateElement, Error> {
self,
location: &OwnedCodeLocation,
) -> Result<
TemplateElement<
Vec<TemplateAttribute<OwnedAttributeValue>>,
OwnedAttributeValue,
Vec<TemplateNodeId>,
Vec<usize>,
>,
Error,
> {
let Self { let Self {
tag, tag,
attributes, attributes,
@@ -163,9 +160,7 @@ impl TemplateAttributeBuilder {
.ok_or_else(|| { .ok_or_else(|| {
if literal { if literal {
// literals will be captured when a full recompile is triggered // literals will be captured when a full recompile is triggered
Error::RecompileRequiredError(RecompileReason::CapturedAttribute( Error::RecompileRequiredError(RecompileReason::Attribute(name.to_string()))
name.to_string(),
))
} else { } else {
Error::ParseError(ParseError::new( Error::ParseError(ParseError::new(
syn::Error::new(span, format!("unknown attribute: {}", name)), syn::Error::new(span, format!("unknown attribute: {}", name)),
@@ -253,22 +248,19 @@ enum TemplateNodeTypeBuilder {
DynamicNode(usize), DynamicNode(usize),
} }
#[cfg(any(feature = "hot-reload", debug_assertions))]
type OwnedTemplateNodeType = TemplateNodeType<
Vec<TemplateAttribute<OwnedAttributeValue>>,
OwnedAttributeValue,
Vec<TemplateNodeId>,
Vec<usize>,
Vec<TextTemplateSegment<String>>,
String,
>;
impl TemplateNodeTypeBuilder { impl TemplateNodeTypeBuilder {
#[cfg(any(feature = "hot-reload", debug_assertions))] #[cfg(any(feature = "hot-reload", debug_assertions))]
fn try_into_owned( fn try_into_owned(self, location: &OwnedCodeLocation) -> Result<OwnedTemplateNodeType, Error> {
self,
location: &OwnedCodeLocation,
) -> Result<
TemplateNodeType<
Vec<TemplateAttribute<OwnedAttributeValue>>,
OwnedAttributeValue,
Vec<TemplateNodeId>,
Vec<usize>,
Vec<TextTemplateSegment<String>>,
String,
>,
Error,
> {
match self { match self {
TemplateNodeTypeBuilder::Element(el) => { TemplateNodeTypeBuilder::Element(el) => {
Ok(TemplateNodeType::Element(el.try_into_owned(location)?)) Ok(TemplateNodeType::Element(el.try_into_owned(location)?))
@@ -382,13 +374,11 @@ impl TemplateBuilder {
} }
// only build a template if there is at least one static node // only build a template if there is at least one static node
if builder.nodes.iter().all(|r| { if builder
if let TemplateNodeTypeBuilder::DynamicNode(_) = &r.node_type { .nodes
true .iter()
} else { .all(|r| matches!(&r.node_type, TemplateNodeTypeBuilder::DynamicNode(_)))
false {
}
}) {
None None
} else { } else {
Some(builder) Some(builder)
@@ -649,50 +639,40 @@ impl TemplateBuilder {
let mut node_mapping = vec![None; dynamic_context.nodes.len()]; let mut node_mapping = vec![None; dynamic_context.nodes.len()];
let nodes = &self.nodes; let nodes = &self.nodes;
for n in nodes { for n in nodes {
match &n.node_type { if let TemplateNodeTypeBuilder::DynamicNode(idx) = &n.node_type {
TemplateNodeTypeBuilder::DynamicNode(idx) => node_mapping[*idx] = Some(n.id), node_mapping[*idx] = Some(n.id)
_ => (),
} }
} }
let mut text_mapping = vec![Vec::new(); dynamic_context.text.len()]; let mut text_mapping = vec![Vec::new(); dynamic_context.text.len()];
for n in nodes { for n in nodes {
match &n.node_type { if let TemplateNodeTypeBuilder::Text(txt) = &n.node_type {
TemplateNodeTypeBuilder::Text(txt) => { for seg in &txt.segments {
for seg in &txt.segments { match seg {
match seg { TextTemplateSegment::Static(_) => (),
TextTemplateSegment::Static(_) => (), TextTemplateSegment::Dynamic(idx) => text_mapping[*idx].push(n.id),
TextTemplateSegment::Dynamic(idx) => text_mapping[*idx].push(n.id),
}
} }
} }
_ => (),
} }
} }
let mut attribute_mapping = vec![Vec::new(); dynamic_context.attributes.len()]; let mut attribute_mapping = vec![Vec::new(); dynamic_context.attributes.len()];
for n in nodes { for n in nodes {
match &n.node_type { if let TemplateNodeTypeBuilder::Element(el) = &n.node_type {
TemplateNodeTypeBuilder::Element(el) => { for (i, attr) in el.attributes.iter().enumerate() {
for (i, attr) in el.attributes.iter().enumerate() { match attr.value {
match attr.value { TemplateAttributeValue::Static(_) => (),
TemplateAttributeValue::Static(_) => (), TemplateAttributeValue::Dynamic(idx) => {
TemplateAttributeValue::Dynamic(idx) => { attribute_mapping[idx].push((n.id, i));
attribute_mapping[idx].push((n.id, i));
}
} }
} }
} }
_ => (),
} }
} }
let mut listener_mapping = Vec::new(); let mut listener_mapping = Vec::new();
for n in nodes { for n in nodes {
match &n.node_type { if let TemplateNodeTypeBuilder::Element(el) = &n.node_type {
TemplateNodeTypeBuilder::Element(el) => { if !el.listeners.is_empty() {
if !el.listeners.is_empty() { listener_mapping.push(n.id);
listener_mapping.push(n.id);
}
} }
_ => (),
} }
} }
@@ -727,50 +707,40 @@ impl ToTokens for TemplateBuilder {
let mut node_mapping = vec![None; dynamic_context.nodes.len()]; let mut node_mapping = vec![None; dynamic_context.nodes.len()];
for n in nodes { for n in nodes {
match &n.node_type { if let TemplateNodeTypeBuilder::DynamicNode(idx) = &n.node_type {
TemplateNodeTypeBuilder::DynamicNode(idx) => node_mapping[*idx] = Some(n.id), node_mapping[*idx] = Some(n.id);
_ => (),
} }
} }
let mut text_mapping = vec![Vec::new(); dynamic_context.text.len()]; let mut text_mapping = vec![Vec::new(); dynamic_context.text.len()];
for n in nodes { for n in nodes {
match &n.node_type { if let TemplateNodeTypeBuilder::Text(txt) = &n.node_type {
TemplateNodeTypeBuilder::Text(txt) => { for seg in &txt.segments {
for seg in &txt.segments { match seg {
match seg { TextTemplateSegment::Static(_) => (),
TextTemplateSegment::Static(_) => (), TextTemplateSegment::Dynamic(idx) => text_mapping[*idx].push(n.id),
TextTemplateSegment::Dynamic(idx) => text_mapping[*idx].push(n.id),
}
} }
} }
_ => (),
} }
} }
let mut attribute_mapping = vec![Vec::new(); dynamic_context.attributes.len()]; let mut attribute_mapping = vec![Vec::new(); dynamic_context.attributes.len()];
for n in nodes { for n in nodes {
match &n.node_type { if let TemplateNodeTypeBuilder::Element(el) = &n.node_type {
TemplateNodeTypeBuilder::Element(el) => { for (i, attr) in el.attributes.iter().enumerate() {
for (i, attr) in el.attributes.iter().enumerate() { match attr.value {
match attr.value { TemplateAttributeValue::Static(_) => (),
TemplateAttributeValue::Static(_) => (), TemplateAttributeValue::Dynamic(idx) => {
TemplateAttributeValue::Dynamic(idx) => { attribute_mapping[idx].push((n.id, i));
attribute_mapping[idx].push((n.id, i));
}
} }
} }
} }
_ => (),
} }
} }
let mut listener_mapping = Vec::new(); let mut listener_mapping = Vec::new();
for n in nodes { for n in nodes {
match &n.node_type { if let TemplateNodeTypeBuilder::Element(el) = &n.node_type {
TemplateNodeTypeBuilder::Element(el) => { if !el.listeners.is_empty() {
if !el.listeners.is_empty() { listener_mapping.push(n.id);
listener_mapping.push(n.id);
}
} }
_ => (),
} }
} }
+33 -72
View File
@@ -69,7 +69,6 @@ pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String {
}; };
let r = ssr_renderer.to_string(); let r = ssr_renderer.to_string();
drop(ssr_renderer); drop(ssr_renderer);
drop(vdom);
r r
} }
@@ -247,7 +246,6 @@ impl<'a: 'c, 'c> TextRenderer<'a, '_, 'c> {
&s.nodes, &s.nodes,
&s.nodes[r.0], &s.nodes[r.0],
dynamic_context, dynamic_context,
&s.dynamic_mapping,
f, f,
last_node_was_text, last_node_was_text,
il, il,
@@ -260,7 +258,6 @@ impl<'a: 'c, 'c> TextRenderer<'a, '_, 'c> {
&o.nodes, &o.nodes,
&o.nodes[r.0], &o.nodes[r.0],
dynamic_context, dynamic_context,
&o.dynamic_mapping,
f, f,
last_node_was_text, last_node_was_text,
il, il,
@@ -278,35 +275,11 @@ impl<'a: 'c, 'c> TextRenderer<'a, '_, 'c> {
Ok(()) Ok(())
} }
fn render_template_node< fn render_template_node<TemplateNodes, Attributes, V, Children, Listeners, TextSegments, Text>(
TemplateNodes,
Attributes,
V,
Children,
Listeners,
TextSegments,
Text,
Nodes,
TextOuter,
TextInner,
AttributesOuter,
AttributesInner,
Volatile,
Listeners2,
>(
&self, &self,
template_nodes: &TemplateNodes, template_nodes: &TemplateNodes,
node: &TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>, node: &TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>,
dynamic_context: &TemplateContext, dynamic_context: &TemplateContext,
dynamic_node_mapping: &DynamicNodeMapping<
Nodes,
TextOuter,
TextInner,
AttributesOuter,
AttributesInner,
Volatile,
Listeners2,
>,
f: &mut impl Write, f: &mut impl Write,
last_node_was_text: &mut bool, last_node_was_text: &mut bool,
il: u16, il: u16,
@@ -315,18 +288,11 @@ impl<'a: 'c, 'c> TextRenderer<'a, '_, 'c> {
TemplateNodes: TemplateNodes:
AsRef<[TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>]>, AsRef<[TemplateNode<Attributes, V, Children, Listeners, TextSegments, Text>]>,
Attributes: AsRef<[TemplateAttribute<V>]>, Attributes: AsRef<[TemplateAttribute<V>]>,
AttributesInner: AsRef<[(TemplateNodeId, usize)]>,
AttributesOuter: AsRef<[AttributesInner]>,
Children: AsRef<[TemplateNodeId]>, Children: AsRef<[TemplateNodeId]>,
Listeners: AsRef<[usize]>, Listeners: AsRef<[usize]>,
Listeners2: AsRef<[TemplateNodeId]>,
Nodes: AsRef<[Option<TemplateNodeId>]>,
Text: AsRef<str>, Text: AsRef<str>,
TextInner: AsRef<[TemplateNodeId]>,
TextOuter: AsRef<[TextInner]>,
TextSegments: AsRef<[TextTemplateSegment<Text>]>, TextSegments: AsRef<[TextTemplateSegment<Text>]>,
V: TemplateValue, V: TemplateValue,
Volatile: AsRef<[(TemplateNodeId, usize)]>,
{ {
match &node.node_type { match &node.node_type {
TemplateNodeType::Element(el) => { TemplateNodeType::Element(el) => {
@@ -342,7 +308,7 @@ impl<'a: 'c, 'c> TextRenderer<'a, '_, 'c> {
let mut inner_html = None; let mut inner_html = None;
let mut attr_iter = el.attributes.as_ref().into_iter().peekable(); let mut attr_iter = el.attributes.as_ref().iter().peekable();
while let Some(attr) = attr_iter.next() { while let Some(attr) = attr_iter.next() {
match attr.attribute.namespace { match attr.attribute.namespace {
@@ -433,7 +399,6 @@ impl<'a: 'c, 'c> TextRenderer<'a, '_, 'c> {
template_nodes, template_nodes,
&template_nodes.as_ref()[child.0], &template_nodes.as_ref()[child.0],
dynamic_context, dynamic_context,
dynamic_node_mapping,
f, f,
&mut last_node_was_text, &mut last_node_was_text,
il + 1, il + 1,
@@ -497,10 +462,8 @@ where
if attr.attribute.name == "dangerous_inner_html" { if attr.attribute.name == "dangerous_inner_html" {
inner_html = Some(attr.value.as_text().unwrap()) inner_html = Some(attr.value.as_text().unwrap())
} else { } else {
if is_boolean_attribute(attr.attribute.name) { if is_boolean_attribute(attr.attribute.name) && !attr.value.is_truthy() {
if !attr.value.is_truthy() { continue;
continue;
}
} }
write!(f, " {}=\"{}\"", attr.attribute.name, attr.value)? write!(f, " {}=\"{}\"", attr.attribute.name, attr.value)?
} }
@@ -527,37 +490,35 @@ where
} }
fn is_boolean_attribute(attribute: &'static str) -> bool { fn is_boolean_attribute(attribute: &'static str) -> bool {
if let "allowfullscreen" matches!(
| "allowpaymentrequest" attribute,
| "async" "allowfullscreen"
| "autofocus" | "allowpaymentrequest"
| "autoplay" | "async"
| "checked" | "autofocus"
| "controls" | "autoplay"
| "default" | "checked"
| "defer" | "controls"
| "disabled" | "default"
| "formnovalidate" | "defer"
| "hidden" | "disabled"
| "ismap" | "formnovalidate"
| "itemscope" | "hidden"
| "loop" | "ismap"
| "multiple" | "itemscope"
| "muted" | "loop"
| "nomodule" | "multiple"
| "novalidate" | "muted"
| "open" | "nomodule"
| "playsinline" | "novalidate"
| "readonly" | "open"
| "required" | "playsinline"
| "reversed" | "readonly"
| "selected" | "required"
| "truespeed" = attribute | "reversed"
{ | "selected"
true | "truespeed"
} else { )
false
}
} }
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
+1 -1
View File
@@ -93,7 +93,7 @@ impl NodeDepState<()> for Focus {
.map(|mut listeners| { .map(|mut listeners| {
listeners listeners
.any(|l| FOCUS_EVENTS.binary_search(&l).is_ok()) .any(|l| FOCUS_EVENTS.binary_search(&l).is_ok())
.then(|| ()) .then_some(())
}) })
.is_some() .is_some()
{ {
+1 -1
View File
@@ -94,7 +94,7 @@ impl ChildDepState for TaffyLayout {
.binary_search(&attribute.name.as_ref()) .binary_search(&attribute.name.as_ref())
.is_ok()); .is_ok());
if let Some(text) = value.as_text() { if let Some(text) = value.as_text() {
apply_layout_attributes(&&attribute.name, text, &mut style); apply_layout_attributes(&attribute.name, text, &mut style);
} }
} }
} }
+2 -2
View File
@@ -230,7 +230,7 @@ fn virtual_event_from_websys_event(
// todo: these handlers might get really slow if the input box gets large and allocation pressure is heavy // todo: these handlers might get really slow if the input box gets large and allocation pressure is heavy
// don't have a good solution with the serialized event problem // don't have a good solution with the serialized event problem
"change" | "input" | "invalid" | "reset" | "submit" => { "change" | "input" | "invalid" | "reset" | "submit" => {
let value: String = (&target) let value: String = target
.dyn_ref() .dyn_ref()
.map(|input: &web_sys::HtmlInputElement| { .map(|input: &web_sys::HtmlInputElement| {
// todo: special case more input types // todo: special case more input types
@@ -273,7 +273,7 @@ fn virtual_event_from_websys_event(
for x in 0..elements.length() { for x in 0..elements.length() {
let element = elements.item(x).unwrap(); let element = elements.item(x).unwrap();
if let Some(name) = element.get_attribute("name") { if let Some(name) = element.get_attribute("name") {
let value: Option<String> = (&element) let value: Option<String> = element
.dyn_ref() .dyn_ref()
.map(|input: &web_sys::HtmlInputElement| { .map(|input: &web_sys::HtmlInputElement| {
match input.type_().as_str() { match input.type_().as_str() {