Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: [crate announcement] nodyn: A Macro for Wrapper Enums with Trait and Method Delegation
[crate announcement] nodyn: A Macro for Wrapper Enums with Trait and Method Delegation
ā rust š 2025-06-13 š¤ surdeus šļø 2Hello Rustaceans,
Iām thrilled to announce nodyn
, a new crate that makes it easy to create wrapper enums for a fixed set of types with automatic From
, TryFrom
, and delegated methods or traits. The nodyn::nodyn!
macro is designed for type-safe, zero-cost polymorphism using enums without the boilerplate.
From<T>
for each variant type and TryFrom<Enum> for T
for non-reference types.count()
, types()
, and type_name()
.nodyn::nodyn! {
#[derive(Debug)]
pub enum Article {
NewsArticle,
SocialPost,
}
impl Summary {
fn summarize(&self) -> String;
}
}
pub trait Summary {
fn summarize(&self) -> String;
}
pub struct NewsArticle { /* fields */ }
impl Summary for NewsArticle {
fn summarize(&self) -> String { "News summary".to_string() }
}
pub struct SocialPost { /* fields */ }
impl Summary for SocialPost {
fn summarize(&self) -> String { "Post summary".to_string() }
}
fn main() {
let article = Article::NewsArticle(NewsArticle {});
assert_eq!(article.summarize(), "News summary");
}
Iād appreciate feedback, use cases, or suggestions for nodyn
.
1 post - 1 participant
š·ļø rust_feed