1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00
denoland-deno/ext/node/ops/zlib/mode.rs

59 lines
1.2 KiB
Rust
Raw Normal View History

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2023-03-27 12:03:07 -04:00
#[derive(Debug, thiserror::Error)]
#[error("bad argument")]
pub struct ModeError;
2023-03-27 12:03:07 -04:00
macro_rules! repr_i32 {
($(#[$meta:meta])* $vis:vis enum $name:ident {
$($(#[$vmeta:meta])* $vname:ident $(= $val:expr)?,)*
}) => {
$(#[$meta])*
$vis enum $name {
$($(#[$vmeta])* $vname $(= $val)?,)*
}
impl core::convert::TryFrom<i32> for $name {
type Error = ModeError;
2023-03-27 12:03:07 -04:00
fn try_from(v: i32) -> Result<Self, Self::Error> {
match v {
$(x if x == $name::$vname as i32 => Ok($name::$vname),)*
_ => Err(ModeError),
2023-03-27 12:03:07 -04:00
}
}
}
}
}
repr_i32! {
#[repr(i32)]
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub enum Mode {
#[default]
None,
Deflate,
Inflate,
Gzip,
Gunzip,
DeflateRaw,
InflateRaw,
Unzip,
}
}
repr_i32! {
#[repr(i32)]
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub enum Flush {
#[default]
None = zlib::Z_NO_FLUSH,
Partial = zlib::Z_PARTIAL_FLUSH,
Sync = zlib::Z_SYNC_FLUSH,
Full = zlib::Z_FULL_FLUSH,
Finish = zlib::Z_FINISH,
Block = zlib::Z_BLOCK,
Trees = zlib::Z_TREES,
2023-03-27 12:03:07 -04:00
}
}