From e1edc611bc04db3fe7ee8fcc06a251506026685d Mon Sep 17 00:00:00 2001 From: p6nj Date: Fri, 17 Jan 2025 22:49:59 -0500 Subject: [PATCH] binary code (renamed, it was mistaken for the crate's binary) --- bingus/src/bin.rs | 2 ++ bingus/src/bin_/bytes.rs | 29 +++++++++++++++++++++++++++++ bingus/src/lib.rs | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 bingus/src/bin_/bytes.rs diff --git a/bingus/src/bin.rs b/bingus/src/bin.rs index e69de29..1e42f77 100644 --- a/bingus/src/bin.rs +++ b/bingus/src/bin.rs @@ -0,0 +1,2 @@ +#[path = "bin_/bytes.rs"] +mod bytes; diff --git a/bingus/src/bin_/bytes.rs b/bingus/src/bin_/bytes.rs new file mode 100644 index 0000000..311a757 --- /dev/null +++ b/bingus/src/bin_/bytes.rs @@ -0,0 +1,29 @@ +use std::convert::Infallible; + +use rayon::iter::{IntoParallelIterator, ParallelIterator}; + +use crate::{Bendable, Bytes, IntoDataBytes, TryFromDataBytes}; + +impl IntoDataBytes for Bytes { + fn into_bytes(self) -> Bytes { + self + } +} + +impl TryFromDataBytes for Bytes { + type Error = Infallible; + type Format = (); + fn try_from_bytes(bytes: Bytes, _: Self::Format) -> Result + where + Self: Sized, + { + Ok(bytes) + } +} + +impl Bendable for Bytes { + type Unit = u8; + fn map Self::Unit + Sync>(self, f: F) -> Self { + self.into_par_iter().map(|e| f(&e)).collect() + } +} diff --git a/bingus/src/lib.rs b/bingus/src/lib.rs index 7aa90ae..2195e59 100644 --- a/bingus/src/lib.rs +++ b/bingus/src/lib.rs @@ -3,7 +3,7 @@ pub mod img; pub mod snd; pub mod txt; -pub type Bytes = Vec; +pub(crate) type Bytes = Vec; pub trait Bendable: TryFromDataBytes + IntoDataBytes { type Unit;