From: Ian Jackson Date: Tue, 12 Apr 2022 20:12:49 +0000 (+0100) Subject: Make GenericSimpleShape::count_faces return RawFaceId X-Git-Tag: otter-1.1.0~612 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7796b74af082ab6cc0acf6cb426ab8540bf93f6d;p=otter.git Make GenericSimpleShape::count_faces return RawFaceId RawFaceId is smaller than usize. It is better not to ask callers to do the unwrap. Motivated by wanting add a new call site which wants a RawFaceId. Signed-off-by: Ian Jackson --- diff --git a/src/pieces.rs b/src/pieces.rs index c65294bb..f1130d8a 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -144,7 +144,7 @@ impl PieceTrait for SimpleShape { r } fn nfaces(&self) -> RawFaceId { - self.count_faces().try_into().unwrap() + self.count_faces() } fn itemname(&self) -> &str { self.itemname() } @@ -228,8 +228,8 @@ impl GenericSimpleShape where Desc: Debug + Send + Sync + 'static, Outl: OutlineTrait, { - pub fn count_faces(&self) -> usize { - max(self.colours.len(), self.edges.len()) + pub fn count_faces(&self) -> RawFaceId { + max(self.colours.len(), self.edges.len()).try_into().unwrap() } pub fn itemname(&self) -> &str { &self.itemname } @@ -265,7 +265,7 @@ impl GenericSimpleShape let check = |colours: &ColourMap| { let x = colours.len(); - if x == 0 || x == count { Ok(()) } + if x == 0 || x == usize::from(count) { Ok(()) } else { Err(SpecError::InconsistentFacesEdgecoloursCount) } }; check(&shape.colours)?;