| Crates.io | anonymous |
| lib.rs | anonymous |
| version | 0.3.1 |
| created_at | 2025-12-11 15:17:43.191946+00 |
| updated_at | 2025-12-11 15:31:06.9215+00 |
| description | A Rust project template with anonymous macro. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1979897 |
| size | 24,306 |
A Rust library that provides macros for creating anonymous structs, enums, and trait implementations.
Add this to your Cargo.toml:
[dependencies]
anonymous = "0.3.1"
structx!)You can use the structx! macro to create anonymous structs with named fields.
use anonymous::structx;
fn main() {
// Create an anonymous struct
let person = structx! {
derive(Debug);
name: String = "Alice".to_string(),
age: u32 = 30,
};
println!("{:?}", person);
// Output: Anon { name: "Alice", age: 30 }
}
enumx!)You can use the enumx! macro to define ad-hoc enums.
use anonymous::enumx;
fn main() {
// Define a type that can be i32 or String
// Note: .into() is required for conversion
let value: enumx!(i32 | String) = 10.into();
match value {
// Matches based on the order of types
enumx::Enum2::V1(v) => println!("Int: {}", v),
enumx::Enum2::V2(s) => println!("String: {}", s),
}
}
implx!)You can use the implx! macro to create an anonymous struct that implements a specific trait.
use anonymous::implx;
trait Greeter {
fn greet(&self);
}
fn main() {
let p = implx! {
struct { name: String = "Guest".to_string() }
impl Greeter {
fn greet(&self) {
println!("Hello, {}", self.name);
}
}
};
p.greet();
}
structx!: Create structs on the fly with named fields and derive support.enumx!: Define anonymous enums (sum types) inline.implx!: Create anonymous structs implementing a trait with internal state.MPL-2.0