Skip to content

Commit

Permalink
please the new rust
Browse files Browse the repository at this point in the history
  • Loading branch information
aclueless committed Sep 10, 2024
1 parent e712ec9 commit 739ebd0
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 54 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ nightly-text-render = []
[workspace]
members = [
"examples/*",
"crates/*"
]

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/component/child_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<C: Component> ChildComp<C> {

let ws_node = instance.root_element.ws_element().ws_node().clone();
Some(Box::new(CompRef {
comp: comp.into(),
_comp: comp.into(),
ws_node,
}))
}
Expand Down
47 changes: 22 additions & 25 deletions src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,118 +362,115 @@ impl<C: Component> Comp<C> {
}
}

fn cb<Cl: 'static>(&self, f: impl Fn(&C) -> Cl + 'static) -> crate::callback::CallbackFn<C, ()>
fn cb<Cl>(&self, f: impl Fn(&C) -> Cl + 'static) -> crate::callback::CallbackFn<C, ()>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
crate::callback::CallbackFn {
comp: self.clone(),
callback: Rc::new(crate::callback::Cb(f)),
}
}

fn cb_mut<Cl: 'static>(
&self,
f: impl Fn(&mut C) -> Cl + 'static,
) -> crate::callback::CallbackFn<C, ()>
fn cb_mut<Cl>(&self, f: impl Fn(&mut C) -> Cl + 'static) -> crate::callback::CallbackFn<C, ()>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
crate::callback::CallbackFn {
comp: self.clone(),
callback: Rc::new(crate::callback::CbMut(f)),
}
}

fn cb_dropped_arg<Cl: 'static, A>(
fn cb_dropped_arg<Cl, A>(
&self,
f: impl Fn(&C) -> Cl + 'static,
) -> crate::callback::CallbackFn<C, A>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
crate::callback::CallbackFn {
comp: self.clone(),
callback: Rc::new(crate::callback::CbDroppedArg(f)),
}
}

fn cb_dropped_arg_mut<Cl: 'static, A>(
fn cb_dropped_arg_mut<Cl, A>(
&self,
f: impl Fn(&mut C) -> Cl + 'static,
) -> crate::callback::CallbackFn<C, A>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
crate::callback::CallbackFn {
comp: self.clone(),
callback: Rc::new(crate::callback::CbDroppedArgMut(f)),
}
}

fn cb_arg_mut<Cl: 'static, A>(
fn cb_arg_mut<Cl, A>(
&self,
f: impl Fn(&mut C, A) -> Cl + 'static,
) -> crate::callback::CallbackFn<C, A>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
crate::callback::CallbackFn {
comp: self.clone(),
callback: Rc::new(crate::callback::CbArgMut(f)),
}
}

pub fn callback<Cl: 'static>(&self, f: impl Fn(&C) -> Cl + 'static) -> crate::Callback
pub fn callback<Cl>(&self, f: impl Fn(&C) -> Cl + 'static) -> crate::Callback
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
Box::new(self.cb(f))
}

pub fn callback_mut<Cl: 'static>(&self, f: impl Fn(&mut C) -> Cl + 'static) -> crate::Callback
pub fn callback_mut<Cl>(&self, f: impl Fn(&mut C) -> Cl + 'static) -> crate::Callback
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
Box::new(self.cb_mut(f))
}

pub fn callback_arg_mut<Cl: 'static, A: 'static>(
pub fn callback_arg_mut<Cl, A: 'static>(
&self,
f: impl Fn(&mut C, A) -> Cl + 'static,
) -> crate::CallbackArg<A>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
Box::new(self.cb_arg_mut(f))
}

pub fn handler<Cl: 'static, A: 'static>(
pub fn handler<Cl, A: 'static>(
&self,
f: impl Fn(&C) -> Cl + 'static,
) -> impl crate::callback::CallbackArg<A>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
self.cb_dropped_arg(f)
}

pub fn handler_mut<Cl: 'static, A: 'static>(
pub fn handler_mut<Cl, A: 'static>(
&self,
f: impl Fn(&mut C) -> Cl + 'static,
) -> impl crate::callback::CallbackArg<A>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
self.cb_dropped_arg_mut(f)
}

