Guest User

Untitled

a guest
Jun 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #[derive(Default, Debug)]
  2. struct Options {
  3. a: i32,
  4. b: i32,
  5. c: i32,
  6. d: i32,
  7. e: f64,
  8. }
  9.  
  10. impl Options {
  11. fn with_a(self, a: impl Into<i32>) -> Self {
  12. Self {
  13. a: a.into(),
  14. ..self
  15. }
  16. }
  17.  
  18. fn with_e(self, e: impl Into<f64>) -> Self {
  19. Self {
  20. e: e.into(),
  21. ..self
  22. }
  23. }
  24. }
  25.  
  26. fn main() {
  27. let opts = Options::default().with_a(1).with_e(2.0);
  28. println!("{:?}", opts);
  29. }
Add Comment
Please, Sign In to add comment