pub struct BorrowCodec<T> { /* private fields */ }
Expand description
Zero-copy codec extractor.
Similar to Codec
in that it can decode from various formats,
but different in that the backing bytes are kept alive after decoding
and it cannot be used as a response encoder.
Note that the decoded data cannot be modified, as it is borrowed.
If you need to modify the data, use Codec
instead.
§Examples
ⓘ
#[axum_codec::apply(decode)]
struct Greeting<'d> {
hello: Cow<'d, [u8]>,
}
async fn my_route(body: BorrowCodec<Greeting<'_>>) -> Result<(), Response> {
// do something with `body.hello`...
println!("{:?}", body.hello);
Ok(())
}
§Errors
See CodecRejection
for more information.
Implementations§
Source§impl<T> BorrowCodec<T>
impl<T> BorrowCodec<T>
Sourcepub unsafe fn as_mut_unchecked(&mut self) -> &mut T
pub unsafe fn as_mut_unchecked(&mut self) -> &mut T
Returns a mutable reference to the inner value.
§Safety
Callers must ensure that the inner value is not kept alive longer
than the original BorrowCodec
that it came from. For example,
via std::mem::swap
or std::mem::replace
.
Source§impl<'de, T> BorrowCodec<T>where
T: CodecDecode<'de>,
impl<'de, T> BorrowCodec<T>where
T: CodecDecode<'de>,
Sourcepub fn from_bytes(
bytes: BytesMut,
content_type: ContentType,
) -> Result<Self, CodecRejection>
pub fn from_bytes( bytes: BytesMut, content_type: ContentType, ) -> Result<Self, CodecRejection>
Creates a new BorrowCodec
from the given bytes and content type.
§Errors
See CodecRejection
for more information.
Trait Implementations§
Source§impl<T> AsRef<T> for BorrowCodec<T>
impl<T> AsRef<T> for BorrowCodec<T>
Source§impl<T> Debug for BorrowCodec<T>where
T: Debug,
impl<T> Debug for BorrowCodec<T>where
T: Debug,
Source§impl<T> Deref for BorrowCodec<T>
impl<T> Deref for BorrowCodec<T>
Source§impl<T, S> FromRequest<S> for BorrowCodec<T>
impl<T, S> FromRequest<S> for BorrowCodec<T>
Source§impl<T> Hash for BorrowCodec<T>where
T: Hash,
impl<T> Hash for BorrowCodec<T>where
T: Hash,
Source§impl<T> OperationInput for BorrowCodec<T>where
T: JsonSchema,
impl<T> OperationInput for BorrowCodec<T>where
T: JsonSchema,
Source§fn operation_input(ctx: &mut GenContext, operation: &mut Operation)
fn operation_input(ctx: &mut GenContext, operation: &mut Operation)
Modify the operation. Read more
Source§fn inferred_early_responses(
ctx: &mut GenContext,
operation: &mut Operation,
) -> Vec<(Option<u16>, Response)>
fn inferred_early_responses( ctx: &mut GenContext, operation: &mut Operation, ) -> Vec<(Option<u16>, Response)>
Inferred early responses are used to document early returns for
extractors, guards inside handlers. For example these could represent
JSON parsing errors, authentication failures. Read more
Source§impl<T> Ord for BorrowCodec<T>where
T: Ord,
impl<T> Ord for BorrowCodec<T>where
T: Ord,
Source§impl<T> PartialEq for BorrowCodec<T>where
T: PartialEq,
impl<T> PartialEq for BorrowCodec<T>where
T: PartialEq,
Source§impl<T> PartialOrd for BorrowCodec<T>where
T: PartialOrd,
impl<T> PartialOrd for BorrowCodec<T>where
T: PartialOrd,
impl<T> Eq for BorrowCodec<T>where
T: Eq,
Auto Trait Implementations§
impl<T> Freeze for BorrowCodec<T>where
T: Freeze,
impl<T> RefUnwindSafe for BorrowCodec<T>where
T: RefUnwindSafe,
impl<T> Send for BorrowCodec<T>where
T: Send,
impl<T> Sync for BorrowCodec<T>where
T: Sync,
impl<T> Unpin for BorrowCodec<T>where
T: Unpin,
impl<T> UnwindSafe for BorrowCodec<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.