Skip to main content

cratestack_axum/envelope_layer/
server_envelope_arc.rs

1//! [`ServerEnvelope`] for `Arc<T>` (API-review nit): kept apart from the
2//! trait, whose documentation alone fills its file.
3
4use std::sync::Arc;
5
6use async_trait::async_trait;
7use bytes::Bytes;
8use cratestack_core::{Binding, CratestackError};
9
10use super::opened::{OpenedRequest, SealContext, Sealed};
11use super::server_envelope::ServerEnvelope;
12
13/// An envelope shared with the rest of the application (or built once and
14/// handed to several layers) is still an envelope.
15#[async_trait]
16impl<T: ServerEnvelope + ?Sized> ServerEnvelope for Arc<T> {
17    fn media_type(&self) -> &'static str {
18        (**self).media_type()
19    }
20
21    fn is_envelope_content_type(&self, content_type: &str) -> bool {
22        (**self).is_envelope_content_type(content_type)
23    }
24
25    async fn open_request(
26        &self,
27        body: Bytes,
28        bind: &Binding<'_>,
29    ) -> Result<OpenedRequest, CratestackError> {
30        (**self).open_request(body, bind).await
31    }
32
33    async fn open_request_any(
34        &self,
35        body: Bytes,
36        binds: &[Binding<'_>],
37    ) -> Result<(OpenedRequest, usize), CratestackError> {
38        (**self).open_request_any(body, binds).await
39    }
40
41    async fn seal_response(
42        &self,
43        payload: &[u8],
44        bind: &Binding<'_>,
45        context: &SealContext,
46    ) -> Result<Sealed, CratestackError> {
47        (**self).seal_response(payload, bind, context).await
48    }
49}