rayon optional feature
This commit is contained in:
parent
066d89d250
commit
d2ede29165
4 changed files with 36 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bingus"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
description.workspace = true
|
||||
|
@ -10,9 +10,9 @@ keywords.workspace = true
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[dependencies]
|
||||
image = { version = "0.25", features = ["rayon"] }
|
||||
image = { version = "0.25" }
|
||||
num = "0"
|
||||
rayon = "1"
|
||||
rayon = { version = "1", optional = true }
|
||||
infer = "0"
|
||||
thiserror = "2"
|
||||
derive-new = "0"
|
||||
|
@ -28,7 +28,6 @@ printpdf = { version = "0.8.2", features = [
|
|||
"jpeg",
|
||||
"png",
|
||||
"pnm",
|
||||
"rayon",
|
||||
"tga",
|
||||
"tiff",
|
||||
"js-sys",
|
||||
|
@ -41,3 +40,7 @@ font-kit = { version = "0.14.2", features = ["loader-freetype-default"] }
|
|||
[dev-dependencies]
|
||||
project-root = "0"
|
||||
pretty_assertions = "1"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
rayon = ["image/rayon", "printpdf/rayon", "dep:rayon"]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::{borrow::Cow, convert::Infallible};
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
|
||||
|
||||
use crate::{Bendable, Bytes, IntoDataBytes, TryFromDataBytes};
|
||||
|
@ -27,10 +28,15 @@ impl TryFromDataBytes for Bytes {
|
|||
|
||||
impl Bendable for Bytes {
|
||||
type Unit = u8;
|
||||
#[cfg(feature = "rayon")]
|
||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||
self.par_iter_mut().for_each(|e| *e = f(Cow::Borrowed(e)));
|
||||
self
|
||||
}
|
||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||
self.iter_mut().for_each(|e| *e = f(Cow::Borrowed(e)));
|
||||
self
|
||||
}
|
||||
fn format() -> crate::Format {
|
||||
crate::Format::Binary
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use num::{
|
|||
traits::{FromBytes, ToBytes},
|
||||
Zero,
|
||||
};
|
||||
#[cfg(feature = "rayon")]
|
||||
use rayon::iter::ParallelIterator;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -178,10 +179,15 @@ where
|
|||
P: Send + Sync,
|
||||
{
|
||||
type Unit = P;
|
||||
#[cfg(feature = "rayon")]
|
||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||
self.par_pixels_mut().for_each(|p| *p = f(Cow::Borrowed(p)));
|
||||
self
|
||||
}
|
||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||
self.pixels_mut().for_each(|p| *p = f(Cow::Borrowed(p)));
|
||||
self
|
||||
}
|
||||
fn format() -> crate::Format {
|
||||
Format::Image
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use num::{
|
|||
traits::{FromBytes, ToBytes},
|
||||
Zero,
|
||||
};
|
||||
#[cfg(feature = "rayon")]
|
||||
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
|
||||
|
||||
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
|
||||
|
@ -66,6 +67,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
impl<T> Bendable for RawSamples<T>
|
||||
where
|
||||
T: Sample + FromBytes + ToBytes + Zero + Send,
|
||||
|
@ -81,3 +83,18 @@ where
|
|||
crate::Format::Sound
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Bendable for RawSamples<T>
|
||||
where
|
||||
T: Sample + FromBytes + ToBytes + Zero + Send,
|
||||
<T as FromBytes>::Bytes: Sized + for<'a> TryFrom<&'a [u8]>,
|
||||
{
|
||||
type Unit = T;
|
||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||
self.0.iter_mut().for_each(|e| *e = f(Cow::Borrowed(e)));
|
||||
self
|
||||
}
|
||||
fn format() -> crate::dynamic::Format {
|
||||
crate::Format::Sound
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue