From af495bbade18c9492f5e71fb47ce8b98f7bd9080 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Sun, 17 Dec 2023 23:16:06 -0600 Subject: [PATCH 1/2] Split trait_transformer back into its own crate --- Cargo.lock | 10 +++++++ Cargo.toml | 1 + README.md | 2 +- trait-transformer/Cargo.toml | 30 +++++++++++++++++++ .../examples/trait_transformer.rs | 2 +- trait-transformer/src/lib.rs | 17 +++++++++++ .../src/transformer.rs | 0 trait-variant/src/lib.rs | 9 ------ 8 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 trait-transformer/Cargo.toml rename {trait-variant => trait-transformer}/examples/trait_transformer.rs (96%) create mode 100644 trait-transformer/src/lib.rs rename {trait-variant => trait-transformer}/src/transformer.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 7535e65..0bffee7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,6 +134,16 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "trait-transformer" +version = "0.0.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "tokio", +] + [[package]] name = "trait-variant" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 61df904..dc525bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "trait-variant", + "trait-transformer", ] resolver = "2" diff --git a/README.md b/README.md index d2a3e44..30dda26 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Implementers of the trait can choose to implement the variant instead of the ori ## `trait_transformer` -`trait_transformer` does the same thing as `make`, but using experimental nightly-only syntax that depends on the `return_type_notation` feature. It may be used to experiment with new kinds of trait transformations in the future. +`trait_transformer` does the same thing as `trait_variant`, but using experimental nightly-only syntax that depends on the `return_type_notation` feature. It may be used to experiment with new kinds of trait transformations in the future. #### License and usage notes diff --git a/trait-transformer/Cargo.toml b/trait-transformer/Cargo.toml new file mode 100644 index 0000000..c2e77f8 --- /dev/null +++ b/trait-transformer/Cargo.toml @@ -0,0 +1,30 @@ +# Copyright (c) 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +[package] +name = "trait-transformer" +version = "0.0.0" +description = "Utilities for working with impl traits in Rust" +categories = ["asynchronous", "no-std", "rust-patterns"] +keywords = ["async", "trait", "impl"] +license.workspace = true +repository.workspace = true +edition = "2021" + +[lib] +proc-macro = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +proc-macro2 = "1.0" +quote = "1.0" +syn = { version = "2.0", features = ["full"] } + +[dev-dependencies] +tokio = { version = "1", features = ["rt"] } diff --git a/trait-variant/examples/trait_transformer.rs b/trait-transformer/examples/trait_transformer.rs similarity index 96% rename from trait-variant/examples/trait_transformer.rs rename to trait-transformer/examples/trait_transformer.rs index 619514e..80129a0 100644 --- a/trait-variant/examples/trait_transformer.rs +++ b/trait-transformer/examples/trait_transformer.rs @@ -11,7 +11,7 @@ use std::iter; -use trait_variant::trait_transformer; +use trait_transformer::trait_transformer; #[trait_transformer(SendIntFactory: Send)] trait IntFactory { diff --git a/trait-transformer/src/lib.rs b/trait-transformer/src/lib.rs new file mode 100644 index 0000000..89d6b65 --- /dev/null +++ b/trait-transformer/src/lib.rs @@ -0,0 +1,17 @@ +// Copyright (c) 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod transformer; + +#[proc_macro_attribute] +pub fn trait_transformer( + attr: proc_macro::TokenStream, + item: proc_macro::TokenStream, +) -> proc_macro::TokenStream { + transformer::trait_transformer(attr, item) +} diff --git a/trait-variant/src/transformer.rs b/trait-transformer/src/transformer.rs similarity index 100% rename from trait-variant/src/transformer.rs rename to trait-transformer/src/transformer.rs diff --git a/trait-variant/src/lib.rs b/trait-variant/src/lib.rs index f651249..7c03519 100644 --- a/trait-variant/src/lib.rs +++ b/trait-variant/src/lib.rs @@ -8,17 +8,8 @@ #![doc = include_str!("../README.md")] -mod transformer; mod variant; -#[proc_macro_attribute] -pub fn trait_transformer( - attr: proc_macro::TokenStream, - item: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - transformer::trait_transformer(attr, item) -} - #[proc_macro_attribute] pub fn make( attr: proc_macro::TokenStream, From 1c75be23a5f09fd62a94d321e577215a3eae5dc8 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Sun, 17 Dec 2023 23:22:34 -0600 Subject: [PATCH 2/2] Create dedicated README --- README.md | 4 ---- trait-transformer/README.md | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 trait-transformer/README.md diff --git a/README.md b/README.md index 30dda26..a56c042 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,6 @@ Which creates a new `SendIntFactory: IntFactory + Send` trait and additionally b Implementers of the trait can choose to implement the variant instead of the original trait. The macro creates a blanket impl which ensures that any type which implements the variant also implements the original trait. -## `trait_transformer` - -`trait_transformer` does the same thing as `trait_variant`, but using experimental nightly-only syntax that depends on the `return_type_notation` feature. It may be used to experiment with new kinds of trait transformations in the future. - #### License and usage notes Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or diff --git a/trait-transformer/README.md b/trait-transformer/README.md new file mode 100644 index 0000000..3e3b755 --- /dev/null +++ b/trait-transformer/README.md @@ -0,0 +1,3 @@ +## `trait_transformer` + +`trait_transformer` does the same thing as `trait_variant`, but using experimental nightly-only syntax that depends on the `return_type_notation` feature. It may be used to experiment with new kinds of trait transformations in the future.