mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
expose encoder error
This commit is contained in:
parent
f12f62ba73
commit
8d2abe4b35
@ -1,7 +1,6 @@
|
||||
//! Stream encoders.
|
||||
|
||||
use std::{
|
||||
error::Error as StdError,
|
||||
future::Future,
|
||||
io::{self, Write as _},
|
||||
pin::Pin,
|
||||
@ -10,7 +9,6 @@ use std::{
|
||||
|
||||
use actix_rt::task::{spawn_blocking, JoinHandle};
|
||||
use bytes::Bytes;
|
||||
use derive_more::Display;
|
||||
use futures_core::ready;
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
@ -23,7 +21,7 @@ use flate2::write::{GzEncoder, ZlibEncoder};
|
||||
#[cfg(feature = "compress-zstd")]
|
||||
use zstd::stream::write::Encoder as ZstdEncoder;
|
||||
|
||||
use super::Writer;
|
||||
use super::{EncoderError, Writer};
|
||||
use crate::{
|
||||
body::{BodySize, MessageBody},
|
||||
error::BlockingError,
|
||||
@ -364,32 +362,3 @@ impl ContentEncoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Display)]
|
||||
#[non_exhaustive]
|
||||
pub enum EncoderError {
|
||||
#[display(fmt = "body")]
|
||||
Body(Box<dyn StdError>),
|
||||
|
||||
#[display(fmt = "blocking")]
|
||||
Blocking(BlockingError),
|
||||
|
||||
#[display(fmt = "io")]
|
||||
Io(io::Error),
|
||||
}
|
||||
|
||||
impl StdError for EncoderError {
|
||||
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
||||
match self {
|
||||
EncoderError::Body(err) => Some(&**err),
|
||||
EncoderError::Blocking(err) => Some(err),
|
||||
EncoderError::Io(err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EncoderError> for crate::Error {
|
||||
fn from(err: EncoderError) -> Self {
|
||||
crate::Error::new_encoder().with_cause(err)
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,60 @@
|
||||
//! Content-Encoding support.
|
||||
|
||||
use std::io;
|
||||
use std::{error::Error as StdError, io};
|
||||
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use derive_more::Display;
|
||||
|
||||
use crate::error::BlockingError;
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
mod decoder;
|
||||
#[cfg(feature = "__compress")]
|
||||
mod encoder;
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
pub use self::decoder::Decoder;
|
||||
pub use self::encoder::{Encoder, EncoderError};
|
||||
#[cfg(feature = "__compress")]
|
||||
pub use self::encoder::Encoder;
|
||||
|
||||
#[derive(Debug, Display)]
|
||||
#[non_exhaustive]
|
||||
pub enum EncoderError {
|
||||
#[display(fmt = "body")]
|
||||
Body(Box<dyn StdError>),
|
||||
|
||||
#[display(fmt = "blocking")]
|
||||
Blocking(BlockingError),
|
||||
|
||||
#[display(fmt = "io")]
|
||||
Io(io::Error),
|
||||
}
|
||||
|
||||
impl StdError for EncoderError {
|
||||
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
||||
match self {
|
||||
EncoderError::Body(err) => Some(&**err),
|
||||
EncoderError::Blocking(err) => Some(err),
|
||||
EncoderError::Io(err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EncoderError> for crate::Error {
|
||||
fn from(err: EncoderError) -> Self {
|
||||
crate::Error::new_encoder().with_cause(err)
|
||||
}
|
||||
}
|
||||
|
||||
/// Special-purpose writer for streaming (de-)compression.
|
||||
///
|
||||
/// Pre-allocates 8KiB of capacity.
|
||||
#[cfg(feature = "__compress")]
|
||||
pub(self) struct Writer {
|
||||
buf: BytesMut,
|
||||
}
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
impl Writer {
|
||||
fn new() -> Writer {
|
||||
Writer {
|
||||
@ -29,6 +67,7 @@ impl Writer {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
impl io::Write for Writer {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
self.buf.extend_from_slice(buf);
|
||||
|
@ -32,7 +32,6 @@ pub mod body;
|
||||
mod builder;
|
||||
mod config;
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
pub mod encoding;
|
||||
mod extensions;
|
||||
pub mod header;
|
||||
|
Loading…
Reference in New Issue
Block a user