this post was submitted on 31 Mar 2024
33 points (94.6% liked)

Rust

5953 readers
7 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

Hi rustaceans! What are you working on this week? Did you discover something new, you want to share?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 7 months ago

This week some more work was done on inheriteRS to support inheriting non-trait implementations of functions.

Basically

use inheriters::specialisations;

specialisations!(
    struct Parent {
        attr1: u8,
    }
    impl Parent {
        fn from_parent(self) -> u8 { 8 }
        fn overridden(self) -> u8 { self.attr1 }
    }
    
    #[inherit(Child)]
    struct Child {
        attr2: u8,
    }
    impl Child {
        fn overridden(self) -> u8 { self.attr2 }
    }
);

results in

struct Parent {
    attr1: u8,
}
impl Parent {
    fn from_parent(self) -> u8 { 8 }
    fn overridden(self) -> u8 { self.attr1 }
}


struct Child {
    attr1: u8, // new
    attr2: u8,
}
impl Child {
    fn from_parent(self) -> u8 { 8 } // new
    fn overridden(self) -> u8 { self.attr2 }
}

There might be some clean-up necessary code-wise and the README has to be expanded. But the project is well on its way to version 1! It's a pity codeberg doesn't have easy CI/CD yet nor domain hosting e.g inheriters.codeberg.io or something. So auto-formatting, testing, auto-tagging, etc. will have to come once I can convince myself to setup a VPS somewhere that hosts all that.