lazy_bastard

Crates.iolazy_bastard
lib.rslazy_bastard
version0.1.6
sourcesrc
created_at2024-10-09 11:07:50.548663
updated_at2024-10-13 06:30:38.370635
descriptionA helpfull macro because writeing a seperate Default function is too much effort
homepage
repositoryhttps://github.com/zachdedoo13/lazy_bastard
max_upload_size
id1402300
size9,550
(zachdedoo13)

documentation

README

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
             },
          }
       }
    }

Commit count: 19

cargo fmt