pub fn handler_arg_mut<Cl: 'static, A: 'static>(
pub fn handler_arg_mut<Cl, A: 'static>(
&self,
f: impl Fn(&mut C, A) -> Cl + 'static,
) -> impl crate::callback::CallbackArg<A>
where
Cl: Into<Checklist<C>>,
Cl: 'static + Into<Checklist<C>>,
{
self.cb_arg_mut(f)
}
Expand Down
16 changes: 8 additions & 8 deletions src/dom/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum Node {
RefComponent(RefComponentNode),
OwnedComponent(OwnedComponent),
#[cfg(feature = "queue-render")]
QrNode(QrNode),
Qr(QrNode),
}

impl std::fmt::Debug for Node {
Expand All @@ -35,14 +35,14 @@ impl std::fmt::Debug for Node {
Self::RefComponent(_) => "Node::RefComponent2",
Self::OwnedComponent(_) => "Node::OwnedComponent",
#[cfg(feature = "queue-render")]
Self::QrNode(_) => "Node::QrNode",
Self::Qr(_) => "Node::QrNode",
};
f.write_fmt(format_args!("[{name}]"))
}
}

pub struct CompRef<C: Component> {
pub comp: ComponentHandle<C>,
pub _comp: ComponentHandle<C>,
pub ws_node: web_sys::Node,
}

Expand Down Expand Up @@ -205,7 +205,7 @@ impl Node {
}
}
#[cfg(feature = "queue-render")]
Self::QrNode(qr) => qr.remove_from(parent),
Self::Qr(qr) => qr.remove_from(parent),
}
}

Expand All @@ -224,7 +224,7 @@ impl Node {
}
}
#[cfg(feature = "queue-render")]
Self::QrNode(qr) => qr.append_to(parent),
Self::Qr(qr) => qr.append_to(parent),
}
}

Expand All @@ -239,7 +239,7 @@ impl Node {
Self::RefComponent(_) => None,
Self::OwnedComponent(_) => None,
#[cfg(feature = "queue-render")]
Self::QrNode(qr) => qr.get_first_element(),
Self::Qr(qr) => qr.get_first_element(),
}
}

Expand All @@ -254,7 +254,7 @@ impl Node {
Self::RefComponent(_) => None,
Self::OwnedComponent(_) => None,
#[cfg(feature = "queue-render")]
Self::QrNode(qr) => qr.get_last_element(),
Self::Qr(qr) => qr.get_last_element(),
}
}

