remove useless format Bendable method, modify API exposition

This commit is contained in:
brevalferrari 2025-06-19 10:34:36 +02:00
parent 6bb627d77b
commit f72a30b972
Signed by: breval
GPG key ID: 913954DA013FAD4F
8 changed files with 4 additions and 56 deletions

View file

@ -37,7 +37,4 @@ impl Bendable for Bytes {
iter.for_each(|e| *e = f(Cow::Borrowed(e)));
self
}
fn format() -> crate::Format {
crate::Format::Binary
}
}

View file

@ -92,10 +92,6 @@ impl Bendable for PdfDocument {
bookmarks,
}
}
fn format() -> crate::Format {
crate::Format::Archive
}
}
#[cfg(test)]

View file

@ -59,8 +59,4 @@ impl Bendable for ShivaDocument {
self.output_format,
)
}
fn format() -> crate::Format {
crate::Format::Doc
}
}

View file

@ -46,8 +46,4 @@ impl Bendable for Font {
)
.expect("coudn't get font back from bytes after map")
}
fn format() -> crate::Format {
crate::Format::Font
}
}

View file

@ -15,7 +15,7 @@ use num::{
use rayon::iter::ParallelIterator;
use thiserror::Error;
use crate::{Bendable, Format, FromDataBytes, IntoDataBytes, TryFromDataBytes};
use crate::{Bendable, FromDataBytes, IntoDataBytes, TryFromDataBytes};
impl<P: Pixel> IntoDataBytes for ImageBuffer<P, Vec<P::Subpixel>>
where
@ -188,9 +188,6 @@ where
iter.for_each(|p| *p = f(Cow::Borrowed(p)));
self
}
fn format() -> crate::Format {
Format::Image
}
}
impl IntoDataBytes for DynamicImage {

View file

@ -13,7 +13,7 @@ pub mod txt;
pub type Bytes = Vec<u8>;
mod dynamic {
pub mod dynamic {
#[cfg(feature = "text")]
use std::string::FromUtf8Error;
use std::{
@ -40,53 +40,33 @@ mod dynamic {
use cfg_if::cfg_if;
#[cfg(feature = "fonts")]
use font_kit::error::FontLoadingError;
pub use infer::MatcherType;
pub use infer::*;
#[cfg(feature = "documents")]
use printpdf::PdfDocument;
#[cfg(feature = "documents")]
use shiva::core::{bytes, Document, DocumentType};
use strum::{AsRefStr, EnumDiscriminants, EnumString};
use thiserror::Error;
#[derive(EnumDiscriminants)]
#[strum_discriminants(name(Format), derive(EnumString, AsRefStr))]
pub enum DynamicBendable<'a> {
#[cfg(feature = "pictures")]
#[strum_discriminants(strum(serialize = "img", serialize = "image"))]
Image(DynamicImage),
#[cfg(feature = "binary")]
#[strum_discriminants(strum(serialize = "bin", serialize = "binary"))]
Binary(Bytes),
#[cfg(feature = "music")]
#[strum_discriminants(strum(serialize = "snd", serialize = "sound"))]
Sound(Audio),
#[cfg(feature = "text")]
#[strum_discriminants(strum(serialize = "txt", serialize = "text"))]
Text(Text<'a>),
#[cfg(not(feature = "text"))]
Phantom(PhantomData<&'a ()>),
#[cfg(feature = "documents")]
#[strum_discriminants(strum(serialize = "doc", serialize = "document"))]
Doc(ShivaDocument),
#[cfg(feature = "documents")]
#[strum_discriminants(strum(serialize = "arc", serialize = "archive"))]
Archive(PdfDocument),
Meta,
#[cfg(feature = "fonts")]
#[strum_discriminants(strum(serialize = "fnt", serialize = "font"))]
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")]
#[derive(Debug, Error)]
#[error("extension is unknown by Shiva")]
@ -165,15 +145,11 @@ mod dynamic {
}
self
}
fn format() -> Format {
Format::Meta
}
}
pub type DynamicResult = Result<Option<DynamicBendable<'static>>, OpenError>;
fn guess(t: Option<infer::Type>, bytes: Bytes) -> DynamicResult {
pub fn guess(t: Option<infer::Type>, bytes: Bytes) -> DynamicResult {
use MatcherType::*;
t.map(|t| (t.matcher_type(), t.extension()))
.map(
@ -244,8 +220,6 @@ mod dynamic {
use std::{borrow::Cow, convert::Infallible};
pub use dynamic::*;
pub trait Bendable: TryFromDataBytes + IntoDataBytes {
type Unit;
fn bend_into<T: TryFromDataBytes + IntoDataBytes>(
@ -263,7 +237,6 @@ pub trait Bendable: TryFromDataBytes + IntoDataBytes {
Self::try_from_data_bytes(b.into_data_bytes(), format, crop)
}
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(self, f: F) -> Self;
fn format() -> Format;
}
pub trait IntoDataBytes: Sized {

View file

@ -93,8 +93,5 @@ if #[cfg(feature = "rayon")] {
self.0.iter_mut().for_each(|e| *e = f(Cow::Borrowed(e)));
self
}
fn format() -> crate::dynamic::Format {
crate::Format::Sound
}
}
}}

View file

@ -31,8 +31,4 @@ impl Bendable for Text<'_> {
.collect::<String>()
.into()
}
fn format() -> crate::Format {
crate::Format::Text
}
}