Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy fixes #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ futures-signals = "0.3.5"
wasm-bindgen = "0.2.48"
js-sys = "0.3.22"
wasm-bindgen-futures = "0.4.9"
gloo-events = "0.1.2"
gloo-events = "0.2.0"

[dependencies.web-sys]
version = "0.3.22"
Expand Down
52 changes: 26 additions & 26 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn timestamps() -> Timestamps {

lock.states.push(Arc::downgrade(&timestamps.state));

if let None = lock.raf {
if lock.raf.is_none() {
let timestamps_manager = timestamps_manager.clone();

lock.raf = Some(Raf::new(move |time| {
Expand All @@ -182,7 +182,7 @@ pub fn timestamps() -> Timestamps {
}
});

if lock.states.len() == 0 {
if lock.states.is_empty() {
lock.raf = None;
// TODO is this a good idea ?
lock.states = vec![];
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<S: SignalVec> AnimatedSignalVec for S {
fn animated_map<A, F>(self, duration: f64, f: F) -> AnimatedMap<Self, F>
where F: FnMut(Self::Item, Self::Animation) -> A {
AnimatedMap {
duration: duration,
duration,
animations: vec![],
signal: Some(self),
callback: f,
Expand Down Expand Up @@ -275,7 +275,7 @@ impl<A, F, S> AnimatedMap<S, F>
}
}

fn should_remove(animations: &mut Vec<AnimatedMapState>, cx: &mut Context, index: usize) -> bool {
fn should_remove(animations: &mut [AnimatedMapState], cx: &mut Context, index: usize) -> bool {
let state = &mut animations[index];

state.animation.animate_to(Percentage::new_unchecked(0.0));
Expand All @@ -291,7 +291,7 @@ impl<A, F, S> AnimatedMap<S, F>
}
}

fn find_index(animations: &Vec<AnimatedMapState>, parent_index: usize) -> Option<usize> {
fn find_index(animations: &mut [AnimatedMapState], parent_index: usize) -> Option<usize> {
let mut seen = 0;

// TODO is there a combinator that can simplify this ?
Expand All @@ -312,7 +312,7 @@ impl<A, F, S> AnimatedMap<S, F>
}

#[inline]
fn find_last_index(animations: &Vec<AnimatedMapState>) -> Option<usize> {
fn find_last_index(animations: &mut [AnimatedMapState]) -> Option<usize> {
animations.iter().rposition(|state| state.removing.is_none())
}
}
Expand All @@ -326,7 +326,7 @@ impl<A, F, S> SignalVec for AnimatedMap<S, F>
fn poll_vec_change(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<VecDiff<Self::Item>>> {
let mut is_done = true;

let AnimatedMapProj { mut animations, mut signal, callback, duration, .. } = self.project();
let AnimatedMapProj { animations, mut signal, callback, duration, .. } = self.project();

// TODO is this loop correct ?
while let Some(result) = signal.as_mut().as_pin_mut().map(|signal| signal.poll_vec_change(cx)) {
Expand All @@ -353,7 +353,7 @@ impl<A, F, S> SignalVec for AnimatedMap<S, F>
},

VecDiff::InsertAt { index, value } => {
let index = Self::find_index(&animations, index).unwrap_or_else(|| animations.len());
let index = Self::find_index(animations, index).unwrap_or(animations.len());
let state = Self::animated_state(*duration);
let value = callback(value, AnimatedMapBroadcaster(state.animation.raw_clone()));
animations.insert(index, state);
Expand All @@ -368,7 +368,7 @@ impl<A, F, S> SignalVec for AnimatedMap<S, F>
},

VecDiff::UpdateAt { index, value } => {
let index = Self::find_index(&animations, index).unwrap_throw();
let index = Self::find_index(animations, index).unwrap_throw();
let state = {
let state = &animations[index];
AnimatedMapBroadcaster(state.animation.raw_clone())
Expand All @@ -380,33 +380,33 @@ impl<A, F, S> SignalVec for AnimatedMap<S, F>
// TODO test this
// TODO should this be treated as a removal + insertion ?
VecDiff::Move { old_index, new_index } => {
let old_index = Self::find_index(&animations, old_index).unwrap_throw();
let old_index = Self::find_index(animations, old_index).unwrap_throw();

let state = animations.remove(old_index);

let new_index = Self::find_index(&animations, new_index).unwrap_or_else(|| animations.len());
let new_index = Self::find_index(animations, new_index).unwrap_or(animations.len());

animations.insert(new_index, state);

Poll::Ready(Some(VecDiff::Move { old_index, new_index }))
},

VecDiff::RemoveAt { index } => {
let index = Self::find_index(&animations, index).unwrap_throw();
let index = Self::find_index(animations, index).unwrap_throw();

if Self::should_remove(&mut animations, cx, index) {
Self::remove_index(&mut animations, index)
if Self::should_remove(animations, cx, index) {
Self::remove_index(animations, index)

} else {
continue;
}
},

VecDiff::Pop {} => {
let index = Self::find_last_index(&animations).unwrap_throw();
let index = Self::find_last_index(animations).unwrap_throw();

if Self::should_remove(&mut animations, cx, index) {
Self::remove_index(&mut animations, index)
if Self::should_remove(animations, cx, index) {
Self::remove_index(animations, index)

} else {
continue;
Expand Down Expand Up @@ -446,7 +446,7 @@ impl<A, F, S> SignalVec for AnimatedMap<S, F>

match index {
Some(index) => {
Self::remove_index(&mut animations, index)
Self::remove_index(animations, index)
},
None => if is_done && !is_removing {
Poll::Ready(None)
Expand All @@ -468,7 +468,7 @@ impl Percentage {

#[inline]
pub fn new(input: f64) -> Self {
debug_assert!(input >= 0.0 && input <= 1.0);
debug_assert!((0.0..=1.0).contains(&input));
Self::new_unchecked(input)
}

Expand Down Expand Up @@ -660,7 +660,7 @@ impl MutableAnimation {
inner: Arc::new(MutableAnimationInner {
state: Mutex::new(MutableAnimationState {
playing: true,
duration: duration,
duration,
end: initial,
_animating: None,
}),
Expand Down Expand Up @@ -757,8 +757,8 @@ impl MutableAnimation {
}
}

fn _jump_to(mut lock: &mut MutableAnimationState, mutable: &Mutable<Percentage>, end: Percentage) {
Self::stop_animating(&mut lock);
fn _jump_to(lock: &mut MutableAnimationState, mutable: &Mutable<Percentage>, end: Percentage) {
Self::stop_animating(lock);

lock.end = end;

Expand Down Expand Up @@ -876,10 +876,10 @@ pub mod easing {

impl CubicBezier {
pub fn new(x1: f64, y1: f64, x2: f64, y2: f64) -> Self {
assert!(x1 >= 0.0 && x1 <= 1.0);
assert!(y1 >= 0.0 && y1 <= 1.0);
assert!(x2 >= 0.0 && x2 <= 1.0);
assert!(y2 >= 0.0 && y2 <= 1.0);
assert!((0.0..=1.0).contains(&x1));
assert!((0.0..=1.0).contains(&y1));
assert!((0.0..=1.0).contains(&x2));
assert!((0.0..=1.0).contains(&y2));

let cx = 3.0 * x1;
let bx = 3.0 * (x2 - x1) - cx;
Expand Down
1 change: 0 additions & 1 deletion src/callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std;
use discard::Discard;


Expand Down
58 changes: 22 additions & 36 deletions src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ impl Discard for DomHandle {
#[inline]
#[track_caller]
pub fn append_dom(parent: &Node, dom: Dom) -> DomHandle {
bindings::append_child(&parent, &dom.element);
bindings::append_child(parent, &dom.element);
DomHandle::new(parent, dom)
}

/// The same as [`append_dom`] except it replaces an existing DOM node.
#[inline]
#[track_caller]
pub fn replace_dom(parent: &Node, old_node: &Node, dom: Dom) -> DomHandle {
bindings::replace_child(&parent, &dom.element, old_node);
bindings::replace_child(parent, &dom.element, old_node);
DomHandle::new(parent, dom)
}

Expand Down Expand Up @@ -318,7 +318,7 @@ pub fn text_signal<A, B>(value: B) -> Dom

Dom {
element: element.into(),
callbacks: callbacks,
callbacks,
}
}

Expand Down Expand Up @@ -419,14 +419,14 @@ fn set_style<A, B>(style: &CssStyleDeclaration, name: &A, value: B, important: b

// TODO track_caller
fn try_set_style(style: &CssStyleDeclaration, names: &mut Vec<String>, values: &mut Vec<String>, name: &str, value: &str, important: bool) -> Option<()> {
assert!(value != "");
assert!(!value.is_empty());

// TODO handle browser prefixes ?
bindings::remove_style(style, name);

bindings::set_style(style, name, value, important);

let is_changed = bindings::get_style(style, name) != "";
let is_changed = !bindings::get_style(style, name).is_empty();

if is_changed {
Some(())
Expand All @@ -443,15 +443,13 @@ fn set_style<A, B>(style: &CssStyleDeclaration, name: &A, value: B, important: b

value.find_map(|value| {
// TODO should this intern ?
try_set_style(style, &mut names, &mut values, &name, &value, important)
try_set_style(style, &mut names, &mut values, name, value, important)
})
});

if let None = okay {
if cfg!(debug_assertions) {
// TODO maybe make this configurable
panic!("style is incorrect:\n names: {}\n values: {}", names.join(", "), values.join(", "));
}
if okay.is_none() && cfg!(debug_assertions) {
// TODO maybe make this configurable
panic!("style is incorrect:\n names: {}\n values: {}", names.join(", "), values.join(", "));
}
}

Expand Down Expand Up @@ -521,7 +519,7 @@ fn set_property<A, B, C>(element: &A, name: &B, value: C) where A: AsRef<JsValue
}


#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, Hash, PartialEq, Eq)]
pub struct EventOptions {
pub bubbles: bool,
pub preventable: bool,
Expand Down Expand Up @@ -554,16 +552,6 @@ impl EventOptions {
}
}

impl Default for EventOptions {
fn default() -> Self {
Self {
bubbles: false,
preventable: false,
}
}
}


// TODO better warning message for must_use
#[must_use]
#[derive(Debug)]
Expand Down Expand Up @@ -774,7 +762,7 @@ impl<A> DomBuilder<A> where A: AsRef<EventTarget> {
pub fn event_with_options<T, F>(mut self, options: &EventOptions, listener: F) -> Self
where T: StaticEvent,
F: FnMut(T) + 'static {
Self::_event(&mut self.callbacks, &self.element.as_ref(), options, listener);
Self::_event(&mut self.callbacks, self.element.as_ref(), options, listener);
self
}

Expand Down Expand Up @@ -886,7 +874,7 @@ impl<A> DomBuilder<A> where A: AsRef<Element> {
let element = self.element.as_ref();

name.each(|name| {
bindings::set_attribute(element, intern(name), &value);
bindings::set_attribute(element, intern(name), value);
});

self
Expand All @@ -906,7 +894,7 @@ impl<A> DomBuilder<A> where A: AsRef<Element> {
let namespace: &str = intern(namespace);

name.each(|name| {
bindings::set_attribute_ns(element, &namespace, intern(name), &value);
bindings::set_attribute_ns(element, namespace, intern(name), value);
});

self
Expand Down Expand Up @@ -959,7 +947,7 @@ impl<A> DomBuilder<A> where A: AsRef<Element> {
Some(value) => {
value.with_str(|value| {
name.each(|name| {
bindings::set_attribute(element, intern(name), &value);
bindings::set_attribute(element, intern(name), value);
});
});
},
Expand Down Expand Up @@ -1014,7 +1002,7 @@ impl<A> DomBuilder<A> where A: AsRef<Element> {
value.with_str(|value| {
name.each(|name| {
// TODO should this intern the value ?
bindings::set_attribute_ns(element, &namespace, intern(name), &value);
bindings::set_attribute_ns(element, &namespace, intern(name), value);
});
});
},
Expand Down Expand Up @@ -1072,14 +1060,12 @@ impl<A> DomBuilder<A> where A: AsRef<Element> {
});
}

} else {
if is_set {
is_set = false;
} else if is_set {
is_set = false;

name.each(|name| {
bindings::remove_class(&element, intern(name));
});
}
name.each(|name| {
bindings::remove_class(&element, intern(name));
});
}
}));
}
Expand Down Expand Up @@ -1418,7 +1404,7 @@ impl ClassBuilder {

Self {
// TODO make this more efficient ?
stylesheet: StylesheetBuilder::__internal_stylesheet(&format!(".{} {{}}", class_name)),
stylesheet: StylesheetBuilder::__internal_stylesheet(format!(".{} {{}}", class_name)),
class_name,
}
}
Expand Down Expand Up @@ -1682,7 +1668,7 @@ mod tests {
.style("foo".to_owned(), "bar".to_owned())
.style_signal("foo".to_owned(), always("bar".to_owned()))

.style(&"foo".to_owned(), &"bar".to_owned())
.style("foo".to_owned(), "bar".to_owned())
//.style(Box::new("foo".to_owned()), Box::new("bar".to_owned()))
//.style_signal(Box::new("foo".to_owned()), always(Box::new("bar".to_owned())))

Expand Down
Loading