diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..39b63bf --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,11 @@ +# Minky rustfmt +unstable_features = true +format_macro_bodies = true +format_macro_matchers = true +imports_layout = "HorizontalVertical" +imports_granularity = "Crate" +overflow_delimited_expr = true +reorder_impl_items = true +reorder_imports = true +group_imports = "StdExternalCrate" +use_field_init_shorthand = true diff --git a/src/main.rs b/src/main.rs index fae7185..6c23977 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,15 +2,17 @@ #[macro_use] extern crate tracing; +use std::sync::{atomic::AtomicU64, Arc}; + use axum::{response::Html, routing::get}; use tracing::level_filters::LevelFilter; use tracing_subscriber::layer::SubscriberExt; -use vespid::*; +use vespid::{axum_compat::render, *}; #[component] fn Shell(children: String) -> String { info!("Index"); - html! { + view! { @@ -26,13 +28,15 @@ fn Shell(children: String) -> String { } async fn index() -> Html { - vespid::axum_compat::render(async move { - html! { + render(async move { + view! {

"Hello to Crusto!"

"Index"

- -
+ + + +
} @@ -54,16 +58,13 @@ async fn main() -> eyre::Result<()> { .with(tracing_subscriber::fmt::layer()), )?; + let amount_of_refreshes = Arc::new(AtomicU64::new(0)); let app = axum::Router::new().route("/", get(index)).route("/widget", get(|| async move { - let ts = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_secs(); - vespid::axum_compat::render(async move { - html! { -
+ render(async move { + view! { +

"Widget"

-

{ts}

+

{amount_of_refreshes.fetch_add(1, std::sync::atomic::Ordering::Relaxed)}

} }).await diff --git a/vespid/macros/src/lib.rs b/vespid/macros/src/lib.rs index 434caed..37812da 100644 --- a/vespid/macros/src/lib.rs +++ b/vespid/macros/src/lib.rs @@ -4,18 +4,30 @@ use proc_macro::TokenStream; use proc_macro2_diagnostics::Diagnostic; use quote::{quote, quote_spanned, ToTokens}; use rstml::{ - node::{KeyedAttribute, Node, NodeAttribute, NodeElement, NodeName}, Infallible, Parser, ParserConfig + node::{KeyedAttribute, Node, NodeAttribute, NodeElement, NodeName}, + Infallible, + Parser, + ParserConfig, +}; +use syn::{ + parse::Parse, + parse_quote, + punctuated::Punctuated, + spanned::Spanned, + Expr, + ExprLit, + FnArg, + ItemStruct, + Token, }; -use syn::punctuated::Punctuated; -use syn::{parse::Parse, parse_quote, spanned::Spanned, Expr, ExprLit, FnArg, ItemStruct, Token}; #[proc_macro] -pub fn html(tokens: TokenStream) -> TokenStream { +pub fn view(tokens: TokenStream) -> TokenStream { html_inner(tokens, false) } #[proc_macro] -pub fn html_ide(tokens: TokenStream) -> TokenStream { +pub fn view_docs(tokens: TokenStream) -> TokenStream { html_inner(tokens, true) } diff --git a/vespid/src/axum_compat.rs b/vespid/src/axum_compat.rs index abf8139..956820f 100644 --- a/vespid/src/axum_compat.rs +++ b/vespid/src/axum_compat.rs @@ -1,5 +1,6 @@ -use axum::response::Html; use std::{future::Future, sync::OnceLock, thread::available_parallelism}; + +use axum::response::Html; use tokio_util::task::LocalPoolHandle; use crate::context; diff --git a/vespid/src/lib.rs b/vespid/src/lib.rs index ff63718..4d48e50 100644 --- a/vespid/src/lib.rs +++ b/vespid/src/lib.rs @@ -18,7 +18,7 @@ pub mod axum_compat; pub use vespid_macros::*; -#[doc(hidden)] -pub extern crate typed_builder; #[doc(hidden)] pub extern crate html_escape; +#[doc(hidden)] +pub extern crate typed_builder; diff --git a/vespid/src/render.rs b/vespid/src/render.rs index 06ca52c..ea67c0f 100644 --- a/vespid/src/render.rs +++ b/vespid/src/render.rs @@ -6,8 +6,18 @@ use std::{ io::ErrorKind, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, num::{ - NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128, - NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, + NonZeroI128, + NonZeroI16, + NonZeroI32, + NonZeroI64, + NonZeroI8, + NonZeroIsize, + NonZeroU128, + NonZeroU16, + NonZeroU32, + NonZeroU64, + NonZeroU8, + NonZeroUsize, }, rc::Rc, sync::{