scufflecloud_ext/http_ext.rs
1use std::sync::Arc;
2
3use crate::OptionExt;
4
5pub trait RequestExt {
6 fn extensions(&self) -> &http::Extensions;
7
8 fn global<G: Send + Sync + 'static>(&self) -> Result<Arc<G>, tonic::Status> {
9 self.extensions()
10 .get::<Arc<G>>()
11 .map(Arc::clone)
12 .into_tonic_internal_err("missing global extension")
13 }
14}
15
16impl<T> RequestExt for tonic::Request<T> {
17 fn extensions(&self) -> &http::Extensions {
18 self.extensions()
19 }
20}
21
22impl RequestExt for tonic::Extensions {
23 fn extensions(&self) -> &http::Extensions {
24 self
25 }
26}
27
28impl<T> RequestExt for http::Request<T> {
29 fn extensions(&self) -> &http::Extensions {
30 self.extensions()
31 }
32}