From 978f4984556e47bd2845eefd267e6a59d0f73cc3 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 17 Dec 2019 06:21:34 -0500 Subject: [PATCH] Make Rank opaque --- src/subs.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/subs.rs b/src/subs.rs index 97cfef067f..fad5775d3b 100644 --- a/src/subs.rs +++ b/src/subs.rs @@ -177,10 +177,39 @@ fn unnamed_flex_var() -> Content { Content::FlexVar(None) } +#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Rank(u8); + +impl Rank { + pub fn none() -> Self { + Rank(0) + } + + pub fn outermost() -> Self { + Rank(1) + } + + pub fn next(&self) -> Self { + Rank(self.0 + 1) + } +} + +impl Into for Rank { + fn into(self) -> u8 { + self.0 + } +} + +impl Into for Rank { + fn into(self) -> usize { + self.0 as usize + } +} + #[derive(Clone, Debug, PartialEq, Eq)] pub struct Descriptor { pub content: Content, - pub rank: u8, + pub rank: Rank, pub mark: Mark, pub copy: Option, } @@ -195,7 +224,7 @@ impl From for Descriptor { fn from(content: Content) -> Descriptor { Descriptor { content, - rank: 0, + rank: Rank::none(), mark: Mark::none(), copy: None, }