memberlist_proto/compression/
error.rs1use super::CompressAlgorithm;
2
3#[derive(Debug, thiserror::Error)]
5pub enum CompressError {
6 #[error(transparent)]
8 #[cfg(feature = "lz4")]
9 #[cfg_attr(docsrs, doc(cfg(feature = "lz4")))]
10 Lz4(#[from] lz4_flex::block::CompressError),
11 #[error(transparent)]
13 #[cfg(feature = "brotli")]
14 #[cfg_attr(docsrs, doc(cfg(feature = "brotli")))]
15 Brotli(std::io::Error),
16 #[error(transparent)]
18 #[cfg(feature = "snappy")]
19 #[cfg_attr(docsrs, doc(cfg(feature = "snappy")))]
20 Snappy(#[from] snap::Error),
21 #[error(transparent)]
23 #[cfg(feature = "zstd")]
24 #[cfg_attr(docsrs, doc(cfg(feature = "zstd")))]
25 Zstd(std::io::Error),
26}
27
28#[derive(Debug, thiserror::Error)]
30pub enum DecompressError {
31 #[error(transparent)]
33 #[cfg(feature = "brotli")]
34 #[cfg_attr(docsrs, doc(cfg(feature = "brotli")))]
35 Brotli(std::io::Error),
36 #[error(transparent)]
38 #[cfg(feature = "lz4")]
39 #[cfg_attr(docsrs, doc(cfg(feature = "lz4")))]
40 Lz4(#[from] lz4_flex::block::DecompressError),
41 #[error(transparent)]
43 #[cfg(feature = "snappy")]
44 #[cfg_attr(docsrs, doc(cfg(feature = "snappy")))]
45 Snappy(#[from] snap::Error),
46 #[error(transparent)]
48 #[cfg(feature = "zstd")]
49 #[cfg_attr(docsrs, doc(cfg(feature = "zstd")))]
50 Zstd(#[from] std::io::Error),
51}
52
53#[derive(Debug, thiserror::Error)]
55pub enum CompressionError {
56 #[error(transparent)]
58 Compress(#[from] CompressError),
59 #[error(transparent)]
61 Decompress(#[from] DecompressError),
62 #[error("the {algo} is supported but the feature {feature} is disabled")]
64 Disabled {
65 algo: CompressAlgorithm,
67 feature: &'static str,
69 },
70 #[error("unknown compress algorithm {0}")]
72 UnknownAlgorithm(CompressAlgorithm),
73}
74
75impl CompressionError {
76 #[cfg(not(all(
77 feature = "brotli",
78 feature = "lz4",
79 feature = "snappy",
80 feature = "zstd"
81 )))]
82 #[inline]
83 pub(crate) const fn disabled(algo: CompressAlgorithm, feature: &'static str) -> Self {
84 Self::Disabled { algo, feature }
85 }
86}