use std::fmt;
#[derive(Default)]
pub struct Extensions {
inner: http::Extensions,
}
impl Extensions {
pub(crate) fn new() -> Self {
Self {
inner: http::Extensions::new(),
}
}
#[inline]
pub fn insert<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T> {
self.inner.insert(val)
}
#[inline]
pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T> {
self.inner.get()
}
#[inline]
pub fn get_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T> {
self.inner.get_mut()
}
#[inline]
pub fn remove<T: Send + Sync + 'static>(&mut self) -> Option<T> {
self.inner.remove()
}
#[inline]
pub fn clear(&mut self) {
self.inner.clear()
}
#[inline]
pub(crate) fn from_http(http: http::Extensions) -> Self {
Self { inner: http }
}
#[inline]
pub fn into_http(self) -> http::Extensions {
self.inner
}
}
impl fmt::Debug for Extensions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Extensions").finish()
}
}
#[derive(Debug, Clone)]
pub struct GrpcMethod {
service: &'static str,
method: &'static str,
}
impl GrpcMethod {
#[doc(hidden)]
pub fn new(service: &'static str, method: &'static str) -> Self {
Self { service, method }
}
pub fn service(&self) -> &str {
self.service
}
pub fn method(&self) -> &str {
self.method
}
}