-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add macro easing from implementations * update macro * update docs * allow function strings instead of just paths * docs * update dependencies * auto from/to for (nearly) all contents. also improve asynciterator results * change serde * docs formatting * update enums * typing for attachmentkind * Update src/warp/raygun.rs Co-authored-by: Darius Clark <[email protected]> * Update src/warp/multipass.rs Co-authored-by: Darius Clark <[email protected]> * Merge branch 'main' into auto-convert-macro --------- Co-authored-by: Flemmli97 <[email protected]> Co-authored-by: Darius Clark <[email protected]>
- Loading branch information
1 parent
f12b0a4
commit d21e269
Showing
8 changed files
with
922 additions
and
557 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "macro_utils" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
syn = { version = "2.0.87", features = ["derive", "full"] } | ||
quote = "1.0.37" | ||
proc-macro2 = "1.0.89" | ||
|
||
[lib] | ||
proc-macro = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
extern crate proc_macro2; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
mod wasm_convert; | ||
|
||
/// Easy type conversion between enums and structs of similar structure | ||
/// | ||
/// Also allows specifying a function for conversion for types not implementing From already | ||
/// | ||
/// Fields can accept an attribute with name "from" or "into" representing a conversion function. | ||
/// | ||
/// This value can either be a path to a function or some rust code. | ||
/// | ||
/// The path need to accept a single value of the current type and output the target type | ||
/// | ||
/// Unnamed enum fields are referenced as f_0, f_1... | ||
/// E.g. `"{f_0}.converter_function()"` | ||
/// ``` | ||
/// use macro_utils::FromTo; | ||
/// | ||
/// #[derive(Debug)] | ||
/// pub enum A { | ||
/// SomeValue1, | ||
/// SomeValue2 | ||
/// } | ||
/// | ||
/// #[derive(FromTo, PartialEq, Debug)] | ||
/// #[from_to(A)] | ||
/// pub enum B { | ||
/// SomeValue1, | ||
/// SomeValue2 | ||
/// } | ||
/// | ||
/// assert_eq!(A::SomeValue1, B::SomeValue1.into()); | ||
/// | ||
/// pub struct S1 { | ||
/// x: i64, | ||
/// y: i128 | ||
/// } | ||
/// | ||
/// #[derive(FromTo)] | ||
/// #[from_to(A)] | ||
/// pub struct S2 { | ||
/// x: i64, | ||
/// y: i128 | ||
/// } | ||
/// | ||
/// #[derive(FromTo)] | ||
/// #[from_to(A)] | ||
/// pub struct S3 { | ||
/// // Pass in a custom conversion function. If not provided will use a From implementation | ||
/// #[from_to(from = "converter_function_from", to = "converter_function_to")] | ||
/// // Referencing the struct itself is also possible | ||
/// #[from_to(from = "{value}.x.converter_function()", to = "{value}.x.converter_function()")] | ||
/// x: String, | ||
/// #[from_to(from = "converter_function_from", to = "converter_function_to")] | ||
/// y: String | ||
/// } | ||
/// ``` | ||
#[proc_macro_derive(FromTo, attributes(from_to))] | ||
pub fn from_to(input: TokenStream) -> TokenStream { | ||
wasm_convert::expand(input) | ||
.unwrap_or_else(|e| e.into_compile_error().into()) | ||
.into() | ||
} |
Oops, something went wrong.