diff --git a/server_fn/src/error.rs b/server_fn/src/error.rs index c139dde062..13215a5b52 100644 --- a/server_fn/src/error.rs +++ b/server_fn/src/error.rs @@ -31,24 +31,50 @@ impl From for Error { Clone, Copy, )] -#[cfg_attr( - feature = "rkyv", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) -)] -pub struct NoCustomError; +pub enum NoCustomError {} + +#[cfg(feature = "rkyv")] +impl rkyv::Archive for NoCustomError { + const COPY_OPTIMIZATION: rkyv::traits::CopyOptimization = + rkyv::traits::CopyOptimization::disable(); + type Archived = (); + type Resolver = (); + fn resolve(&self, _: Self::Resolver, _: rkyv::Place) { + match *self {} + } +} + +#[cfg(feature = "rkyv")] +impl rkyv::Deserialize + for NoCustomError +{ + fn deserialize(&self, _: &mut D) -> Result { + match *self {} + } +} + +#[cfg(feature = "rkyv")] +impl rkyv::Serialize for NoCustomError { + fn serialize( + &self, + _: &mut S, + ) -> Result::Error> { + match *self {} + } +} // Implement `Display` for `NoCustomError` impl fmt::Display for NoCustomError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Unit Type Displayed") + fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { + match *self {} } } impl FromStr for NoCustomError { type Err = (); - fn from_str(_s: &str) -> Result { - Ok(NoCustomError) + fn from_str(_: &str) -> Result { + Err(()) } } @@ -94,13 +120,6 @@ pub(crate) trait ServerFnErrorKind {} impl ServerFnErrorKind for ServerFnError {} -// This impl should catch passing () or nothing to server_fn_error -impl ViaError for &&&WrapError<()> { - fn to_server_error(&self) -> ServerFnError { - ServerFnError::WrappedServerError(NoCustomError) - } -} - // This impl will catch any type that implements any type that impls // Error and Clone, so that it can be wrapped into ServerFnError impl ViaError for &&WrapError {