diff --git a/src/error.rs b/src/error.rs index 33ee2f1..b98946e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,6 +11,7 @@ use magnus::{ use tokio::sync::mpsc::error::SendError; const ERROR_PREDICATES_IVAR: &str = "wreq_error_predicates"; +type ErrorPredicateBits = u64; const RACE_CONDITION_ERROR_MSG: &str = r#"Due to Rust's memory management with borrowing, you cannot use certain instances multiple times as they may be consumed. @@ -57,8 +58,8 @@ macro_rules! define_error_mapping { const CLASSIFICATION_ORDER: &'static [Self] = &[$(Self::$predicate),+]; /// Return this predicate's position in the compact Ruby metadata. - const fn mask(self) -> u16 { - 1_u16 << (self as u8) + const fn mask(self) -> ErrorPredicateBits { + 1 << (self as u8) } /// Evaluate this predicate before the native error is consumed. @@ -77,7 +78,7 @@ macro_rules! define_error_mapping { } const _: () = - assert!(ErrorPredicate::CLASSIFICATION_ORDER.len() <= u16::BITS as usize); + assert!(ErrorPredicate::CLASSIFICATION_ORDER.len() <= ErrorPredicateBits::BITS as usize); $( $(define_exception!($class, $ruby_name, exception_runtime_error);)? @@ -131,16 +132,16 @@ define_error_mapping! { /// Native predicates retained after consuming a wreq error. #[derive(Clone, Copy, Default)] -struct ErrorPredicates(u16); +struct ErrorPredicates(ErrorPredicateBits); impl ErrorPredicates { /// Restore predicates from compact Ruby metadata. - const fn from_bits(bits: u16) -> Self { + const fn from_bits(bits: ErrorPredicateBits) -> Self { Self(bits) } /// Return the compact representation stored on the Ruby exception. - const fn bits(self) -> u16 { + const fn bits(self) -> ErrorPredicateBits { self.0 } @@ -339,7 +340,7 @@ fn wreq_error_class(ruby: &Ruby, predicates: ErrorPredicates) -> ExceptionClass /// Read one native predicate from a Ruby error, defaulting to false. fn error_has_predicate(rb_self: RObject, predicate: ErrorPredicate) -> Result { rb_self - .ivar_get::<_, Option>(ERROR_PREDICATES_IVAR) + .ivar_get::<_, Option>(ERROR_PREDICATES_IVAR) .map(|bits| bits.is_some_and(|bits| ErrorPredicates::from_bits(bits).contains(predicate))) }