Expand All @@ -277,7 +277,7 @@ impl Node {
}
}
#[cfg(feature = "queue-render")]
Self::QrNode(qr) => qr.insert_before_a_sibling(parent, next_sibling),
Self::Qr(qr) => qr.insert_before_a_sibling(parent, next_sibling),
}
}
}
4 changes: 2 additions & 2 deletions src/dom/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl Nodes {

#[cfg(feature = "queue-render")]
pub fn add_qr_node(&mut self, qr: QrNode) {
self.0.push(Node::QrNode(qr));
self.0.push(Node::Qr(qr));
}

#[cfg(feature = "queue-render")]
Expand All @@ -345,7 +345,7 @@ impl Nodes {
.get_mut(index)
.expect_throw("dom::nodes::Nodes::get_qr_node get_mut")
{
Node::QrNode(qr) => qr,
Node::Qr(qr) => qr,
_ => panic!("dom::nodes::Nodes::get_qr_node expected Node::QrNode"),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/element.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use wasm_bindgen::JsCast;

pub struct EventTarget(pub(crate) Option<web_sys::EventTarget>);
pub struct InputElement(pub(crate) web_sys::HtmlInputElement);
pub struct SelectElement(pub(crate) web_sys::HtmlSelectElement);
pub struct FormElement(pub(crate) web_sys::HtmlFormElement);
// pub struct InputElement(pub(crate) web_sys::HtmlInputElement);
// pub struct SelectElement(pub(crate) web_sys::HtmlSelectElement);
// pub struct FormElement(pub(crate) web_sys::HtmlFormElement);

duplicate::duplicate! {
[
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ pub mod prelude {

#[cfg(feature = "queue-render")]
pub use crate::queue_render::html::HemsForQrList;
#[cfg(all(feature = "queue-render", feature = "svg"))]
pub use crate::queue_render::svg::SemsForQrList;

#[cfg(feature = "keyed-list")]
pub use crate::render::html::HemsForKeyedList;

#[cfg(feature = "svg")]
pub use crate::render::svg::{
MethodsForSvgElementContent, SamsForDistinctNames, SamsHandMade, SemsForDistinctNames,
SemsForList, SemsForPartialList, SemsHandMade,
MethodsForSvgElementContent, SamsForAmbiguousNames, SamsForDistinctNames, SamsHandMade,
SemsForDistinctNames, SemsForList, SemsForPartialList, SemsHandMade, SemsSamsAmbiguous,
};

#[cfg(all(feature = "keyed-list", feature = "svg"))]
Expand Down
2 changes: 0 additions & 2 deletions src/queue_render/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ mod nodes;
mod text;

pub use attribute::*;
pub use element::*;
pub use list::*;
pub use nodes::*;
1 change: 0 additions & 1 deletion src/queue_render/html/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod element;
mod list;

pub use element::*;
pub use list::*;
1 change: 1 addition & 0 deletions src/queue_render/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,6 @@ impl<T: 'static + PartialEq> QrVal<T> {

pub trait QueueRender<T> {
fn render(&mut self, t: &T);
#[allow(dead_code)]
fn unmounted(&self) -> bool;
}
1 change: 1 addition & 0 deletions src/queue_render/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::val::{QrVal, QueueRender};

pub trait ListRender<I: Clone> {
fn render(&mut self, items: &[I], diffs: Vec<Diff<I>>);
#[allow(dead_code)]
fn unmounted(&self) -> bool;
}

Expand Down
10 changes: 3 additions & 7 deletions src/render/base/keyed_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ where

pub fn update<I, K>(
&mut self,
entries_state_iter: impl Iterator<Item = I> + DoubleEndedIterator,
entries_state_iter: impl DoubleEndedIterator<Item = I>,
) -> super::RememberSettingSelectedOption
where
G: Fn(&I) -> &K,
Expand Down Expand Up @@ -235,9 +235,7 @@ where

fn update_same_key_entries_from_end<I, K>(
&mut self,
entries_state_iter: &mut PeekableDoubleEndedIterator<
impl Iterator<Item = I> + DoubleEndedIterator,
>,
entries_state_iter: &mut PeekableDoubleEndedIterator<impl DoubleEndedIterator<Item = I>>,
) -> usize
where
G: Fn(&I) -> &K,
Expand Down Expand Up @@ -328,9 +326,7 @@ where

fn update_moved_backward_entry<I, K>(
&mut self,
entries_state_iter: &mut PeekableDoubleEndedIterator<
impl Iterator<Item = I> + DoubleEndedIterator,
>,
entries_state_iter: &mut PeekableDoubleEndedIterator<impl DoubleEndedIterator<Item = I>>,
) -> usize
where
G: Fn(&I) -> &K,
Expand Down
7 changes: 7 additions & 0 deletions src/render/macros/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ macro_rules! make_trait_for_attributes_with_predefined_values {
}

pub trait $AttributeValueTrait<C: Component> {
// This "allow(dead_code)" is just to hide the warnings.
// The reason is I want the current code to pass the test, but I don't have time to
// look up why this is not use?
// At the time of adding this, I plan to do some experiments of some newish ideas for
// spair. If the experiments succeed, the current code may end up being removed entirely
// from spair. Ortherwise, this "allow(dead_code)" must have some investigations!!!
#[allow(dead_code)]
fn render(self, attribute_name: &str, element: &mut crate::render::base::ElementUpdater<C>);
}

Expand Down
6 changes: 3 additions & 3 deletions src/render/svg/attributes_elements_with_ambiguous_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ make_trait_for_same_name_attribute_and_element_methods! {
ambiguous_attributes:
// The names are also used to make methods for SVG elements
// type name
str clip_path :a:"clip-path" :e:"clipPath"
str mask
str path
str _clip_path :a:"clip-path" :e:"clipPath"
str _mask
str _path
}

impl<'updater, C: Component> SemsSamsAmbiguous for SvgElementUpdater<'updater, C> {}
Expand Down

0 comments on commit 739ebd0

Please sign in to comment.