Skip to main content

rustidy_util/
ast_pos.rs

1//! Ast position
2
3/// Ast position
4#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug)]
5#[derive(serde::Serialize, serde::Deserialize)]
6#[derive(derive_more::From)]
7#[serde(transparent)]
8pub struct AstPos(pub usize);
9
10impl AstPos {
11	/// Creates an ast position from a usize
12	// TODO: Should we allow this?
13	#[must_use]
14	pub const fn from_usize(pos: usize) -> Self {
15		Self(pos)
16	}
17
18	/// Returns the index corresponding to this position
19	// TODO: Should we allow this?
20	#[must_use]
21	pub const fn to_usize(self) -> usize {
22		self.0
23	}
24}