diff --git a/Cargo.toml b/Cargo.toml index 763926368..744a8e6cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,41 +34,39 @@ members = [ # libraries "meta", "router", - "routing", "is_server", - "routing_macro", + "router_macro", "any_error", ] exclude = ["benchmarks", "examples"] [workspace.package] -version = "0.6.13" +version = "0.7.0-preview" rust-version = "1.75" [workspace.dependencies] -any_error = { path = "./any_error/" } -any_spawner = { path = "./any_spawner/" } -const_str_slice_concat = { path = "./const_str_slice_concat" } +any_error = { path = "./any_error/", version = "0.1" } +any_spawner = { path = "./any_spawner/", version = "0.1" } +const_str_slice_concat = { path = "./const_str_slice_concat", version = "0.1" } either_of = { path = "./either_of/" } hydration_context = { path = "./hydration_context" } -leptos = { path = "./leptos", version = "0.6.5" } -leptos_config = { path = "./leptos_config", version = "0.6.5" } -leptos_dom = { path = "./leptos_dom", version = "0.6.5" } -leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.6.5" } -leptos_integration_utils = { path = "./integrations/utils", version = "0.6.5" } -leptos_macro = { path = "./leptos_macro", version = "0.6.5" } -leptos_reactive = { path = "./leptos_reactive", version = "0.6.5" } -leptos_router = { path = "./router", version = "0.6.5" } -leptos_server = { path = "./leptos_server", version = "0.6.5" } -leptos_meta = { path = "./meta", version = "0.6.5" } -oco = { path = "./oco" } +leptos = { path = "./leptos", version = "0.7.0-preview" } +leptos_config = { path = "./leptos_config", version = "0.7.0-preview" } +leptos_dom = { path = "./leptos_dom", version = "0.7.0-preview" } +leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.7.0-preview" } +leptos_integration_utils = { path = "./integrations/utils", version = "0.7.0-preview" } +leptos_macro = { path = "./leptos_macro", version = "0.7.0-preview" } +leptos_reactive = { path = "./leptos_reactive", version = "0.7.0-preview" } +leptos_router = { path = "./router", version = "0.7.0-preview" } +leptos_server = { path = "./leptos_server", version = "0.7.0-preview" } +leptos_meta = { path = "./meta", version = "0.7.0-preview" } +oco_ref = { path = "./oco", version = "0.2" } or_poisoned = { path = "./or_poisoned" } reactive_graph = { path = "./reactive_graph" } -routing = { path = "./routing" } -server_fn = { path = "./server_fn", version = "0.6.5" } -server_fn_macro = { path = "./server_fn_macro", version = "0.6.5" } -server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.6" } -tachys = { path = "./tachys" } +server_fn = { path = "./server_fn", version = "0.7.0-preview" } +server_fn_macro = { path = "./server_fn_macro", version = "0.7.0-preview" } +server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.7.0-preview" } +tachys = { path = "./tachys", version = "0.1" } [profile.release] codegen-units = 1 diff --git a/any_error/Cargo.toml b/any_error/Cargo.toml index 7edd5f3bd..5143720aa 100644 --- a/any_error/Cargo.toml +++ b/any_error/Cargo.toml @@ -1,7 +1,13 @@ [package] name = "any_error" edition = "2021" -version.workspace = true +version = "0.1.0" +authors = ["Greg Johnston"] +license = "MIT" +readme = "../README.md" +repository = "https://github.com/leptos-rs/leptos" +description = "Utilities for wrapping, throwing, and catching errors." +rust-version.workspace = true [dependencies] pin-project-lite = "0.2" diff --git a/any_error/Makefile.toml b/any_error/Makefile.toml new file mode 100644 index 000000000..3d822c68d --- /dev/null +++ b/any_error/Makefile.toml @@ -0,0 +1 @@ +extend = { path = "../cargo-make/main.toml" } diff --git a/any_error/README.md b/any_error/README.md new file mode 100644 index 000000000..666a13bba --- /dev/null +++ b/any_error/README.md @@ -0,0 +1,2 @@ +A utility library for wrapping arbitrary errors, and for “throwing” errors in a way +that can be caught by user-defined error hooks. diff --git a/any_error/src/lib.rs b/any_error/src/lib.rs index 6d4d22fb2..1ab9af4a7 100644 --- a/any_error/src/lib.rs +++ b/any_error/src/lib.rs @@ -1,3 +1,9 @@ +#![forbid(unsafe_code)] +#![deny(missing_docs)] + +//! A utility library for wrapping arbitrary errors, and for “throwing” errors in a way +//! that can be caught by user-defined error hooks. + use std::{ cell::RefCell, error, diff --git a/any_spawner/Cargo.toml b/any_spawner/Cargo.toml index 403e60f6e..74e1c1bbf 100644 --- a/any_spawner/Cargo.toml +++ b/any_spawner/Cargo.toml @@ -1,13 +1,20 @@ [package] name = "any_spawner" edition = "2021" -version.workspace = true +version = "0.1.0" +authors = ["Greg Johnston"] +license = "MIT" +readme = "../README.md" +repository = "https://github.com/leptos-rs/leptos" +description = "Spawn asynchronous tasks in an executor-independent way." [dependencies] futures = "0.3" glib = { version = "0.19", optional = true } thiserror = "1" -tokio = { version = "1", optional = true, default-features = false, features = ["rt"] } +tokio = { version = "1", optional = true, default-features = false, features = [ + "rt", +] } tracing = { version = "0.1", optional = true } wasm-bindgen-futures = { version = "0.4", optional = true } diff --git a/any_spawner/README.md b/any_spawner/README.md new file mode 100644 index 000000000..e3c85d2cc --- /dev/null +++ b/any_spawner/README.md @@ -0,0 +1,26 @@ +This crate makes it easier to write asynchronous code that is executor-agnostic, by providing a +utility that can be used to spawn tasks in a variety of executors. + +It only supports single executor per program, but that executor can be set at runtime, anywhere +in your crate (or an application that depends on it). + +This can be extended to support any executor or runtime that supports spawning [`Future`]s. + +This is a least common denominator implementation in many ways. Limitations include: + +- setting an executor is a one-time, global action +- no "join handle" or other result is returned from the spawn +- the `Future` must output `()` + +```rust +use any_spawner::Executor; + +Executor::init_futures_executor() + .expect("executor should only be initialized once"); + +// spawn a thread-safe Future +Executor::spawn(async { /* ... */ }); + +// spawn a Future that is !Send +Executor::spawn_local(async { /* ... */ }); +``` diff --git a/const_str_slice_concat/Cargo.toml b/const_str_slice_concat/Cargo.toml index 16cbc64b8..c61659264 100644 --- a/const_str_slice_concat/Cargo.toml +++ b/const_str_slice_concat/Cargo.toml @@ -1,8 +1,12 @@ [package] name = "const_str_slice_concat" -version = "0.1.0" edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +version = "0.1.0" +authors = ["Greg Johnston"] +license = "MIT" +readme = "../README.md" +repository = "https://github.com/leptos-rs/leptos" +description = "Utilities for const concatenation of string slices." +rust-version.workspace = true [dependencies] diff --git a/const_str_slice_concat/src/lib.rs b/const_str_slice_concat/src/lib.rs index 6a6153263..1197d6a8f 100644 --- a/const_str_slice_concat/src/lib.rs +++ b/const_str_slice_concat/src/lib.rs @@ -1,4 +1,8 @@ #![no_std] +#![forbid(unsafe_code)] +#![deny(missing_docs)] + +//! Utilities for const concatenation of string slices. pub(crate) const MAX_TEMPLATE_SIZE: usize = 4096; @@ -13,7 +17,7 @@ pub const fn str_from_buffer(buf: &[u8; MAX_TEMPLATE_SIZE]) -> &str { } } -/// Concatenates any number of static strings in a single one. +/// Concatenates any number of static strings into a single array. // credit to Rainer Stropek, "Constant fun," Rust Linz, June 2022 pub const fn const_concat( strs: &'static [&'static str], diff --git a/either_of/Cargo.toml b/either_of/Cargo.toml index 0b6a8a176..9d10cb32d 100644 --- a/either_of/Cargo.toml +++ b/either_of/Cargo.toml @@ -1,7 +1,13 @@ [package] name = "either_of" edition = "2021" -version.workspace = true +version = "0.1.0" +authors = ["Greg Johnston"] +license = "MIT" +readme = "../README.md" +repository = "https://github.com/leptos-rs/leptos" +description = "Utilities for working with enumerated types that contain one of 2..n other types." +rust-version.workspace = true [dependencies] pin-project-lite = "0.2" diff --git a/either_of/README.md b/either_of/README.md new file mode 100644 index 000000000..2c397be10 --- /dev/null +++ b/either_of/README.md @@ -0,0 +1 @@ +Utilities for working with enumerated types that contain one of `2..n` other types. diff --git a/either_of/src/lib.rs b/either_of/src/lib.rs index 8eef3b79e..e0a34650c 100644 --- a/either_of/src/lib.rs +++ b/either_of/src/lib.rs @@ -1,4 +1,7 @@ #![no_std] +#![forbid(unsafe_code)] + +//! Utilities for working with enumerated types that contain one of `2..n` other types. use core::{ fmt::Display, diff --git a/examples/router/Cargo.toml b/examples/router/Cargo.toml index 52a761bc8..5203ae300 100644 --- a/examples/router/Cargo.toml +++ b/examples/router/Cargo.toml @@ -13,7 +13,7 @@ panic = "abort" console_log = "1" log = "0.4" leptos = { path = "../../leptos", features = ["csr"] } #, "tracing"] } -routing = { path = "../../routing" } #, features = ["tracing"] } +leptos_router = { path = "../../router" } #, features = ["tracing"] } #leptos_router = { path = "../../router", features = ["csr", "nightly"] } serde = { version = "1", features = ["derive"] } futures = "0.3" diff --git a/examples/ssr_modes_axum/Cargo.toml b/examples/ssr_modes_axum/Cargo.toml index 8b7d3ec34..21005b215 100644 --- a/examples/ssr_modes_axum/Cargo.toml +++ b/examples/ssr_modes_axum/Cargo.toml @@ -10,17 +10,21 @@ crate-type = ["cdylib", "rlib"] console_error_panic_hook = "0.1" console_log = "1" lazy_static = "1" -leptos = { path = "../../leptos", features = ["nightly"] } +leptos = { path = "../../leptos", features = ["nightly", "hydration"] } leptos_meta = { path = "../../meta" } leptos_axum = { path = "../../integrations/axum", optional = true } -routing = { path = "../../routing" } +leptos_router = { path = "../../router" } log = "0.4" serde = { version = "1", features = ["derive"] } thiserror = "1" axum = { version = "0.7", optional = true } tower = { version = "0.4", optional = true } tower-http = { version = "0.5", features = ["fs"], optional = true } -tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"], optional = true } +tokio = { version = "1", features = [ + "rt-multi-thread", + "macros", + "time", +], optional = true } wasm-bindgen = "0.2" [features] @@ -33,9 +37,12 @@ ssr = [ "leptos/ssr", "leptos_meta/ssr", "dep:leptos_axum", - "routing/ssr", + "leptos_router/ssr", ] +[profile.release] +panic = "abort" + [profile.wasm-release] inherits = "release" opt-level = 'z' diff --git a/examples/ssr_modes_axum/src/app.rs b/examples/ssr_modes_axum/src/app.rs index 2d1bfe237..24c6dfcbc 100644 --- a/examples/ssr_modes_axum/src/app.rs +++ b/examples/ssr_modes_axum/src/app.rs @@ -5,7 +5,7 @@ use leptos::{ IntoView, Params, Suspense, }; use leptos_meta::*; -use routing::{ +use leptos_router::{ components::{FlatRoutes, Route, Router}, hooks::use_params, params::Params, diff --git a/leptos/Cargo.toml b/leptos/Cargo.toml index f71803f59..7830277fe 100644 --- a/leptos/Cargo.toml +++ b/leptos/Cargo.toml @@ -21,7 +21,7 @@ leptos_reactive = { workspace = true } leptos_server = { workspace = true } leptos_config = { workspace = true } leptos-spin-macro = { version = "0.1", optional = true } -oco = { workspace = true } +oco_ref = { workspace = true } or_poisoned = { workspace = true } paste = "1" rand = { version = "0.8", optional = true } @@ -38,7 +38,6 @@ server_fn = { workspace = true, features = [ "form-redirects", "browser", "url", - "cbor", ] } web-sys = { version = "0.3.63", features = [ "ShadowRoot", @@ -52,10 +51,7 @@ futures = "0.3.30" [features] default = ["serde"] -hydration = [ - "leptos_server/hydration", - "hydration_context/browser", -] +hydration = ["leptos_server/hydration", "hydration_context/browser"] csr = ["leptos_macro/csr", "leptos_reactive/csr"] hydrate = [ "leptos_macro/hydrate", diff --git a/leptos/src/lib.rs b/leptos/src/lib.rs index ad7950b93..52dcfb57a 100644 --- a/leptos/src/lib.rs +++ b/leptos/src/lib.rs @@ -194,7 +194,7 @@ pub use leptos_config as config; #[cfg(feature = "hydrate")] pub use mount::hydrate_body; pub use mount::mount_to_body; -pub use oco; +pub use oco_ref as oco; pub mod from_form_data; pub mod signals { diff --git a/leptos/src/text_prop.rs b/leptos/src/text_prop.rs index 2a08373cb..3d029dacb 100644 --- a/leptos/src/text_prop.rs +++ b/leptos/src/text_prop.rs @@ -1,4 +1,4 @@ -use oco::Oco; +use oco_ref::Oco; use std::sync::Arc; /// Describes a value that is either a static or a reactive string, i.e., diff --git a/leptos_macro/src/params.rs b/leptos_macro/src/params.rs index eafff0cbe..d0b57c41a 100644 --- a/leptos_macro/src/params.rs +++ b/leptos_macro/src/params.rs @@ -19,7 +19,7 @@ pub fn params_impl(ast: &syn::DeriveInput) -> proc_macro::TokenStream { let span = field.span(); quote_spanned! { - span=> #ident: <#ty as ::routing::params::IntoParam>::into_param( + span=> #ident: <#ty as ::leptos_router::params::IntoParam>::into_param( map.get(#field_name_string), #field_name_string )? @@ -32,7 +32,7 @@ pub fn params_impl(ast: &syn::DeriveInput) -> proc_macro::TokenStream { let gen = quote! { impl Params for #name { - fn from_map(map: &::routing::params::ParamsMap) -> Result { + fn from_map(map: &::leptos_router::params::ParamsMap) -> Result { Ok(Self { #(#fields,)* }) diff --git a/meta/Cargo.toml b/meta/Cargo.toml index 3ba10ec94..8aaabd983 100644 --- a/meta/Cargo.toml +++ b/meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leptos_meta" -version = "0.6.13" +version = "0.7.0-preview" edition = "2021" authors = ["Greg Johnston"] license = "MIT" diff --git a/oco/Cargo.toml b/oco/Cargo.toml index 09cb364c9..2085b96b9 100644 --- a/oco/Cargo.toml +++ b/oco/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "oco_ref" +name = "oco_ref" edition = "2021" -version = "0.1.1" +version = "0.2.0" authors = ["Danik Vitek", "Greg Johnston"] license = "MIT" repository = "https://github.com/leptos-rs/leptos" diff --git a/oco/Makefile.toml b/oco/Makefile.toml new file mode 100644 index 000000000..3d822c68d --- /dev/null +++ b/oco/Makefile.toml @@ -0,0 +1 @@ +extend = { path = "../cargo-make/main.toml" } diff --git a/oco/README.md b/oco/README.md index fff8da542..44e12b3c2 100644 --- a/oco/README.md +++ b/oco/README.md @@ -1,31 +1,31 @@ - This module contains the `Oco` (Owned Clones Once) smart pointer, - which is used to store immutable references to values. - This is useful for storing, for example, strings. +This module contains the `Oco` (Owned Clones Once) smart pointer, +which is used to store immutable references to values. +This is useful for storing, for example, strings. - Imagine this as an alternative to [`Cow`] with an additional, reference-counted - branch. +Imagine this as an alternative to [`Cow`] with an additional, reference-counted +branch. - ```rust - use oco_ref::Oco; - use std::rc::Rc; +```rust +use oco_ref::Oco; +use std::sync::Arc; - let static_str = "foo"; - let rc_str: Rc = "bar".into(); - let owned_str: String = "baz".into(); +let static_str = "foo"; +let arc_str: Arc = "bar".into(); +let owned_str: String = "baz".into(); - fn uses_oco(value: impl Into>) { - let mut value = value.into(); +fn uses_oco(value: impl Into>) { + let mut value = value.into(); - // ensures that the value is either a reference, or reference-counted - // O(n) at worst - let clone1 = value.clone_inplace(); + // ensures that the value is either a reference, or reference-counted + // O(n) at worst + let clone1 = value.clone_inplace(); - // these subsequent clones are O(1) - let clone2 = value.clone(); - let clone3 = value.clone(); - } + // these subsequent clones are O(1) + let clone2 = value.clone(); + let clone3 = value.clone(); +} - uses_oco(static_str); - uses_oco(rc_str); - uses_oco(owned_str); - ``` +uses_oco(static_str); +uses_oco(arc_str); +uses_oco(owned_str); +``` diff --git a/oco/src/lib.rs b/oco/src/lib.rs index bcf44ac84..203c6fc51 100644 --- a/oco/src/lib.rs +++ b/oco/src/lib.rs @@ -272,24 +272,6 @@ where } } } - - /// Converts the value into its cheaply-clonable form in place. - /// In other words, if it is currently [`Oco::Owned`], converts into [`Oco::Counted`] - /// in an `O(n)` operation, so that all future clones are `O(1)`. - /// - /// # Examples - /// ``` - /// # use leptos_reactive::oco::Oco; - /// let mut oco = Oco::::Owned("Hello".to_string()); - /// oco.upgrade_inplace(); - /// assert!(oco1.is_counted()); - /// ``` - pub fn upgrade_inplace(&mut self) { - if let Self::Owned(v) = &*self { - let rc = Arc::from(v.borrow()); - *self = Self::Counted(rc); - } - } } impl Default for Oco<'_, T> diff --git a/routing_macro/Cargo.toml b/routing_macro/Cargo.toml deleted file mode 100644 index d5a35feb8..000000000 --- a/routing_macro/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "routing_macro" -edition = "2021" -version.workspace = true - -[lib] -proc-macro = true - -[dependencies] -proc-macro-error = { version = "1", default-features = false } -proc-macro2 = "1" -quote = "1" -syn = { version = "2", features = ["full"] } - -[dev-dependencies] -routing = { workspace = true } diff --git a/routing_macro/src/lib.rs b/routing_macro/src/lib.rs deleted file mode 100644 index 26a95f0ce..000000000 --- a/routing_macro/src/lib.rs +++ /dev/null @@ -1,76 +0,0 @@ -use proc_macro::{TokenStream, TokenTree}; -use quote::{quote, ToTokens}; -use std::borrow::Cow; -use syn::{ - parse::{Parse, ParseStream}, - parse_macro_input, - token::Token, -}; - -#[proc_macro_error::proc_macro_error] -#[proc_macro] -pub fn path(tokens: TokenStream) -> TokenStream { - let mut parser = SegmentParser::new(tokens); - parser.parse_all(); - let segments = Segments(parser.segments); - segments.into_token_stream().into() -} - -#[derive(Debug, PartialEq)] -struct Segments(pub Vec); - -#[derive(Debug, PartialEq)] -enum Segment { - Static(Cow<'static, str>), -} - -struct SegmentParser { - input: proc_macro::token_stream::IntoIter, - current_str: Option, - segments: Vec, -} - -impl SegmentParser { - pub fn new(input: TokenStream) -> Self { - Self { - input: input.into_iter(), - current_str: None, - segments: Vec::new(), - } - } -} - -impl SegmentParser { - pub fn parse_all(&mut self) { - for input in self.input.by_ref() { - match input { - TokenTree::Literal(lit) => { - Self::parse_str( - lit.to_string() - .trim_start_matches(['"', '/']) - .trim_end_matches(['"', '/']), - &mut self.segments, - ); - } - TokenTree::Group(_) => todo!(), - TokenTree::Ident(_) => todo!(), - TokenTree::Punct(_) => todo!(), - } - } - } - - pub fn parse_str(current_str: &str, segments: &mut Vec) { - let mut chars = current_str.chars(); - } -} - -impl ToTokens for Segments { - fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - let children = quote! {}; - if self.0.len() != 1 { - tokens.extend(quote! { (#children) }); - } else { - tokens.extend(children) - } - } -} diff --git a/routing_macro/tests/path.rs b/routing_macro/tests/path.rs deleted file mode 100644 index 5d80fd422..000000000 --- a/routing_macro/tests/path.rs +++ /dev/null @@ -1,9 +0,0 @@ -use routing::StaticSegment; -use routing_macro::path; - -#[test] -fn parses_empty_list() { - let output = path!(""); - assert_eq!(output, ()); - //let segments: Segments = syn::parse(path.into()).unwrap(); -} diff --git a/server_fn/Cargo.toml b/server_fn/Cargo.toml index f3278a37e..3d957f952 100644 --- a/server_fn/Cargo.toml +++ b/server_fn/Cargo.toml @@ -68,7 +68,7 @@ web-sys = { version = "0.3", optional = true, features = [ "ReadableStream", "ReadableStreamDefaultReader", "AbortController", - "AbortSignal" + "AbortSignal", ] } # reqwest client @@ -80,7 +80,7 @@ url = "2" pin-project-lite = "0.2.13" [features] -default = ["json", "cbor"] +default = ["json"] axum-no-default = [ "ssr", "dep:axum", diff --git a/tachys/Cargo.toml b/tachys/Cargo.toml index 40ef51525..c688dfcef 100644 --- a/tachys/Cargo.toml +++ b/tachys/Cargo.toml @@ -11,7 +11,7 @@ either_of = { workspace = true } next_tuple = { path = "../next_tuple" } reactive_graph = { workspace = true, optional = true } slotmap = { version = "1", optional = true } -oco = { workspace = true, optional = true } +oco_ref = { workspace = true, optional = true } once_cell = "1" paste = "1" pin-project-lite = "0.2" @@ -160,6 +160,7 @@ error-hook = [] hydrate = [] islands = [] ssr = [] +oco = ["dep:oco_ref"] nightly = ["reactive_graph/nightly"] testing = ["dep:slotmap"] reactive_graph = ["dep:reactive_graph"] diff --git a/tachys/src/oco.rs b/tachys/src/oco.rs index a9610b8f8..510f1b0eb 100644 --- a/tachys/src/oco.rs +++ b/tachys/src/oco.rs @@ -5,7 +5,7 @@ use crate::{ renderer::{DomRenderer, Renderer}, view::{strings::StrState, Position, PositionState, ToTemplate}, }; -use oco::Oco; +use oco_ref::Oco; use std::future::{ready, Ready}; pub struct OcoStrState {