Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. use std::fmt;
  2.  
  3. #[derive(Debug, Copy, Clone, PartialEq)]
  4. pub struct Location {
  5. pub row: u32,
  6. pub column: u32,
  7. }
  8.  
  9. impl Location {
  10. pub fn new(row: u32, column: u32) -> Location {
  11. Location {
  12. row: row,
  13. column: column,
  14. }
  15. }
  16.  
  17. pub fn bump_row(&self) -> Location {
  18. Location { row: self.row + 1, column: 1 }
  19. }
  20.  
  21. pub fn bump_column(&self) -> Location {
  22. Location { row: self.row, column: self.column + 1 }
  23. }
  24. }
  25.  
  26. impl fmt::Display for Location {
  27. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  28. write!(f, "({}, {})", self.row, self.column)
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement