binary code (renamed, it was mistaken for the crate's binary)

This commit is contained in:
Breval Ferrari 2025-01-17 22:49:59 -05:00
parent 5e078c951d
commit e1edc611bc
No known key found for this signature in database
GPG key ID: CEAB625B75A836B2
3 changed files with 32 additions and 1 deletions

View file

@ -0,0 +1,2 @@
#[path = "bin_/bytes.rs"]
mod bytes;

29
bingus/src/bin_/bytes.rs Normal file
View file

@ -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<Self, Self::Error>
where
Self: Sized,
{
Ok(bytes)
}
}
impl Bendable for Bytes {
type Unit = u8;
fn map<F: Fn(&Self::Unit) -> Self::Unit + Sync>(self, f: F) -> Self {
self.into_par_iter().map(|e| f(&e)).collect()
}
}

View file

@ -3,7 +3,7 @@ pub mod img;
pub mod snd; pub mod snd;
pub mod txt; pub mod txt;
pub type Bytes = Vec<u8>; pub(crate) type Bytes = Vec<u8>;
pub trait Bendable: TryFromDataBytes + IntoDataBytes { pub trait Bendable: TryFromDataBytes + IntoDataBytes {
type Unit; type Unit;