Skip to content

Commit

Permalink
make clippy happy again
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed May 4, 2024
1 parent 2043791 commit 95e3ab7
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 59 deletions.
9 changes: 5 additions & 4 deletions crates/gosub_css3/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::location::Location;
use core::fmt::{Display, Formatter};
use std::ops::Deref;

use crate::location::Location;

pub type Number = f32;

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -304,7 +305,7 @@ impl Node {
matcher,
value,
flags,
} => (&name, matcher, &value, &flags),
} => (name, matcher, value, flags),
_ => panic!("Node is not an attribute selector"),
}
}
Expand Down Expand Up @@ -348,7 +349,7 @@ impl Node {

pub fn as_dimension(&self) -> (&Number, &String) {
match &self.node_type.deref() {
&NodeType::Dimension { value, unit } => (&value, &unit),
&NodeType::Dimension { value, unit } => (value, unit),
_ => panic!("Node is not a dimension"),
}
}
Expand All @@ -374,7 +375,7 @@ impl Node {
property,
value,
important,
} => (&property, &value, &important),
} => (property, value, important),
_ => panic!("Node is not a declaration"),
}
}
Expand Down
69 changes: 35 additions & 34 deletions crates/gosub_html5/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,40 @@ enum InsertionMode {
AfterAfterFrameset,
}

/// Additional extensions to the Vec type so we can do some stack operations
trait VecExtensions<T> {
fn pop_until<F>(&mut self, f: F)
where
F: FnMut(&T) -> bool;
fn pop_check<F>(&mut self, f: F) -> bool
where
F: FnMut(&T) -> bool;
}

impl VecExtensions<NodeId> for Vec<NodeId> {
fn pop_until<F>(&mut self, mut f: F)
where
F: FnMut(&NodeId) -> bool,
{
while let Some(top) = self.last() {
if f(top) {
break;
}
self.pop();
}
}

fn pop_check<F>(&mut self, mut f: F) -> bool
where
F: FnMut(&NodeId) -> bool,
{
match self.pop() {
Some(popped_value) => f(&popped_value),
None => false,
}
}
}
// /// Additional extensions to the Vec type so we can do some stack operations
// trait VecExtensions<T> {
// fn pop_until<F>(&mut self, f: F)
// where
// F: FnMut(&T) -> bool;
// fn pop_check<F>(&mut self, f: F) -> bool
// where
// F: FnMut(&T) -> bool;
// }
//
// impl VecExtensions<NodeId> for Vec<NodeId> {
// fn pop_until<F>(&mut self, mut f: F)
// where
// F: FnMut(&NodeId) -> bool,
// {
// while let Some(top) = self.last() {
// if f(top) {
// break;
// }
// self.pop();
// }
// }
//
// fn pop_check<F>(&mut self, mut f: F) -> bool
// where
// F: FnMut(&NodeId) -> bool,
// {
// match self.pop() {
// Some(popped_value) => f(&popped_value),
// None => false,
// }
// }
// }
//TODO: are these still needed?

