location.rs 918 B

12345678910111213141516171819202122232425262728293031
  1. // SPDX-License-Identifier: Apache-2.0 OR MIT
  2. use core::cmp::Ordering;
  3. /// A line-column pair representing the start or end of a `Span`.
  4. ///
  5. /// This type is semver exempt and not exposed by default.
  6. #[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))]
  7. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
  8. pub struct LineColumn {
  9. /// The 1-indexed line in the source file on which the span starts or ends
  10. /// (inclusive).
  11. pub line: usize,
  12. /// The 0-indexed column (in UTF-8 characters) in the source file on which
  13. /// the span starts or ends (inclusive).
  14. pub column: usize,
  15. }
  16. impl Ord for LineColumn {
  17. fn cmp(&self, other: &Self) -> Ordering {
  18. self.line
  19. .cmp(&other.line)
  20. .then(self.column.cmp(&other.column))
  21. }
  22. }
  23. impl PartialOrd for LineColumn {
  24. fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
  25. Some(self.cmp(other))
  26. }
  27. }