diff --git a/tonic/src/interceptor.rs b/tonic/src/interceptor.rs index 3ad0ac6bb..f99d27cc2 100644 --- a/tonic/src/interceptor.rs +++ b/tonic/src/interceptor.rs @@ -1,8 +1,15 @@ use crate::{Request, Status}; +use std::panic::{RefUnwindSafe, UnwindSafe}; use std::{fmt, sync::Arc}; -type InterceptorFn = - Arc) -> Result, Status> + Send + Sync + 'static>; +type InterceptorFn = Arc< + dyn Fn(Request<()>) -> Result, Status> + + Send + + Sync + + UnwindSafe + + RefUnwindSafe + + 'static, +>; /// Represents a gRPC interceptor. /// @@ -25,7 +32,12 @@ pub struct Interceptor { impl Interceptor { /// Create a new `Interceptor` from the provided function. pub fn new( - f: impl Fn(Request<()>) -> Result, Status> + Send + Sync + 'static, + f: impl Fn(Request<()>) -> Result, Status> + + Send + + Sync + + UnwindSafe + + RefUnwindSafe + + 'static, ) -> Self { Interceptor { f: Arc::new(f) } } @@ -43,7 +55,12 @@ impl Interceptor { impl From for Interceptor where - F: Fn(Request<()>) -> Result, Status> + Send + Sync + 'static, + F: Fn(Request<()>) -> Result, Status> + + Send + + Sync + + UnwindSafe + + RefUnwindSafe + + 'static, { fn from(f: F) -> Self { Interceptor::new(f) @@ -55,3 +72,15 @@ impl fmt::Debug for Interceptor { f.debug_struct("Interceptor").finish() } } + +#[cfg(test)] +mod tests { + #[allow(unused_imports)] + use super::*; + + #[test] + fn interceptor_fn_is_unwind_safe() { + fn is_unwind_safe() {} + is_unwind_safe::(); + } +}