| Crates.io | deki_macros |
| lib.rs | deki_macros |
| version | 0.1.2 |
| created_at | 2024-12-27 06:01:19.281527+00 |
| updated_at | 2025-10-26 03:15:37.87403+00 |
| description | A growing set of macros (tailored to myself)! |
| homepage | |
| repository | https://github.com/dekirisu/deki-rs/ |
| max_upload_size | |
| id | 1496221 |
| size | 15,887 |
Various macros I made and liked to use occasionally!
Basically write this:
enum Object {RedSphere, GreenCube}
match_fns!{
// 1. Define Methods - '&self' is assumed as parameter
[Object]
shape() -> &'static str;
color(brightness:f32) -> &'static str;
// 2. Add Code
[::RedSphere]
shape: "sphere";
color: if brightness > 0.5 {"bright-red"} else {"red"};
[::GreenCube]
shape: "cube";
color: "just-green";
}
Instead of:
impl Object {
pub fn shape(&self) -> &'static str {
match self {
Color::RedSphere => "sphere",
Color::GreenCube => "cube",
}
}
pub fn color(&self, brightness: f32) -> &'static str {
match self {
Color::RedSphere => {
if brightness > 0.5 {"bright-red"} else {"red"}
}
Color::GreenCube => "just-green",
}
}
}
Alternative syntax for implementing trait with ONE required method.
quimp!{StructName
fn clone(&self) -> Self {Self::new(self.0)};
fn default() -> Self {Self::new(100)};
}
Or using this:
#[imp(Struct)]: for a owned Type#[imp(Struct|Trait)]: to impl a singe-method trait#[imp(Struct|*)]: for a foreign Type (generates a new trait)#[imp(Struct)]
fn function(){}
Simple macro that replaces X -> true and O -> false:
xoxo!{match [true,false,true] {
[O,O,O] => "nope",
[O,O,X] => "nope",
[X,O,X] => "YEP!",
[_,_,_] => "nope"
}}