Skip to content

Commit

Permalink
MOD: Change casing of enums
Browse files Browse the repository at this point in the history
  • Loading branch information
threecgreen committed Aug 16, 2024
1 parent 0490b4b commit 4f66140
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions rust/dbn/src/encode/dyn_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where
W: io::Write,
{
Uncompressed(W),
ZStd(zstd::stream::AutoFinishEncoder<'a, W>),
Zstd(zstd::stream::AutoFinishEncoder<'a, W>),
}

impl<'a, W> DynWriter<'a, W>
Expand All @@ -28,15 +28,15 @@ where
pub fn new(writer: W, compression: Compression) -> Result<Self> {
match compression {
Compression::None => Ok(Self(DynWriterImpl::Uncompressed(writer))),
Compression::ZStd => zstd_encoder(writer).map(|enc| Self(DynWriterImpl::ZStd(enc))),
Compression::ZStd => zstd_encoder(writer).map(|enc| Self(DynWriterImpl::Zstd(enc))),
}
}

/// Returns a mutable reference to the underlying writer.
pub fn get_mut(&mut self) -> &mut W {
match &mut self.0 {
DynWriterImpl::Uncompressed(w) => w,
DynWriterImpl::ZStd(enc) => enc.get_mut(),
DynWriterImpl::Zstd(enc) => enc.get_mut(),
}
}
}
Expand All @@ -48,35 +48,35 @@ where
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
match &mut self.0 {
DynWriterImpl::Uncompressed(writer) => writer.write(buf),
DynWriterImpl::ZStd(writer) => writer.write(buf),
DynWriterImpl::Zstd(writer) => writer.write(buf),
}
}

fn flush(&mut self) -> io::Result<()> {
match &mut self.0 {
DynWriterImpl::Uncompressed(writer) => writer.flush(),
DynWriterImpl::ZStd(writer) => writer.flush(),
DynWriterImpl::Zstd(writer) => writer.flush(),
}
}

fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
match &mut self.0 {
DynWriterImpl::Uncompressed(writer) => writer.write_vectored(bufs),
DynWriterImpl::ZStd(writer) => writer.write_vectored(bufs),
DynWriterImpl::Zstd(writer) => writer.write_vectored(bufs),
}
}

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
match &mut self.0 {
DynWriterImpl::Uncompressed(writer) => writer.write_all(buf),
DynWriterImpl::ZStd(writer) => writer.write_all(buf),
DynWriterImpl::Zstd(writer) => writer.write_all(buf),
}
}

fn write_fmt(&mut self, fmt: std::fmt::Arguments<'_>) -> io::Result<()> {
match &mut self.0 {
DynWriterImpl::Uncompressed(writer) => writer.write_fmt(fmt),
DynWriterImpl::ZStd(writer) => writer.write_fmt(fmt),
DynWriterImpl::Zstd(writer) => writer.write_fmt(fmt),
}
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ mod r#async {
B: io::AsyncWriteExt + Unpin,
{
Uncompressed(B),
ZStd(ZstdEncoder<W>),
Zstd(ZstdEncoder<W>),
}

impl<W> DynBufWriter<W>
Expand All @@ -123,7 +123,7 @@ mod r#async {
pub fn new(writer: W, compression: Compression) -> Self {
Self(match compression {
Compression::None => DynBufWriterImpl::Uncompressed(writer),
Compression::ZStd => DynBufWriterImpl::ZStd(async_zstd_encoder(writer)),
Compression::ZStd => DynBufWriterImpl::Zstd(async_zstd_encoder(writer)),
})
}
}
Expand All @@ -138,7 +138,7 @@ mod r#async {
Compression::None => DynBufWriterImpl::Uncompressed(BufWriter::new(writer)),
// `ZstdEncoder` already wraps `W` in a `BufWriter`, cf.
// https://github.com/Nullus157/async-compression/blob/main/src/tokio/write/generic/encoder.rs
Compression::ZStd => DynBufWriterImpl::ZStd(async_zstd_encoder(writer)),
Compression::ZStd => DynBufWriterImpl::Zstd(async_zstd_encoder(writer)),
})
}
}
Expand All @@ -156,21 +156,21 @@ mod r#async {
DynBufWriterImpl::Uncompressed(w) => {
io::AsyncWrite::poll_write(Pin::new(w), cx, buf)
}
DynBufWriterImpl::ZStd(enc) => io::AsyncWrite::poll_write(Pin::new(enc), cx, buf),
DynBufWriterImpl::Zstd(enc) => io::AsyncWrite::poll_write(Pin::new(enc), cx, buf),
}
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
match &mut self.0 {
DynBufWriterImpl::Uncompressed(w) => io::AsyncWrite::poll_flush(Pin::new(w), cx),
DynBufWriterImpl::ZStd(enc) => io::AsyncWrite::poll_flush(Pin::new(enc), cx),
DynBufWriterImpl::Zstd(enc) => io::AsyncWrite::poll_flush(Pin::new(enc), cx),
}
}

fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
match &mut self.0 {
DynBufWriterImpl::Uncompressed(w) => io::AsyncWrite::poll_shutdown(Pin::new(w), cx),
DynBufWriterImpl::ZStd(enc) => io::AsyncWrite::poll_shutdown(Pin::new(enc), cx),
DynBufWriterImpl::Zstd(enc) => io::AsyncWrite::poll_shutdown(Pin::new(enc), cx),
}
}
}
Expand All @@ -188,7 +188,7 @@ mod r#async {
W: io::AsyncWriteExt + Unpin,
{
Uncompressed(W),
ZStd(ZstdEncoder<W>),
Zstd(ZstdEncoder<W>),
}

impl<W> DynWriter<W>
Expand All @@ -200,15 +200,15 @@ mod r#async {
pub fn new(writer: W, compression: Compression) -> Self {
Self(match compression {
Compression::None => DynWriterImpl::Uncompressed(writer),
Compression::ZStd => DynWriterImpl::ZStd(async_zstd_encoder(writer)),
Compression::ZStd => DynWriterImpl::Zstd(async_zstd_encoder(writer)),
})
}

/// Returns a mutable reference to the underlying writer.
pub fn get_mut(&mut self) -> &mut W {
match &mut self.0 {
DynWriterImpl::Uncompressed(w) => w,
DynWriterImpl::ZStd(enc) => enc.get_mut(),
DynWriterImpl::Zstd(enc) => enc.get_mut(),
}
}
}
Expand All @@ -224,21 +224,21 @@ mod r#async {
) -> Poll<io::Result<usize>> {
match &mut self.0 {
DynWriterImpl::Uncompressed(w) => io::AsyncWrite::poll_write(Pin::new(w), cx, buf),
DynWriterImpl::ZStd(enc) => io::AsyncWrite::poll_write(Pin::new(enc), cx, buf),
DynWriterImpl::Zstd(enc) => io::AsyncWrite::poll_write(Pin::new(enc), cx, buf),
}
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
match &mut self.0 {
DynWriterImpl::Uncompressed(w) => io::AsyncWrite::poll_flush(Pin::new(w), cx),
DynWriterImpl::ZStd(enc) => io::AsyncWrite::poll_flush(Pin::new(enc), cx),
DynWriterImpl::Zstd(enc) => io::AsyncWrite::poll_flush(Pin::new(enc), cx),
}
}

fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
match &mut self.0 {
DynWriterImpl::Uncompressed(w) => io::AsyncWrite::poll_shutdown(Pin::new(w), cx),
DynWriterImpl::ZStd(enc) => io::AsyncWrite::poll_shutdown(Pin::new(enc), cx),
DynWriterImpl::Zstd(enc) => io::AsyncWrite::poll_shutdown(Pin::new(enc), cx),
}
}
}
Expand Down

0 comments on commit 4f66140

Please sign in to comment.