Created
June 24, 2020 14:01
-
-
Save MartinKavik/82503487178dfe8470ee50dec832d530 to your computer and use it in GitHub Desktop.
S. + Style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait StyleTrait: Sized { | |
fn font_size(self, font_size: u32) -> Style { | |
Style::default().font_size(font_size) | |
} | |
fn height(self, height: u32) -> Style { | |
Style::default().height(height) | |
} | |
} | |
struct S; | |
impl StyleTrait for S {} | |
#[derive(Default, Debug)] | |
struct Style { | |
font_size: u32, | |
height: u32, | |
} | |
impl StyleTrait for Style { | |
fn font_size(mut self, font_size: u32) -> Style { | |
self.font_size = font_size; | |
self | |
} | |
fn height(mut self, height: u32) -> Style { | |
self.height = height; | |
self | |
} | |
} | |
fn main() { | |
let style = S.font_size(16).height(50); | |
dbg!(style); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Runnable in https://play.rust-lang.org/