macro_rules! get_node_by_id {
($doc_handle:expr, $id:expr) => {
Expand Down Expand Up @@ -3741,7 +3742,7 @@ impl<'chars> Html5Parser<'chars> {
fn adjust_svg_tag_names(&self, token: &mut Token) {
if let Token::StartTag { name, .. } = token {
if SVG_ADJUSTMENTS_TAGS.contains_key(name) {
*name = (*SVG_ADJUSTMENTS_TAGS.get(name).expect("svg tagname")).to_owned();
(*SVG_ADJUSTMENTS_TAGS.get(name).expect("svg tagname")).clone_into(name);
}
}
}
Expand Down
23 changes: 17 additions & 6 deletions crates/gosub_html5/src/parser/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,20 @@ impl DocumentHandle {
pub fn deep_clone(&self) -> DocumentHandle {
let mut doc_handle = Document::shared(None);

doc_handle.get_mut().location = self.get().location.clone();
doc_handle.get_mut().named_id_elements = self.get().named_id_elements.clone();
doc_handle
.get_mut()
.location
.clone_from(&self.get().location);
doc_handle
.get_mut()
.named_id_elements
.clone_from(&self.get().named_id_elements);
doc_handle.get_mut().doctype = self.get().doctype;
doc_handle.get_mut().quirks_mode = self.get().quirks_mode;
doc_handle.get_mut().stylesheets = self.get().stylesheets.clone();
doc_handle
.get_mut()
.stylesheets
.clone_from(&self.get().stylesheets);
doc_handle.get_mut().arena = self.get().arena.clone();

doc_handle
Expand Down Expand Up @@ -965,7 +974,9 @@ impl DocumentBuilder {
}

// Copy location
doc.get_mut().location = doc_get.borrow().location.clone();
doc.get_mut()
.location
.clone_from(&doc_get.borrow().location);
}

// @TODO: Set tokenizer state based on context element
Expand Down Expand Up @@ -1299,8 +1310,8 @@ mod tests {

// validate that invalid changes did not apply to DOM
let doc_read = document.get();
assert!(doc_read.named_id_elements.get("my id").is_none());
assert!(doc_read.named_id_elements.get("").is_none());
assert!(!doc_read.named_id_elements.contains_key("my id"));
assert!(!doc_read.named_id_elements.contains_key(""));
}

// this is basically a replica of document_task_queue() test
Expand Down
12 changes: 6 additions & 6 deletions crates/gosub_jsapi/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ impl Console {
/// Create a counter named "label"
pub fn count(&mut self, label: &str) {
let mut cnt = 1;
if self.count_map.contains_key(&label.to_owned()) {
cnt = self.count_map.get(&label.to_owned()).unwrap() + 1;
if self.count_map.contains_key(label) {
cnt = self.count_map.get(label).unwrap() + 1;
}

self.count_map.insert(label.to_owned(), cnt);
Expand All @@ -173,7 +173,7 @@ impl Console {

/// Reset count of the given label to 0
pub fn count_reset(&mut self, label: &str) {
if !self.count_map.contains_key(&label.to_owned()) {
if !self.count_map.contains_key(label) {
self.logger(LogLevel::CountReset, &[&"label does not exist"]);
return;
}
Expand Down Expand Up @@ -225,7 +225,7 @@ impl Console {

/// Create a timer with given label
pub fn time(&mut self, label: &str) {
if self.timer_map.contains_key(&label.to_owned()) {
if self.timer_map.contains_key(label) {
let warning = format!("Timer '{label}' already started");
self.logger(LogLevel::Warn, &[&warning]);
return;
Expand Down Expand Up @@ -262,7 +262,7 @@ impl Console {
let concat = format!(
"{}: {}ms{}",
label.to_owned(),
cur - self.timer_map.get(&label.to_owned()).unwrap().start,
cur - self.timer_map.get(label).unwrap().start,
message
);
self.printer.print(LogLevel::TimeLog, &[&concat], &[]);
Expand All @@ -278,7 +278,7 @@ impl Console {
let concat = format!(
"{}: {}ms",
label.to_owned(),
end - self.timer_map.get(&label.to_owned()).unwrap().start
end - self.timer_map.get(label).unwrap().start
);
self.printer.print(LogLevel::TimeEnd, &[&concat], &[]);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_jsapi/src/console/writable_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<W: Write> Printer for WritablePrinter<W> {
for arg in args {
data.push_str(format!("{arg} ").as_str());
}
data = data.trim_end().to_owned();
data = data.trim_end().to_string();
let mut writer = self.writer.borrow_mut();

let _ = match log_level {
Expand Down
1 change: 1 addition & 0 deletions crates/gosub_net/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ trait DnsResolver {
fn name(&self) -> &'static str;
}

#[allow(dead_code)]
trait DnsCache {
/// Flush all domains
fn flush_all(&mut self);
Expand Down
14 changes: 6 additions & 8 deletions crates/gosub_webinterop/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::fmt::Debug;

pub(crate) use args::*;
use executor::Executor;
pub(crate) use field::*;
pub(crate) use generics::*;
pub(crate) use primitive::*;
Expand All @@ -15,8 +12,9 @@ mod primitive;
mod slice;
mod ty;

#[derive(Clone, PartialEq, Debug)]
pub(crate) struct PropertyOptions {
pub(crate) executor: Executor,
pub(crate) rename: Option<String>,
}
// #[derive(Clone, PartialEq, Debug)]
// pub(crate) struct PropertyOptions {
// pub(crate) executor: Executor,
// pub(crate) rename: Option<String>,
// }
//TODO: is this still needed?

0 comments on commit 95e3ab7

Please sign in to comment.