diff --git a/Cargo.toml b/Cargo.toml index 7151a19c4..964ccffa6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ "next_tuple", "or_poisoned", "any_spawner", + "either_of", # core "hydration_context", @@ -31,7 +32,7 @@ members = [ # libraries "meta", - "router", + "router", "either_of", ] exclude = ["benchmarks", "examples"] @@ -42,6 +43,7 @@ rust-version = "1.75" [workspace.dependencies] any_spawner = { path = "./any_spawner/" } const_str_slice_concat = { path = "./const_str_slice_concat" } +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" } diff --git a/either_of/Cargo.toml b/either_of/Cargo.toml new file mode 100644 index 000000000..5482edf30 --- /dev/null +++ b/either_of/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "either_of" +edition = "2021" +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/either_of/src/lib.rs b/either_of/src/lib.rs new file mode 100644 index 000000000..b111fe6dd --- /dev/null +++ b/either_of/src/lib.rs @@ -0,0 +1,44 @@ +#![no_std] + +use core::fmt::Display; + +#[derive(Debug)] +pub enum Either { + Left(A), + Right(B), +} + +macro_rules! tuples { + ($name:ident => $($ty:ident),*) => { + #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] + pub enum $name<$($ty,)*> { + $($ty ($ty),)* + } + + impl<$($ty,)*> Display for $name<$($ty,)*> + where + $($ty: Display,)* + { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + $($name::$ty(this) => this.fmt(f),)* + } + } + } + } +} + +tuples!(EitherOf3 => A, B, C); +tuples!(EitherOf4 => A, B, C, D); +tuples!(EitherOf5 => A, B, C, D, E); +tuples!(EitherOf6 => A, B, C, D, E, F); +tuples!(EitherOf7 => A, B, C, D, E, F, G); +tuples!(EitherOf8 => A, B, C, D, E, F, G, H); +tuples!(EitherOf9 => A, B, C, D, E, F, G, H, I); +tuples!(EitherOf10 => A, B, C, D, E, F, G, H, I, J); +tuples!(EitherOf11 => A, B, C, D, E, F, G, H, I, J, K); +tuples!(EitherOf12 => A, B, C, D, E, F, G, H, I, J, K, L); +tuples!(EitherOf13 => A, B, C, D, E, F, G, H, I, J, K, L, M); +tuples!(EitherOf14 => A, B, C, D, E, F, G, H, I, J, K, L, M, N); +tuples!(EitherOf15 => A, B, C, D, E, F, G, H, I, J, K, L, M, N, O); +tuples!(EitherOf16 => A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P);