macos-shortcuts 1.1.0

This crate enables access to Apple Shortcuts for Mac
Documentation
use std::{fmt, io::Cursor, ops::Deref};

use image::{DynamicImage, ImageReader};
use serde::{de::{self, Visitor}, Deserialize};

/// Extension type for `DynamicImage` to allow implemention of custom deserialisation logic
#[derive(Clone, Debug)]
pub struct DynamicImageExt {
    image: DynamicImage,
}

impl Deref for DynamicImageExt {
    type Target = DynamicImage;
    fn deref(&self) -> &Self::Target {
        &self.image
    }
}

impl <'de> Deserialize<'de> for DynamicImageExt {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: de::Deserializer<'de> {
        deserializer.deserialize_bytes(DynamicImageExtVisitor)
    }
}

/// `serde` `Visitor` for the `DynamicImageExt` type
struct DynamicImageExtVisitor;

impl<'de> Visitor<'de> for DynamicImageExtVisitor {
    type Value = DynamicImageExt;

    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("a «data» field containing a TIFF")
    }

    fn visit_byte_buf<E>(self, v: Vec<u8>) -> std::result::Result<Self::Value, E>
        where
            E: de::Error, {
        let mut reader = ImageReader::new(Cursor::new(v));
        reader.set_format(image::ImageFormat::Tiff);
        // TODO do we need any of the overlay stuff?
        //let mut bottom = DynamicImage::new(image_format.size.0 as u32, image_format.size.1 as u32, image::ColorType::Rgba32F);
        //let top = reader.decode().unwrap().resize(image_format.size.0 as u32 - 12u32, image_format.size.1 as u32 - 12, image::imageops::FilterType::CatmullRom);
        // overlay(& mut bottom, & match image_format.rotation {
        //     ImageRotation::Rot90 =>  top.rotate180(),
        //     _ => top,
        // }, 5, 9);
        Ok(DynamicImageExt { image: reader.decode().unwrap() })
    }
}