mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/liquid.rs')
| -rw-r--r-- | src/block/liquid.rs | 56 |
1 files changed, 14 insertions, 42 deletions
diff --git a/src/block/liquid.rs b/src/block/liquid.rs index 888bd0d..d74fc9d 100644 --- a/src/block/liquid.rs +++ b/src/block/liquid.rs @@ -1,6 +1,5 @@ //! liquid related things -use std::error::Error; -use std::fmt; +use thiserror::Error; use crate::block::distribution::BridgeBlock; use crate::block::simple::*; @@ -102,7 +101,13 @@ impl BlockLogic for FluidBlock { } } - fn draw(&self, category: &str, name: &str, state: Option<&State>) -> Option<ImageHolder> { + fn draw( + &self, + category: &str, + name: &str, + state: Option<&State>, + _: Option<&RenderingContext>, + ) -> Option<ImageHolder> { let mut p = load(category, name).unwrap().clone(); if let Some(state) = state { if let Some(s) = Self::get_state(state) { @@ -117,21 +122,16 @@ impl BlockLogic for FluidBlock { } } -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Error)] +#[error("invalid config ({0}) for fluid")] pub struct FluidConvertError(pub i32); -impl fmt::Display for FluidConvertError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "invalid config ({}) for fluid", self.0) - } -} - -impl Error for FluidConvertError {} - -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Error)] pub enum FluidDeserializeError { + #[error("expected Fluid but got {0:?}")] ContentType(content::Type), - NotFound(fluid::TryFromU16Error), + #[error("fluid not found")] + NotFound(#[from] fluid::TryFromU16Error), } impl FluidDeserializeError { @@ -142,31 +142,3 @@ impl FluidDeserializeError { } } } - -impl From<fluid::TryFromU16Error> for FluidDeserializeError { - fn from(err: fluid::TryFromU16Error) -> Self { - Self::NotFound(err) - } -} - -impl fmt::Display for FluidDeserializeError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::ContentType(have) => write!( - f, - "expected content {:?} but got {have:?}", - content::Type::Fluid - ), - Self::NotFound(..) => f.write_str("fluid not found"), - } - } -} - -impl Error for FluidDeserializeError { - fn source(&self) -> Option<&(dyn Error + 'static)> { - match self { - Self::NotFound(e) => Some(e), - _ => None, - } - } -} |