Crates.io | lazy_bastard |
lib.rs | lazy_bastard |
version | 0.1.6 |
source | src |
created_at | 2024-10-09 11:07:50.548663 |
updated_at | 2024-10-13 06:30:38.370635 |
description | A helpfull macro because writeing a seperate Default function is too much effort |
homepage | |
repository | https://github.com/zachdedoo13/lazy_bastard |
max_upload_size | |
id | 1402300 |
size | 9,550 |
inline defaults for struct definitions if you’re lazy, plus some other stuff, probably.
makes creating simple structs that don’t need a constructor like settings structs much clearer
somewhat second guessing the name, but it’s too late to change it
use lazy_bastard::lazy_bastard;
lazy_bastard!(
#[derive(Clone, Debug)]
pub struct MyStruct<'a> { // lifetime is just for the example
normal: i32 => 100_324,
function_call: String => "test".into(),
automatic: f64, // uses Default::default() instead
scoped: f32 => {
let c: f32 = 1.2;
let v = c.abs().sin().sin().sqrt();
0.1 * v
}
}
);
impl MyStruct {
fn new() -> Self { Self::default() }
}
// Compiles into //
#[derive(Clone, Debug)]
pub struct CompiledStruct<'a> {
normal: i32,
function_call: String,
automatic: f64,
scoped: f32,
}
impl<'a> Default for CompiledStruct<'a> {
fn default() -> Self {
Self {
normal: 100_324,
function_call: ("test".into()),
automatic: Default::default(),
scoped: {
let c: f32 = 1.2;
let v = c.abs().sin().sin().sqrt();
0.1 * v
},
}
}
}