summaryrefslogtreecommitdiffstats
path: root/libs/hello_macro
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.cc>2026-11-11 17:16:48 +0300
committerhybrid <hybrid@hybridlabs.cc>2026-11-11 17:16:48 +0300
commit9dea46b5e66eb54746b251d8950b2367c49be23d (patch)
treefdebf3880f2f25a1351a220e771da84ea32f07e2 /libs/hello_macro
parent59e457f7d6267ac2591837085b388d7c15ed2004 (diff)
downloadrust-book-9dea46b5e66eb54746b251d8950b2367c49be23d.tar.gz
rust-book-9dea46b5e66eb54746b251d8950b2367c49be23d.tar.bz2
rust-book-9dea46b5e66eb54746b251d8950b2367c49be23d.zip
add: supertraits, ext_traits, pancakes, hello, hello_macromain
Diffstat (limited to '')
-rw-r--r--libs/hello_macro/Cargo.toml6
-rw-r--r--libs/hello_macro/hello_macro_derive/Cargo.toml11
-rw-r--r--libs/hello_macro/hello_macro_derive/src/lib.rs24
-rw-r--r--libs/hello_macro/src/lib.rs3
4 files changed, 44 insertions, 0 deletions
diff --git a/libs/hello_macro/Cargo.toml b/libs/hello_macro/Cargo.toml
new file mode 100644
index 0000000..aaaf3bf
--- /dev/null
+++ b/libs/hello_macro/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "hello_macro"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/libs/hello_macro/hello_macro_derive/Cargo.toml b/libs/hello_macro/hello_macro_derive/Cargo.toml
new file mode 100644
index 0000000..18f0d3f
--- /dev/null
+++ b/libs/hello_macro/hello_macro_derive/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "hello_macro_derive"
+version = "0.1.0"
+edition = "2024"
+
+[lib]
+proc-macro = true
+
+[dependencies]
+syn = "2.0"
+quote = "1.0" \ No newline at end of file
diff --git a/libs/hello_macro/hello_macro_derive/src/lib.rs b/libs/hello_macro/hello_macro_derive/src/lib.rs
new file mode 100644
index 0000000..1eaef1f
--- /dev/null
+++ b/libs/hello_macro/hello_macro_derive/src/lib.rs
@@ -0,0 +1,24 @@
+use proc_macro::TokenStream;
+use quote::quote;
+
+#[proc_macro_derive(HelloMacro)]
+pub fn hello_macro_derive(input: TokenStream) -> TokenStream {
+ // Construct a representation of Rust code as a syntax tree
+ // that we can manipulate.
+ let ast = syn::parse(input).unwrap();
+
+ // Build the trait implementation
+ impl_hello_macro(&ast)
+}
+
+fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream {
+ let name = &ast.ident;
+ let generated = quote! {
+ impl HelloMacro for #name {
+ fn hello_macro() {
+ println!("Hello, Macro! My name is {}!", stringify!(#name));
+ }
+ }
+ };
+ generated.into()
+}
diff --git a/libs/hello_macro/src/lib.rs b/libs/hello_macro/src/lib.rs
new file mode 100644
index 0000000..e747931
--- /dev/null
+++ b/libs/hello_macro/src/lib.rs
@@ -0,0 +1,3 @@
+pub trait HelloMacro {
+ fn hello_macro();
+}