add some strum on Format
This commit is contained in:
parent
53bdd265b3
commit
52c15986a8
2 changed files with 20 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bingus"
|
name = "bingus"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
description.workspace = true
|
description.workspace = true
|
||||||
|
|
|
@ -45,31 +45,48 @@ mod dynamic {
|
||||||
use printpdf::PdfDocument;
|
use printpdf::PdfDocument;
|
||||||
#[cfg(feature = "documents")]
|
#[cfg(feature = "documents")]
|
||||||
use shiva::core::{bytes, Document, DocumentType};
|
use shiva::core::{bytes, Document, DocumentType};
|
||||||
use strum::EnumDiscriminants;
|
use strum::{AsRefStr, EnumDiscriminants, EnumString};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(EnumDiscriminants)]
|
#[derive(EnumDiscriminants)]
|
||||||
#[strum_discriminants(name(Format))]
|
#[strum_discriminants(name(Format), derive(EnumString, AsRefStr))]
|
||||||
pub enum DynamicBendable<'a> {
|
pub enum DynamicBendable<'a> {
|
||||||
#[cfg(feature = "pictures")]
|
#[cfg(feature = "pictures")]
|
||||||
|
#[strum_discriminants(strum(serialize = "img", serialize = "image"))]
|
||||||
Image(DynamicImage),
|
Image(DynamicImage),
|
||||||
#[cfg(feature = "binary")]
|
#[cfg(feature = "binary")]
|
||||||
|
#[strum_discriminants(strum(serialize = "bin", serialize = "binary"))]
|
||||||
Binary(Bytes),
|
Binary(Bytes),
|
||||||
#[cfg(feature = "music")]
|
#[cfg(feature = "music")]
|
||||||
|
#[strum_discriminants(strum(serialize = "snd", serialize = "sound"))]
|
||||||
Sound(Audio),
|
Sound(Audio),
|
||||||
#[cfg(feature = "text")]
|
#[cfg(feature = "text")]
|
||||||
|
#[strum_discriminants(strum(serialize = "txt", serialize = "text"))]
|
||||||
Text(Text<'a>),
|
Text(Text<'a>),
|
||||||
#[cfg(not(feature = "text"))]
|
#[cfg(not(feature = "text"))]
|
||||||
Phantom(PhantomData<&'a ()>),
|
Phantom(PhantomData<&'a ()>),
|
||||||
#[cfg(feature = "documents")]
|
#[cfg(feature = "documents")]
|
||||||
|
#[strum_discriminants(strum(serialize = "doc", serialize = "document"))]
|
||||||
Doc(ShivaDocument),
|
Doc(ShivaDocument),
|
||||||
#[cfg(feature = "documents")]
|
#[cfg(feature = "documents")]
|
||||||
|
#[strum_discriminants(strum(serialize = "arc", serialize = "archive"))]
|
||||||
Archive(PdfDocument),
|
Archive(PdfDocument),
|
||||||
Meta,
|
Meta,
|
||||||
#[cfg(feature = "fonts")]
|
#[cfg(feature = "fonts")]
|
||||||
|
#[strum_discriminants(strum(serialize = "fnt", serialize = "font"))]
|
||||||
Font(FontKitFont),
|
Font(FontKitFont),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "pictures")]
|
||||||
|
#[cfg(test)]
|
||||||
|
#[test]
|
||||||
|
fn format_str() {
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
assert_eq!("image", Format::Image.as_ref());
|
||||||
|
assert_eq!(Ok(Format::Image), Format::from_str("img"));
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "shiva")]
|
#[cfg(feature = "shiva")]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
#[error("extension is unknown by Shiva")]
|
#[error("extension is unknown by Shiva")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue