Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #[derive(Debug)]
  2. pub struct Counter<'a> {
  3. pub name: &'a str,
  4. pub tally: u64,
  5. }
  6.  
  7. impl<'a> Counter<'a> {
  8. pub fn new(name: &str) -> Counter {
  9. Counter {
  10. name,
  11. tally: 0,
  12. }
  13. }
  14. pub fn max(x: Counter<'a>, y: Counter<'a>) -> Counter<'a> {
  15. if x.tally > y.tally {
  16. x
  17. } else {
  18. y
  19. }
  20. }
  21.  
  22. pub fn increase(&mut self) {
  23. self.tally += 1;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement