dyn-clonable-impl-0.9.2/.cargo_vcs_info.json0000644000000001570000000000100143550ustar { "git": { "sha1": "7ec332d7915c226bc59a4e5979e0490422874a89" }, "path_in_vcs": "dyn-clonable-impl" }dyn-clonable-impl-0.9.2/.gitignore000064400000000000000000000000361046102023000151310ustar 00000000000000/target **/*.rs.bk Cargo.lock dyn-clonable-impl-0.9.2/Cargo.toml0000644000000020620000000000100123500ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "dyn-clonable-impl" version = "0.9.2" authors = ["Jacob Brown "] build = false autobins = false autoexamples = false autotests = false autobenches = false description = "Attribute wrapper for dyn-clone" readme = "README.md" license = "MIT" repository = "https://github.com/kardeiz/objekt-clonable" [lib] name = "dyn_clonable_impl" path = "src/lib.rs" proc-macro = true [dependencies.proc-macro2] version = "1.0" [dependencies.quote] version = "1.0" [dependencies.syn] version = "2.0" features = ["full"] [dev-dependencies.dyn-clone] version = "1.0" dyn-clonable-impl-0.9.2/Cargo.toml.orig000064400000000000000000000006611046102023000160340ustar 00000000000000[package] authors = ["Jacob Brown "] edition = "2018" name = "dyn-clonable-impl" version = "0.9.2" description = "Attribute wrapper for dyn-clone" license = "MIT" repository = "https://github.com/kardeiz/objekt-clonable" readme = "../README.md" [dependencies] proc-macro2 = "1.0" quote = "1.0" [dependencies.syn] features = ["full"] version = "2.0" [dev-dependencies] dyn-clone = "1.0" [lib] proc-macro = true dyn-clonable-impl-0.9.2/README.md000064400000000000000000000005441046102023000144240ustar 00000000000000# dyn-clonable Provides a proc_macro attribute wrapper for [dyn-clone](https://docs.rs/dyn-clone/*/dyn_clone/). # Usage ```rust use dyn_clonable::*; #[clonable] trait MyTrait: Clone { fn recite(&self); } ``` For additional information, see [dtolnay's](https://github.com/dtolnay) [dyn-clone](https://docs.rs/dyn-clone/*/dyn_clone/). License: MIT dyn-clonable-impl-0.9.2/src/lib.rs000064400000000000000000000022301046102023000150420ustar 00000000000000extern crate proc_macro; use proc_macro::TokenStream; use quote::quote; use syn::*; #[proc_macro_attribute] pub fn clonable(_attrs: TokenStream, item: TokenStream) -> TokenStream { let mut item_trait = parse_macro_input!(item as ItemTrait); let item_trait_ident = &item_trait.ident; let cloneish_paths = &[quote!(Clone), quote!(std::clone::Clone), quote!(::std::clone::Clone)]; if let Some(path) = item_trait .supertraits .iter_mut() .filter_map(|x| match x { TypeParamBound::Trait(y) => Some(y), _ => None }) .map(|x| &mut x.path) .find(|x| { let s = quote!(#x).to_string(); cloneish_paths.iter().any(|y| y.to_string() == s) }) { *path = parse_quote!(dyn_clonable::dyn_clone::DynClone); } else { panic!("`Clone` must be present in trait supertrait list"); } let (impl_generics, ty_generics, where_clause) = item_trait.generics.split_for_impl(); (quote! { #item_trait dyn_clonable::dyn_clone::clone_trait_object!(#impl_generics #item_trait_ident #ty_generics #where_clause); }) .into() }