chiark / gitweb /
Make GenericSimpleShape::count_faces return RawFaceId
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 12 Apr 2022 20:12:49 +0000 (21:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 12 Apr 2022 20:12:49 +0000 (21:12 +0100)
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 <ijackson@chiark.greenend.org.uk>
src/pieces.rs

index c65294bba205b05ef4d78ead0d306afe1dd2efcc..f1130d8a5ef943dd7f23d7ed41cf484c4eb86959 100644 (file)
@@ -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<Desc, Outl:'static> GenericSimpleShape<Desc, Outl>
     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<Desc, Outl:'static> GenericSimpleShape<Desc, Outl>
 
     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)?;