fix clippy issues

This commit is contained in:
Michael Zhang 2020-02-09 22:58:13 -06:00
parent ebcb5f818b
commit 46be78e007
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
3 changed files with 22 additions and 22 deletions

View file

@ -9,7 +9,6 @@ mod visitor;
use std::collections::HashMap; use std::collections::HashMap;
use petgraph::{dot::Dot, graph::Graph};
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use syn::Expr; use syn::Expr;
@ -29,10 +28,8 @@ fn process(
let new_dom = visitor.make_graph(&dom); let new_dom = visitor.make_graph(&dom);
let toplevel_names = visitor.gen_code(&new_dom); let toplevel_names = visitor.gen_code(&new_dom);
// println!("{:?}", visitor); // let graph: Graph<_, _, _> = visitor.deps.clone().into_graph();
println!("DOT:"); // println!("{:?}", Dot::new(&graph));
let graph: Graph<_, _, _> = visitor.deps.clone().into_graph();
println!("{:?}", Dot::new(&graph));
let name = format_ident!("{}", name); let name = format_ident!("{}", name);
let mut model = TokenStream::new(); let mut model = TokenStream::new();
@ -85,7 +82,7 @@ fn process(
} }
#[proc_macro] #[proc_macro]
pub fn example(input_tokens: proc_macro::TokenStream) -> proc_macro::TokenStream { pub fn example(_input_tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
let helloworld_datamodel: HashMap<String, String> = hashmap! { let helloworld_datamodel: HashMap<String, String> = hashmap! {
"name".into() => "String".into(), "name".into() => "String".into(),
}; };

View file

@ -15,8 +15,10 @@ type Id = Symbol;
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum TagLhs { pub enum TagLhs {
Bind(String), Bind(String),
On(String), // On(String),
Plain(String), // Plain(String),
#[doc(hidden)]
_Nonexhaustive,
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]
@ -31,6 +33,9 @@ pub enum Rsx {
Elem(Elem<Rsx>), Elem(Elem<Rsx>),
Code(Expr), Code(Expr),
Text(String), Text(String),
#[doc(hidden)]
_Nonexhaustive,
} }
#[derive(Debug)] #[derive(Debug)]
@ -38,12 +43,16 @@ pub enum TaggedRsx {
Elem(Id, Elem<TaggedRsx>), Elem(Id, Elem<TaggedRsx>),
Code(Id, Expr), Code(Id, Expr),
Text(Id, String), Text(Id, String),
#[doc(hidden)]
_Nonexhaustive,
} }
impl TaggedRsx { impl TaggedRsx {
pub fn get_id(&self) -> Id { pub fn get_id(&self) -> Id {
match self { match self {
TaggedRsx::Elem(id, _) | TaggedRsx::Code(id, _) | TaggedRsx::Text(id, _) => *id, TaggedRsx::Elem(id, _) | TaggedRsx::Code(id, _) | TaggedRsx::Text(id, _) => *id,
_ => unimplemented!(),
} }
} }
} }
@ -60,11 +69,6 @@ pub enum DepNode {
ModelValue(Symbol), ModelValue(Symbol),
} }
#[derive(Debug)]
enum DepActions {
Updates,
}
type DependencyGraph = DiGraphMap<DepNode, ()>; type DependencyGraph = DiGraphMap<DepNode, ()>;
#[derive(Default, Debug)] #[derive(Default, Debug)]
@ -138,6 +142,7 @@ impl Visitor {
TaggedRsx::Code(node_id, expr.clone()) TaggedRsx::Code(node_id, expr.clone())
} }
Rsx::Text(literal) => TaggedRsx::Text(node_id, literal.clone()), Rsx::Text(literal) => TaggedRsx::Text(node_id, literal.clone()),
_ => unimplemented!(),
}; };
new_nodes.push(new_node); new_nodes.push(new_node);
} }
@ -150,7 +155,7 @@ impl Visitor {
let node_str = node.get_id().as_str(); let node_str = node.get_id().as_str();
let make_node_id = format_ident!("make_{}", node_str); let make_node_id = format_ident!("make_{}", node_str);
match node { match node {
TaggedRsx::Elem(node_id, Elem { tag, attrs, inner }) => { TaggedRsx::Elem(node_id, Elem { tag, inner, .. }) => {
let mut updates = TokenStream::new(); let mut updates = TokenStream::new();
if let Some(this_attrs) = self.elem_attr_map.get(node_id) { if let Some(this_attrs) = self.elem_attr_map.get(node_id) {
for attr in this_attrs { for attr in this_attrs {
@ -159,7 +164,6 @@ impl Visitor {
let mut update_func = TokenStream::new(); let mut update_func = TokenStream::new();
while let Some(nx) = dfs.next(&self.deps) { while let Some(nx) = dfs.next(&self.deps) {
if nx != starting { if nx != starting {
println!("NX: {:?}", nx);
match nx { match nx {
DepNode::ModelValue(sym) => { DepNode::ModelValue(sym) => {
let sym_name = format_ident!( let sym_name = format_ident!(
@ -206,24 +210,24 @@ impl Visitor {
self.impl_code.extend(quote! { self.impl_code.extend(quote! {
fn #make_node_id(&self) -> impl stdweb::web::INode { fn #make_node_id(&self) -> impl stdweb::web::INode {
let el = document().create_element(#tag).unwrap(); let el = document().create_element(#tag).unwrap();
el.set_attribute("id", #node_str); el.set_attribute("id", #node_str).unwrap();
#updates #updates
el el
} }
}); });
self.gen_code(&inner); self.gen_code(&inner);
} }
TaggedRsx::Code(node_id, expr) => { TaggedRsx::Code(_, _) => {
self.impl_code.extend(quote! { self.impl_code.extend(quote! {
#[inline] #[inline]
fn #make_node_id(&self) -> impl stdweb::web::INode { fn #make_node_id(&self) -> impl stdweb::web::INode {
let el = document().create_element("span").expect("shouldn't fail"); let el = document().create_element("span").expect("shouldn't fail");
el.set_attribute("id", #node_str); el.set_attribute("id", #node_str).unwrap();
el el
} }
}); });
} }
TaggedRsx::Text(node_id, literal) => { TaggedRsx::Text(_, literal) => {
self.impl_code.extend(quote! { self.impl_code.extend(quote! {
#[inline] #[inline]
fn #make_node_id(&self) -> impl stdweb::web::INode { fn #make_node_id(&self) -> impl stdweb::web::INode {
@ -231,7 +235,7 @@ impl Visitor {
} }
}); });
} }
_ => (), _ => unimplemented!(),
} }
names.push(format!("{}", make_node_id)); names.push(format!("{}", make_node_id));
} }

View file

@ -12,9 +12,8 @@ use stdweb::{
unstable::TryFrom, unstable::TryFrom,
web::{ web::{
document, html_element::InputElement, Element, IElement, IEventTarget, INode, document, html_element::InputElement, Element, IElement, IEventTarget, INode,
INonElementParentNode, TextNode, INonElementParentNode,
}, },
Reference, Value,
}; };
use crate::backend::{Backend, Web}; use crate::backend::{Backend, Web};