From 65203ebccad3d14bea86572a8498aa9240431c8a Mon Sep 17 00:00:00 2001 From: Andre Fontenele Date: Thu, 8 May 2025 11:22:24 -0400 Subject: [PATCH] pub/priv stuff --- src/error.rs | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/error.rs b/src/error.rs index e19c32075..be2c72ff5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -12,24 +12,20 @@ use std::fmt; /// An error related to array shape or layout. #[derive(Clone)] -pub struct ShapeError -{ +pub struct ShapeError { // we want to be able to change this representation later - repr: ErrorKind, + pub repr: ErrorKind, } -impl ShapeError -{ +impl ShapeError { /// Return the `ErrorKind` of this error. #[inline] - pub fn kind(&self) -> ErrorKind - { + pub fn kind(&self) -> ErrorKind { self.repr } /// Create a new `ShapeError` - pub fn from_kind(error: ErrorKind) -> Self - { + pub fn from_kind(error: ErrorKind) -> Self { from_kind(error) } } @@ -40,8 +36,7 @@ impl ShapeError /// is not guaranteed. #[non_exhaustive] #[derive(Copy, Clone, Debug)] -pub enum ErrorKind -{ +pub enum ErrorKind { /// incompatible shape IncompatibleShape = 1, /// incompatible memory layout @@ -57,25 +52,20 @@ pub enum ErrorKind } #[inline(always)] -pub fn from_kind(k: ErrorKind) -> ShapeError -{ +pub fn from_kind(k: ErrorKind) -> ShapeError { ShapeError { repr: k } } -impl PartialEq for ErrorKind -{ +impl PartialEq for ErrorKind { #[inline(always)] - fn eq(&self, rhs: &Self) -> bool - { + fn eq(&self, rhs: &Self) -> bool { *self as u8 == *rhs as u8 } } -impl PartialEq for ShapeError -{ +impl PartialEq for ShapeError { #[inline(always)] - fn eq(&self, rhs: &Self) -> bool - { + fn eq(&self, rhs: &Self) -> bool { self.repr == rhs.repr } } @@ -84,10 +74,8 @@ impl PartialEq for ShapeError #[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl Error for ShapeError {} -impl fmt::Display for ShapeError -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result - { +impl fmt::Display for ShapeError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let description = match self.kind() { ErrorKind::IncompatibleShape => "incompatible shapes", ErrorKind::IncompatibleLayout => "incompatible memory layout", @@ -100,10 +88,8 @@ impl fmt::Display for ShapeError } } -impl fmt::Debug for ShapeError -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result - { +impl fmt::Debug for ShapeError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self) } }