Git Product home page Git Product logo

traitful's Introduction

Traitful

A collection of helper macros for trait patterns

Crates.io Crates.io Crates.io (recent)
Crates.io Docs.rs

License

Copyright © 2023 The Traitful Contributors.

Licensed under any of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as described above, without any additional terms or conditions.

Help

If you want help using or contributing to this library, feel free to send me an email at [email protected].

traitful's People

Contributors

aldaronlau avatar

Stargazers

 avatar

Watchers

 avatar

traitful's Issues

Add `#[default]` macro (or different name)

An attribute macro to create a separate trait that can set default values for associated items, and default blocks for methods and associated functions. Everything that implements the "default" trait will implement the trait.

use traitful::default;

#[default(
    TraitDefault => Default::default(),
    TraitUnimplemented => unimplemented!(),
)]
pub trait Trait {
    fn uwu() -> i32;
}

// becomes:

pub trait Trait {
    fn uwu() -> i32;
}

pub trait TraitDefault {
    fn uwu() -> i32 {
        Default::default()
    }
}

pub trait TraitUnimplemented {
    fn uwu() -> i32 {
        unimplemented!()
    }
}

mod traitful_default__ {
    use super::*;

    impl<T: TraitDefault> Trait for T {
        fn uwu() -> i32 {
            <Self as TraitDefault>::uwu()
        }
    }

    impl<T: TraitUnimplemented> TraitDefault for T {
        fn uwu() -> i32 {
            <Self as TraitUnimplemented>::uwu()
        }
    }
}

Change `#[extend]` API

I think this is better

/// Doc comment for trait
#[extend(core::time::Duration)]
pub trait DurationExt {
    /// Returns the total number of whole centiseconds contained by this Duration.
    fn as_centis(&self) -> u128 {
        self.as_millis() / 10
    }
}

Improve extension trait documentation

Extension traits produce documentation which has

// Required method

But, extension traits provide all implementations, so this may be confusing.

This could be fixed by adding unused bodies with unreachable!() code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.