Merge pull request #803 from Demonthos/fix-clippy
Fix Clippy warnings in core
This commit is contained in:
37 files changed
+96
-107
No files matched your search
@@ -39,7 +39,7 @@ async fn main() {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("Listening on http://{}", addr);
|
println!("Listening on http://{addr}");
|
||||||
|
|
||||||
axum::Server::bind(&addr.to_string().parse().unwrap())
|
axum::Server::bind(&addr.to_string().parse().unwrap())
|
||||||
.serve(app.into_make_service())
|
.serve(app.into_make_service())
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
let temp = calc_val(val.as_str());
|
let temp = calc_val(val.as_str());
|
||||||
if temp > 0.0 {
|
if temp > 0.0 {
|
||||||
val.set(format!("-{}", temp));
|
val.set(format!("-{temp}"));
|
||||||
} else {
|
} else {
|
||||||
val.set(format!("{}", temp.abs()));
|
val.set(format!("{}", temp.abs()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("{:#?}, ", res);
|
println!("{res:#?}, ");
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
loop {
|
loop {
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||||
count += 1;
|
count += 1;
|
||||||
println!("current: {}", count);
|
println!("current: {count}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ struct DogApi {
|
|||||||
#[inline_props]
|
#[inline_props]
|
||||||
async fn breed_pic(cx: Scope, breed: String) -> Element {
|
async fn breed_pic(cx: Scope, breed: String) -> Element {
|
||||||
let fut = use_future!(cx, |breed| async move {
|
let fut = use_future!(cx, |breed| async move {
|
||||||
reqwest::get(format!("https://dog.ceo/api/breed/{}/images/random", breed))
|
reqwest::get(format!("https://dog.ceo/api/breed/{breed}/images/random"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.json::<DogApi>()
|
.json::<DogApi>()
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ impl Files {
|
|||||||
let paths = match std::fs::read_dir(cur_path) {
|
let paths = match std::fs::read_dir(cur_path) {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let err = format!("An error occured: {:?}", err);
|
let err = format!("An error occured: {err:?}");
|
||||||
self.err = Some(err);
|
self.err = Some(err);
|
||||||
self.path_stack.pop();
|
self.path_stack.pop();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use dioxus_desktop::Config;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cfg = Config::new().with_file_drop_handler(|_w, e| {
|
let cfg = Config::new().with_file_drop_handler(|_w, e| {
|
||||||
println!("{:?}", e);
|
println!("{e:?}");
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -42,7 +42,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
// so the value of our input event will be either huey, dewey, louie, or true/false (because of the checkboxe)
|
// so the value of our input event will be either huey, dewey, louie, or true/false (because of the checkboxe)
|
||||||
// be mindful in grouping inputs together, as they will all be handled by the same event handler
|
// be mindful in grouping inputs together, as they will all be handled by the same event handler
|
||||||
oninput: move |evt| {
|
oninput: move |evt| {
|
||||||
println!("{:?}", evt);
|
println!("{evt:?}");
|
||||||
},
|
},
|
||||||
div {
|
div {
|
||||||
input {
|
input {
|
||||||
@@ -104,7 +104,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
name: "pdf",
|
name: "pdf",
|
||||||
r#type: "checkbox",
|
r#type: "checkbox",
|
||||||
oninput: move |evt| {
|
oninput: move |evt| {
|
||||||
println!("{:?}", evt);
|
println!("{evt:?}");
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
label {
|
label {
|
||||||
@@ -121,7 +121,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
r#type: "{field}",
|
r#type: "{field}",
|
||||||
value: "{value}",
|
value: "{value}",
|
||||||
oninput: move |evt: FormEvent| {
|
oninput: move |evt: FormEvent| {
|
||||||
println!("{:?}", evt);
|
println!("{evt:?}");
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
label {
|
label {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
div {
|
div {
|
||||||
class: {
|
class: {
|
||||||
const WORD: &str = "expressions";
|
const WORD: &str = "expressions";
|
||||||
format_args!("Arguments can be passed in through curly braces for complex {}", WORD)
|
format_args!("Arguments can be passed in through curly braces for complex {WORD}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn format_dollars(dollars: u32, cents: u32) -> String {
|
fn format_dollars(dollars: u32, cents: u32) -> String {
|
||||||
format!("${}.{:02}", dollars, cents)
|
format!("${dollars}.{cents:02}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn helper<'a>(cx: &'a ScopeState, text: &str) -> Element<'a> {
|
fn helper<'a>(cx: &'a ScopeState, text: &str) -> Element<'a> {
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ fn main() {
|
|||||||
let mut file = String::new();
|
let mut file = String::new();
|
||||||
let mut renderer = dioxus_ssr::Renderer::default();
|
let mut renderer = dioxus_ssr::Renderer::default();
|
||||||
renderer.render_to(&mut file, &vdom).unwrap();
|
renderer.render_to(&mut file, &vdom).unwrap();
|
||||||
println!("{}", file);
|
println!("{file}");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ fn main() {
|
|||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
let model = use_state(cx, || String::from("asd"));
|
let model = use_state(cx, || String::from("asd"));
|
||||||
|
|
||||||
println!("{}", model);
|
println!("{model}");
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
textarea {
|
textarea {
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ impl Writer<'_> {
|
|||||||
let mut written = generics.to_token_stream().to_string();
|
let mut written = generics.to_token_stream().to_string();
|
||||||
written.retain(|c| !c.is_whitespace());
|
written.retain(|c| !c.is_whitespace());
|
||||||
|
|
||||||
write!(self.out, "{}", written)?;
|
write!(self.out, "{written}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(self.out, " {{")?;
|
write!(self.out, " {{")?;
|
||||||
@@ -165,7 +165,7 @@ impl Writer<'_> {
|
|||||||
match &field.content {
|
match &field.content {
|
||||||
ContentField::ManExpr(exp) => {
|
ContentField::ManExpr(exp) => {
|
||||||
let out = prettyplease::unparse_expr(exp);
|
let out = prettyplease::unparse_expr(exp);
|
||||||
write!(self.out, "{}: {}", name, out)?;
|
write!(self.out, "{name}: {out}")?;
|
||||||
}
|
}
|
||||||
ContentField::Formatted(s) => {
|
ContentField::Formatted(s) => {
|
||||||
write!(
|
write!(
|
||||||
@@ -179,11 +179,11 @@ impl Writer<'_> {
|
|||||||
let out = prettyplease::unparse_expr(exp);
|
let out = prettyplease::unparse_expr(exp);
|
||||||
let mut lines = out.split('\n').peekable();
|
let mut lines = out.split('\n').peekable();
|
||||||
let first = lines.next().unwrap();
|
let first = lines.next().unwrap();
|
||||||
write!(self.out, "{}: {}", name, first)?;
|
write!(self.out, "{name}: {first}")?;
|
||||||
for line in lines {
|
for line in lines {
|
||||||
self.out.new_line()?;
|
self.out.new_line()?;
|
||||||
self.out.indented_tab()?;
|
self.out.indented_tab()?;
|
||||||
write!(self.out, "{}", line)?;
|
write!(self.out, "{line}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ impl Writer<'_> {
|
|||||||
}
|
}
|
||||||
ElementAttr::AttrExpression { name, value } => {
|
ElementAttr::AttrExpression { name, value } => {
|
||||||
let out = prettyplease::unparse_expr(value);
|
let out = prettyplease::unparse_expr(value);
|
||||||
write!(self.out, "{}: {}", name, out)?;
|
write!(self.out, "{name}: {out}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementAttr::CustomAttrText { name, value } => {
|
ElementAttr::CustomAttrText { name, value } => {
|
||||||
@@ -250,13 +250,13 @@ impl Writer<'_> {
|
|||||||
// a one-liner for whatever reason
|
// a one-liner for whatever reason
|
||||||
// Does not need a new line
|
// Does not need a new line
|
||||||
if lines.peek().is_none() {
|
if lines.peek().is_none() {
|
||||||
write!(self.out, "{}: {}", name, first)?;
|
write!(self.out, "{name}: {first}")?;
|
||||||
} else {
|
} else {
|
||||||
writeln!(self.out, "{}: {}", name, first)?;
|
writeln!(self.out, "{name}: {first}")?;
|
||||||
|
|
||||||
while let Some(line) = lines.next() {
|
while let Some(line) = lines.next() {
|
||||||
self.out.indented_tab()?;
|
self.out.indented_tab()?;
|
||||||
write!(self.out, "{}", line)?;
|
write!(self.out, "{line}")?;
|
||||||
if lines.peek().is_none() {
|
if lines.peek().is_none() {
|
||||||
write!(self.out, "")?;
|
write!(self.out, "")?;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ impl Writer<'_> {
|
|||||||
let start = byte_offset(self.raw_src, start);
|
let start = byte_offset(self.raw_src, start);
|
||||||
let end = byte_offset(self.raw_src, end);
|
let end = byte_offset(self.raw_src, end);
|
||||||
let row = self.raw_src[start..end].trim();
|
let row = self.raw_src[start..end].trim();
|
||||||
write!(self.out, "{}", row)?;
|
write!(self.out, "{row}")?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,11 +56,11 @@ impl Writer<'_> {
|
|||||||
write!(self.out, " ")?;
|
write!(self.out, " ")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(self.out, "{}", line)?;
|
write!(self.out, "{line}")?;
|
||||||
} else {
|
} else {
|
||||||
let offset = offset as usize;
|
let offset = offset as usize;
|
||||||
let right = &line[offset..];
|
let right = &line[offset..];
|
||||||
write!(self.out, "{}", right)?;
|
write!(self.out, "{right}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
|
|||||||
&& matches!(body.roots[0], BodyNode::RawExpr(_) | BodyNode::Text(_));
|
&& matches!(body.roots[0], BodyNode::RawExpr(_) | BodyNode::Text(_));
|
||||||
|
|
||||||
if formatted.len() <= 80 && !formatted.contains('\n') && !body_is_solo_expr {
|
if formatted.len() <= 80 && !formatted.contains('\n') && !body_is_solo_expr {
|
||||||
formatted = format!(" {} ", formatted);
|
formatted = format!(" {formatted} ");
|
||||||
}
|
}
|
||||||
|
|
||||||
end_span = span.end();
|
end_span = span.end();
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ impl ToTokens for InlinePropsBody {
|
|||||||
quote! { #vis #f }
|
quote! { #vis #f }
|
||||||
});
|
});
|
||||||
|
|
||||||
let struct_name = Ident::new(&format!("{}Props", ident), Span::call_site());
|
let struct_name = Ident::new(&format!("{ident}Props"), Span::call_site());
|
||||||
|
|
||||||
let field_names = inputs.iter().filter_map(|f| match f {
|
let field_names = inputs.iter().filter_map(|f| match f {
|
||||||
FnArg::Receiver(_) => todo!(),
|
FnArg::Receiver(_) => todo!(),
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ mod field_info {
|
|||||||
let tokenized_code = TokenStream::from_str(&code.value())?;
|
let tokenized_code = TokenStream::from_str(&code.value())?;
|
||||||
self.default = Some(
|
self.default = Some(
|
||||||
syn::parse(tokenized_code.into())
|
syn::parse(tokenized_code.into())
|
||||||
.map_err(|e| Error::new_spanned(code, format!("{}", e)))?,
|
.map_err(|e| Error::new_spanned(code, format!("{e}")))?,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::new_spanned(assign.right, "Expected string"));
|
return Err(Error::new_spanned(assign.right, "Expected string"));
|
||||||
@@ -332,7 +332,7 @@ mod field_info {
|
|||||||
}
|
}
|
||||||
_ => Err(Error::new_spanned(
|
_ => Err(Error::new_spanned(
|
||||||
&assign,
|
&assign,
|
||||||
format!("Unknown parameter {:?}", name),
|
format!("Unknown parameter {name:?}"),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -503,11 +503,11 @@ mod struct_info {
|
|||||||
builder_attr,
|
builder_attr,
|
||||||
builder_name: syn::Ident::new(&builder_name, proc_macro2::Span::call_site()),
|
builder_name: syn::Ident::new(&builder_name, proc_macro2::Span::call_site()),
|
||||||
conversion_helper_trait_name: syn::Ident::new(
|
conversion_helper_trait_name: syn::Ident::new(
|
||||||
&format!("{}_Optional", builder_name),
|
&format!("{builder_name}_Optional"),
|
||||||
proc_macro2::Span::call_site(),
|
proc_macro2::Span::call_site(),
|
||||||
),
|
),
|
||||||
core: syn::Ident::new(
|
core: syn::Ident::new(
|
||||||
&format!("{}_core", builder_name),
|
&format!("{builder_name}_core"),
|
||||||
proc_macro2::Span::call_site(),
|
proc_macro2::Span::call_site(),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
@@ -594,7 +594,6 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
None => {
|
None => {
|
||||||
let doc = format!(
|
let doc = format!(
|
||||||
"Builder for [`{name}`] instances.\n\nSee [`{name}::builder()`] for more info.",
|
"Builder for [`{name}`] instances.\n\nSee [`{name}::builder()`] for more info.",
|
||||||
name = name
|
|
||||||
);
|
);
|
||||||
quote!(#[doc = #doc])
|
quote!(#[doc = #doc])
|
||||||
}
|
}
|
||||||
@@ -709,9 +708,9 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
});
|
});
|
||||||
let reconstructing = self.included_fields().map(|f| f.name);
|
let reconstructing = self.included_fields().map(|f| f.name);
|
||||||
|
|
||||||
let &FieldInfo {
|
let FieldInfo {
|
||||||
name: ref field_name,
|
name: field_name,
|
||||||
ty: ref field_type,
|
ty: field_type,
|
||||||
..
|
..
|
||||||
} = field;
|
} = field;
|
||||||
let mut ty_generics: Vec<syn::GenericArgument> = self
|
let mut ty_generics: Vec<syn::GenericArgument> = self
|
||||||
@@ -810,7 +809,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
),
|
),
|
||||||
proc_macro2::Span::call_site(),
|
proc_macro2::Span::call_site(),
|
||||||
);
|
);
|
||||||
let repeated_fields_error_message = format!("Repeated field {}", field_name);
|
let repeated_fields_error_message = format!("Repeated field {field_name}");
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[allow(dead_code, non_camel_case_types, missing_docs)]
|
#[allow(dead_code, non_camel_case_types, missing_docs)]
|
||||||
@@ -929,7 +928,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
),
|
),
|
||||||
proc_macro2::Span::call_site(),
|
proc_macro2::Span::call_site(),
|
||||||
);
|
);
|
||||||
let early_build_error_message = format!("Missing required field {}", field_name);
|
let early_build_error_message = format!("Missing required field {field_name}");
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
@@ -1037,7 +1036,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
// I’d prefer “a” or “an” to “its”, but determining which is grammatically
|
// I’d prefer “a” or “an” to “its”, but determining which is grammatically
|
||||||
// correct is roughly impossible.
|
// correct is roughly impossible.
|
||||||
let doc =
|
let doc =
|
||||||
format!("Finalise the builder and create its [`{}`] instance", name);
|
format!("Finalise the builder and create its [`{name}`] instance");
|
||||||
quote!(#[doc = #doc])
|
quote!(#[doc = #doc])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1132,7 +1131,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
}
|
}
|
||||||
_ => Err(Error::new_spanned(
|
_ => Err(Error::new_spanned(
|
||||||
&assign,
|
&assign,
|
||||||
format!("Unknown parameter {:?}", name),
|
format!("Unknown parameter {name:?}"),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1146,7 +1145,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
}
|
}
|
||||||
_ => Err(Error::new_spanned(
|
_ => Err(Error::new_spanned(
|
||||||
&path,
|
&path,
|
||||||
format!("Unknown parameter {:?}", name),
|
format!("Unknown parameter {name:?}"),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1161,7 +1160,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
let call_func = quote!(#call_func);
|
let call_func = quote!(#call_func);
|
||||||
Error::new_spanned(
|
Error::new_spanned(
|
||||||
&call.func,
|
&call.func,
|
||||||
format!("Illegal builder setting group {}", call_func),
|
format!("Illegal builder setting group {call_func}"),
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
match subsetting_name.as_str() {
|
match subsetting_name.as_str() {
|
||||||
@@ -1173,7 +1172,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
}
|
}
|
||||||
_ => Err(Error::new_spanned(
|
_ => Err(Error::new_spanned(
|
||||||
&call.func,
|
&call.func,
|
||||||
format!("Illegal builder setting group name {}", subsetting_name),
|
format!("Illegal builder setting group name {subsetting_name}"),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ fn formatting_compiles() {
|
|||||||
// escape sequences work
|
// escape sequences work
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format_args_f!("{x:?} {{}}}}").to_string(),
|
format_args_f!("{x:?} {{}}}}").to_string(),
|
||||||
format!("{:?} {{}}}}", x)
|
format!("{x:?} {{}}}}")
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format_args_f!("{{{{}} {x:?}").to_string(),
|
format_args_f!("{{{{}} {x:?}").to_string(),
|
||||||
format!("{{{{}} {:?}", x)
|
format!("{{{{}} {x:?}")
|
||||||
);
|
);
|
||||||
|
|
||||||
// paths in formating works
|
// paths in formating works
|
||||||
@@ -27,6 +27,6 @@ fn formatting_compiles() {
|
|||||||
// allows duplicate format args
|
// allows duplicate format args
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format_args_f!("{x:?} {x:?}").to_string(),
|
format_args_f!("{x:?} {x:?}").to_string(),
|
||||||
format!("{:?} {:?}", x, x)
|
format!("{x:?} {x:?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -757,15 +757,21 @@ impl<'a, 'b> IntoDynNode<'a> for LazyNodes<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> IntoDynNode<'_> for &'a str {
|
impl<'a, 'b> IntoDynNode<'b> for &'a str {
|
||||||
fn into_vnode(self, cx: &ScopeState) -> DynamicNode {
|
fn into_vnode(self, cx: &'b ScopeState) -> DynamicNode<'b> {
|
||||||
cx.text_node(format_args!("{}", self))
|
DynamicNode::Text(VText {
|
||||||
|
value: bumpalo::collections::String::from_str_in(self, cx.bump()).into_bump_str(),
|
||||||
|
id: Default::default(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoDynNode<'_> for String {
|
impl IntoDynNode<'_> for String {
|
||||||
fn into_vnode(self, cx: &ScopeState) -> DynamicNode {
|
fn into_vnode(self, cx: &ScopeState) -> DynamicNode {
|
||||||
cx.text_node(format_args!("{}", self))
|
DynamicNode::Text(VText {
|
||||||
|
value: cx.bump().alloc(self),
|
||||||
|
id: Default::default(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -207,13 +207,12 @@ impl DesktopContext {
|
|||||||
"method":"eval_result",
|
"method":"eval_result",
|
||||||
"params": (
|
"params": (
|
||||||
function(){{
|
function(){{
|
||||||
{}
|
{code}
|
||||||
}}
|
}}
|
||||||
)()
|
)()
|
||||||
}})
|
}})
|
||||||
);
|
);
|
||||||
"#,
|
"#
|
||||||
code
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = self.webview.evaluate_script(&script) {
|
if let Err(e) = self.webview.evaluate_script(&script) {
|
||||||
|
|||||||
@@ -326,5 +326,5 @@ fn send_edits(edits: Mutations, webview: &WebView) {
|
|||||||
let serialized = serde_json::to_string(&edits).unwrap();
|
let serialized = serde_json::to_string(&edits).unwrap();
|
||||||
|
|
||||||
// todo: use SSE and binary data to send the edits with lower overhead
|
// todo: use SSE and binary data to send the edits with lower overhead
|
||||||
_ = webview.evaluate_script(&format!("window.interpreter.handleEdits({})", serialized));
|
_ = webview.evaluate_script(&format!("window.interpreter.handleEdits({serialized})"));
|
||||||
}
|
}
|
||||||
@@ -11,15 +11,14 @@ fn module_loader(root_name: &str) -> String {
|
|||||||
<script>
|
<script>
|
||||||
{INTERPRETER_JS}
|
{INTERPRETER_JS}
|
||||||
|
|
||||||
let rootname = "{}";
|
let rootname = "{root_name}";
|
||||||
let root = window.document.getElementById(rootname);
|
let root = window.document.getElementById(rootname);
|
||||||
if (root != null) {{
|
if (root != null) {{
|
||||||
window.interpreter = new Interpreter(root);
|
window.interpreter = new Interpreter(root);
|
||||||
window.ipc.postMessage(serializeIpcMessage("initialize"));
|
window.ipc.postMessage(serializeIpcMessage("initialize"));
|
||||||
}}
|
}}
|
||||||
</script>
|
</script>
|
||||||
"#,
|
"#
|
||||||
root_name
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ mod tests {
|
|||||||
fn app(cx: Scope, name: String) -> Element {
|
fn app(cx: Scope, name: String) -> Element {
|
||||||
let task = use_coroutine(cx, |mut rx: UnboundedReceiver<i32>| async move {
|
let task = use_coroutine(cx, |mut rx: UnboundedReceiver<i32>| async move {
|
||||||
while let Some(msg) = rx.next().await {
|
while let Some(msg) = rx.next().await {
|
||||||
println!("got message: {}", msg);
|
println!("got message: {msg}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ mod tests {
|
|||||||
|
|
||||||
async fn view_task(mut rx: UnboundedReceiver<i32>) {
|
async fn view_task(mut rx: UnboundedReceiver<i32>) {
|
||||||
while let Some(msg) = rx.next().await {
|
while let Some(msg) = rx.next().await {
|
||||||
println!("got message: {}", msg);
|
println!("got message: {msg}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ fn render_template_node(node: &TemplateNode, out: &mut String) -> std::fmt::Resu
|
|||||||
write!(out, "<{tag}")?;
|
write!(out, "<{tag}")?;
|
||||||
for attr in *attrs {
|
for attr in *attrs {
|
||||||
if let TemplateAttribute::Static { name, value, .. } = attr {
|
if let TemplateAttribute::Static { name, value, .. } = attr {
|
||||||
write!(out, "{}=\"{}\"", name, value)?;
|
write!(out, "{name}=\"{value}\"")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for child in *children {
|
for child in *children {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ async fn main() {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("Listening on http://{}", addr);
|
println!("Listening on http://{addr}");
|
||||||
|
|
||||||
axum::Server::bind(&addr.to_string().parse().unwrap())
|
axum::Server::bind(&addr.to_string().parse().unwrap())
|
||||||
.serve(app.into_make_service())
|
.serve(app.into_make_service())
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ impl Parse for Dependency {
|
|||||||
input
|
input
|
||||||
.parse::<Ident>()
|
.parse::<Ident>()
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|i: &Ident| format!("{}", i) != "NONE")
|
.filter(|i: &Ident| i != "NONE")
|
||||||
.map(|i| vec![i])
|
.map(|i| vec![i])
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|||||||
@@ -151,10 +151,10 @@ pub trait Pass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait UpwardPass<T>: Pass {
|
pub trait UpwardPass<T>: Pass {
|
||||||
fn pass<'a>(
|
fn pass(
|
||||||
&self,
|
&self,
|
||||||
node: &mut T,
|
node: &mut T,
|
||||||
children: &mut dyn Iterator<Item = &'a mut T>,
|
children: &mut dyn Iterator<Item = &mut T>,
|
||||||
ctx: &SendAnyMap,
|
ctx: &SendAnyMap,
|
||||||
) -> PassReturn;
|
) -> PassReturn;
|
||||||
}
|
}
|
||||||
@@ -764,10 +764,10 @@ fn up_pass() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl UpwardPass<i32> for AddPass {
|
impl UpwardPass<i32> for AddPass {
|
||||||
fn pass<'a>(
|
fn pass(
|
||||||
&self,
|
&self,
|
||||||
node: &mut i32,
|
node: &mut i32,
|
||||||
children: &mut dyn Iterator<Item = &'a mut i32>,
|
children: &mut dyn Iterator<Item = &mut i32>,
|
||||||
_: &SendAnyMap,
|
_: &SendAnyMap,
|
||||||
) -> PassReturn {
|
) -> PassReturn {
|
||||||
*node += children.map(|i| *i).sum::<i32>();
|
*node += children.map(|i| *i).sum::<i32>();
|
||||||
@@ -830,10 +830,10 @@ fn dependant_up_pass() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl UpwardPass<i32> for AddPass {
|
impl UpwardPass<i32> for AddPass {
|
||||||
fn pass<'a>(
|
fn pass(
|
||||||
&self,
|
&self,
|
||||||
node: &mut i32,
|
node: &mut i32,
|
||||||
children: &mut dyn Iterator<Item = &'a mut i32>,
|
children: &mut dyn Iterator<Item = &mut i32>,
|
||||||
_: &SendAnyMap,
|
_: &SendAnyMap,
|
||||||
) -> PassReturn {
|
) -> PassReturn {
|
||||||
*node += children.map(|i| *i).sum::<i32>();
|
*node += children.map(|i| *i).sum::<i32>();
|
||||||
@@ -863,10 +863,10 @@ fn dependant_up_pass() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl UpwardPass<i32> for SubtractPass {
|
impl UpwardPass<i32> for SubtractPass {
|
||||||
fn pass<'a>(
|
fn pass(
|
||||||
&self,
|
&self,
|
||||||
node: &mut i32,
|
node: &mut i32,
|
||||||
children: &mut dyn Iterator<Item = &'a mut i32>,
|
children: &mut dyn Iterator<Item = &mut i32>,
|
||||||
_: &SendAnyMap,
|
_: &SendAnyMap,
|
||||||
) -> PassReturn {
|
) -> PassReturn {
|
||||||
*node -= children.map(|i| *i).sum::<i32>();
|
*node -= children.map(|i| *i).sum::<i32>();
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ impl ChildDepState for () {
|
|||||||
impl ParentDepState for () {
|
impl ParentDepState for () {
|
||||||
type Ctx = ();
|
type Ctx = ();
|
||||||
type DepState = ();
|
type DepState = ();
|
||||||
fn reduce<'a>(&mut self, _: NodeView<'a>, _: Option<()>, _: &Self::Ctx) -> bool {
|
fn reduce(&mut self, _: NodeView, _: Option<()>, _: &Self::Ctx) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,7 +259,7 @@ impl ParentDepState for () {
|
|||||||
impl NodeDepState for () {
|
impl NodeDepState for () {
|
||||||
type DepState = ();
|
type DepState = ();
|
||||||
type Ctx = ();
|
type Ctx = ();
|
||||||
fn reduce<'a>(&mut self, _: NodeView<'a>, _sibling: (), _: &Self::Ctx) -> bool {
|
fn reduce(&mut self, _: NodeView, _sibling: (), _: &Self::Ctx) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -426,7 +426,7 @@ fn creation() {
|
|||||||
let child = tree.create_node(0);
|
let child = tree.create_node(0);
|
||||||
tree.add_child(parent, child);
|
tree.add_child(parent, child);
|
||||||
|
|
||||||
println!("Tree: {:#?}", tree);
|
println!("Tree: {tree:#?}");
|
||||||
assert_eq!(tree.size(), 2);
|
assert_eq!(tree.size(), 2);
|
||||||
assert_eq!(tree.height(parent), Some(0));
|
assert_eq!(tree.height(parent), Some(0));
|
||||||
assert_eq!(tree.height(child), Some(1));
|
assert_eq!(tree.height(child), Some(1));
|
||||||
@@ -448,7 +448,7 @@ fn insertion() {
|
|||||||
let after = tree.create_node(3);
|
let after = tree.create_node(3);
|
||||||
tree.insert_after(child, after);
|
tree.insert_after(child, after);
|
||||||
|
|
||||||
println!("Tree: {:#?}", tree);
|
println!("Tree: {tree:#?}");
|
||||||
assert_eq!(tree.size(), 4);
|
assert_eq!(tree.size(), 4);
|
||||||
assert_eq!(tree.height(parent), Some(0));
|
assert_eq!(tree.height(parent), Some(0));
|
||||||
assert_eq!(tree.height(child), Some(1));
|
assert_eq!(tree.height(child), Some(1));
|
||||||
@@ -475,7 +475,7 @@ fn deletion() {
|
|||||||
let after = tree.create_node(3);
|
let after = tree.create_node(3);
|
||||||
tree.insert_after(child, after);
|
tree.insert_after(child, after);
|
||||||
|
|
||||||
println!("Tree: {:#?}", tree);
|
println!("Tree: {tree:#?}");
|
||||||
assert_eq!(tree.size(), 4);
|
assert_eq!(tree.size(), 4);
|
||||||
assert_eq!(tree.height(parent), Some(0));
|
assert_eq!(tree.height(parent), Some(0));
|
||||||
assert_eq!(tree.height(child), Some(1));
|
assert_eq!(tree.height(child), Some(1));
|
||||||
@@ -492,7 +492,7 @@ fn deletion() {
|
|||||||
|
|
||||||
tree.remove(child);
|
tree.remove(child);
|
||||||
|
|
||||||
println!("Tree: {:#?}", tree);
|
println!("Tree: {tree:#?}");
|
||||||
assert_eq!(tree.size(), 3);
|
assert_eq!(tree.size(), 3);
|
||||||
assert_eq!(tree.height(parent), Some(0));
|
assert_eq!(tree.height(parent), Some(0));
|
||||||
assert_eq!(tree.height(before), Some(1));
|
assert_eq!(tree.height(before), Some(1));
|
||||||
@@ -507,7 +507,7 @@ fn deletion() {
|
|||||||
|
|
||||||
tree.remove(before);
|
tree.remove(before);
|
||||||
|
|
||||||
println!("Tree: {:#?}", tree);
|
println!("Tree: {tree:#?}");
|
||||||
assert_eq!(tree.size(), 2);
|
assert_eq!(tree.size(), 2);
|
||||||
assert_eq!(tree.height(parent), Some(0));
|
assert_eq!(tree.height(parent), Some(0));
|
||||||
assert_eq!(tree.height(after), Some(1));
|
assert_eq!(tree.height(after), Some(1));
|
||||||
@@ -519,7 +519,7 @@ fn deletion() {
|
|||||||
|
|
||||||
tree.remove(after);
|
tree.remove(after);
|
||||||
|
|
||||||
println!("Tree: {:#?}", tree);
|
println!("Tree: {tree:#?}");
|
||||||
assert_eq!(tree.size(), 1);
|
assert_eq!(tree.size(), 1);
|
||||||
assert_eq!(tree.height(parent), Some(0));
|
assert_eq!(tree.height(parent), Some(0));
|
||||||
assert_eq!(*tree.get(parent).unwrap(), 0);
|
assert_eq!(*tree.get(parent).unwrap(), 0);
|
||||||
@@ -562,7 +562,7 @@ fn get_node_children_mut() {
|
|||||||
for (i, child) in children.enumerate() {
|
for (i, child) in children.enumerate() {
|
||||||
assert_eq!(*child, i + 1);
|
assert_eq!(*child, i + 1);
|
||||||
}
|
}
|
||||||
println!("Parent: {:#?}", parent);
|
println!("Parent: {parent:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -574,7 +574,7 @@ fn get_many_mut_unchecked() {
|
|||||||
|
|
||||||
let all =
|
let all =
|
||||||
unsafe { slab.get_many_mut_unchecked([parent, child, grandchild].into_iter()) }.unwrap();
|
unsafe { slab.get_many_mut_unchecked([parent, child, grandchild].into_iter()) }.unwrap();
|
||||||
println!("All: {:#?}", all);
|
println!("All: {all:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ fn persist_removes() {
|
|||||||
let mut rdom: RealDom<Empty> = RealDom::new();
|
let mut rdom: RealDom<Empty> = RealDom::new();
|
||||||
|
|
||||||
let build = vdom.rebuild();
|
let build = vdom.rebuild();
|
||||||
println!("{:#?}", build);
|
println!("{build:#?}");
|
||||||
let _to_update = rdom.apply_mutations(build);
|
let _to_update = rdom.apply_mutations(build);
|
||||||
|
|
||||||
// this will end on the node that is removed
|
// this will end on the node that is removed
|
||||||
@@ -400,7 +400,7 @@ fn persist_removes() {
|
|||||||
|
|
||||||
vdom.mark_dirty(ScopeId(0));
|
vdom.mark_dirty(ScopeId(0));
|
||||||
let update = vdom.render_immediate();
|
let update = vdom.render_immediate();
|
||||||
println!("{:#?}", update);
|
println!("{update:#?}");
|
||||||
iter1.prune(&update, &rdom);
|
iter1.prune(&update, &rdom);
|
||||||
iter2.prune(&update, &rdom);
|
iter2.prune(&update, &rdom);
|
||||||
let _to_update = rdom.apply_mutations(update);
|
let _to_update = rdom.apply_mutations(update);
|
||||||
|
|||||||
@@ -20,12 +20,7 @@ impl ParentDepState for BlablaState {
|
|||||||
const NODE_MASK: NodeMask =
|
const NODE_MASK: NodeMask =
|
||||||
NodeMask::new_with_attrs(AttributeMask::Static(&sorted_str_slice!(["blabla",])));
|
NodeMask::new_with_attrs(AttributeMask::Static(&sorted_str_slice!(["blabla",])));
|
||||||
|
|
||||||
fn reduce<'a>(
|
fn reduce(&mut self, _node: NodeView, _parent: Option<(&Self,)>, _ctx: &Self::Ctx) -> bool {
|
||||||
&mut self,
|
|
||||||
_node: NodeView,
|
|
||||||
_parent: Option<(&'a Self,)>,
|
|
||||||
_ctx: &Self::Ctx,
|
|
||||||
) -> bool {
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,5 @@ fn main() {
|
|||||||
|
|
||||||
let out = dioxus_autofmt::write_block_out(body).unwrap();
|
let out = dioxus_autofmt::write_block_out(body).unwrap();
|
||||||
|
|
||||||
println!("{}", out);
|
println!("{out}");
|
||||||
}
|
}
|
||||||
@@ -193,7 +193,7 @@ pub struct FormattedSegment {
|
|||||||
impl ToTokens for FormattedSegment {
|
impl ToTokens for FormattedSegment {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||||
let (fmt, seg) = (&self.format_args, &self.segment);
|
let (fmt, seg) = (&self.format_args, &self.segment);
|
||||||
let fmt = format!("{{0:{}}}", fmt);
|
let fmt = format!("{{0:{fmt}}}");
|
||||||
tokens.append_all(quote! {
|
tokens.append_all(quote! {
|
||||||
format_args!(#fmt, #seg)
|
format_args!(#fmt, #seg)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ impl StringCache {
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
cur_path.push(root_idx);
|
cur_path.push(root_idx);
|
||||||
write!(chain, "<{}", tag)?;
|
write!(chain, "<{tag}")?;
|
||||||
for attr in *attrs {
|
for attr in *attrs {
|
||||||
match attr {
|
match attr {
|
||||||
TemplateAttribute::Static { name, value, .. } => {
|
TemplateAttribute::Static { name, value, .. } => {
|
||||||
write!(chain, " {}=\"{}\"", name, value)?;
|
write!(chain, " {name}=\"{value}\"")?;
|
||||||
}
|
}
|
||||||
TemplateAttribute::Dynamic { id: index } => {
|
TemplateAttribute::Dynamic { id: index } => {
|
||||||
chain.segments.push(Segment::Attr(*index))
|
chain.segments.push(Segment::Attr(*index))
|
||||||
@@ -78,11 +78,11 @@ impl StringCache {
|
|||||||
for child in *children {
|
for child in *children {
|
||||||
Self::recurse(child, cur_path, root_idx, chain)?;
|
Self::recurse(child, cur_path, root_idx, chain)?;
|
||||||
}
|
}
|
||||||
write!(chain, "</{}>", tag)?;
|
write!(chain, "</{tag}>")?;
|
||||||
}
|
}
|
||||||
cur_path.pop();
|
cur_path.pop();
|
||||||
}
|
}
|
||||||
TemplateNode::Text { text } => write!(chain, "{}", text)?,
|
TemplateNode::Text { text } => write!(chain, "{text}")?,
|
||||||
TemplateNode::Dynamic { id: idx } | TemplateNode::DynamicText { id: idx } => {
|
TemplateNode::Dynamic { id: idx } | TemplateNode::DynamicText { id: idx } => {
|
||||||
chain.segments.push(Segment::Node(*idx))
|
chain.segments.push(Segment::Node(*idx))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ impl Renderer {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Segment::PreRendered(contents) => write!(buf, "{}", contents)?,
|
Segment::PreRendered(contents) => write!(buf, "{contents}")?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,10 +115,7 @@ impl RinkWidget for &TuiNode {
|
|||||||
[0, 1] => Direction::Down,
|
[0, 1] => Direction::Down,
|
||||||
[0, -1] => Direction::Up,
|
[0, -1] => Direction::Up,
|
||||||
[a, b] => {
|
[a, b] => {
|
||||||
panic!(
|
panic!("draw({before:?} {current:?} {after:?}) {a}, {b} no cell adjacent")
|
||||||
"draw({:?} {:?} {:?}) {}, {} no cell adjacent",
|
|
||||||
before, current, after, a, b
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let end_dir = match [after[0] - current[0], after[1] - current[1]] {
|
let end_dir = match [after[0] - current[0], after[1] - current[1]] {
|
||||||
@@ -127,10 +124,7 @@ impl RinkWidget for &TuiNode {
|
|||||||
[0, 1] => Direction::Down,
|
[0, 1] => Direction::Down,
|
||||||
[0, -1] => Direction::Up,
|
[0, -1] => Direction::Up,
|
||||||
[a, b] => {
|
[a, b] => {
|
||||||
panic!(
|
panic!("draw({before:?} {current:?} {after:?}) {a}, {b} no cell adjacent")
|
||||||
"draw({:?} {:?} {:?}) {}, {} no cell adjacent",
|
|
||||||
before, current, after, a, b
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -151,10 +145,7 @@ impl RinkWidget for &TuiNode {
|
|||||||
[Direction::Left, Direction::Up] => symbols.bottom_right,
|
[Direction::Left, Direction::Up] => symbols.bottom_right,
|
||||||
[Direction::Left, Direction::Right] => symbols.horizontal,
|
[Direction::Left, Direction::Right] => symbols.horizontal,
|
||||||
[Direction::Left, Direction::Down] => symbols.top_right,
|
[Direction::Left, Direction::Down] => symbols.top_right,
|
||||||
_ => panic!(
|
_ => panic!("{before:?} {current:?} {after:?} cannont connect cell to itself"),
|
||||||
"{:?} {:?} {:?} cannont connect cell to itself",
|
|
||||||
before, current, after
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
.to_string();
|
.to_string();
|
||||||
buf.set(
|
buf.set(
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ fn rehydrates() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.body()
|
.body()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_inner_html(&format!("<div id='main'>{}</div>", out));
|
.set_inner_html(&format!("<div id='main'>{out}</div>"));
|
||||||
|
|
||||||
dioxus_web::launch_cfg(app, Config::new().hydrate(true));
|
dioxus_web::launch_cfg(app, Config::new().hydrate(true));
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user