Skip to main content

rustidy_util/
ast_range.rs

1//! Ast range
2
3// Imports
4use crate::AstPos;
5
6/// Ast range
7#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)]
8#[derive(serde::Serialize, serde::Deserialize)]
9pub struct AstRange {
10	pub start: AstPos,
11	pub end:   AstPos,
12}
13
14impl AstRange {
15	/// Creates an ast range from a start and end position
16	#[must_use]
17	pub const fn new(start: AstPos, end: AstPos) -> Self {
18		Self { start, end }
19	}
20
21	/// Returns the length of this range
22	#[must_use]
23	pub const fn len(&self) -> usize {
24		self.end.0 - self.start.0
25	}
26
27	/// Returns if this range is empty
28	#[must_use]
29	pub const fn is_empty(&self) -> bool {
30		self.len() == 0
31	}
32}