chore: initial draft of proc macros
This commit is contained in:
29
Cargo.lock
generated
29
Cargo.lock
generated
@@ -1634,9 +1634,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.103"
|
version = "1.0.106"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
|
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@@ -1736,9 +1736,26 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_more",
|
"derive_more",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
|
"python-utils-macros",
|
||||||
"snafu",
|
"snafu",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "python-utils-macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"python-utils-macros-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "python-utils-macros-impl"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quick_cache"
|
name = "quick_cache"
|
||||||
version = "0.6.18"
|
version = "0.6.18"
|
||||||
@@ -1751,9 +1768,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.42"
|
version = "1.0.46"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
|
checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@@ -2198,9 +2215,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.111"
|
version = "2.0.118"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
|
checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ members = [
|
|||||||
"persisted",
|
"persisted",
|
||||||
"protocol",
|
"protocol",
|
||||||
"python-utils",
|
"python-utils",
|
||||||
|
"python-utils-macros",
|
||||||
|
"python-utils-macros-impl",
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
|
|||||||
9
python-utils-macros-impl/Cargo.toml
Normal file
9
python-utils-macros-impl/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "python-utils-macros-impl"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
proc-macro2 = "1.0.106"
|
||||||
|
quote = "1.0.46"
|
||||||
|
syn = "2.0.118"
|
||||||
17
python-utils-macros-impl/src/lib.rs
Normal file
17
python-utils-macros-impl/src/lib.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
use proc_macro2::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
use syn::{DeriveInput, parse_macro_input};
|
||||||
|
|
||||||
|
pub fn py_from_str(input: TokenStream) -> TokenStream {
|
||||||
|
let derive_input: DeriveInput = parse_macro_input!(input);
|
||||||
|
|
||||||
|
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||||
|
|
||||||
|
let expanded = quote! {
|
||||||
|
impl #impl_generics MyTrait for #name #ty_generics #where_clause {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expanded
|
||||||
|
}
|
||||||
11
python-utils-macros/Cargo.toml
Normal file
11
python-utils-macros/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "python-utils-macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
license.workspace = true
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
python-utils-macros-impl = { path = "../python-utils-macros-impl" }
|
||||||
6
python-utils-macros/src/lib.rs
Normal file
6
python-utils-macros/src/lib.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
use proc_macro::proc_macro_derive;
|
||||||
|
|
||||||
|
#[proc_macro_derive(PyFromStr)]
|
||||||
|
pub fn py_from_str(input: TokenStream) -> TokenStream {
|
||||||
|
python_utils_macros_impl::py_from_str(input.into()).into()
|
||||||
|
}
|
||||||
@@ -7,4 +7,5 @@ license = { workspace = true }
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
derive_more = { workspace = true }
|
derive_more = { workspace = true }
|
||||||
pyo3 = { workspace = true }
|
pyo3 = { workspace = true }
|
||||||
|
python-utils-macros = { path = "../python-utils-macros" }
|
||||||
snafu = { workspace = true }
|
snafu = { workspace = true }
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ use pyo3::{
|
|||||||
};
|
};
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
|
pub use python_utils_macros::PyFromStr;
|
||||||
|
|
||||||
pub mod none;
|
pub mod none;
|
||||||
pub use none::IsNone;
|
pub use none::IsNone;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user