Debian Codegraph @

rust/proc-macro2/location.rs

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