cargo fmt

This commit is contained in:
Olivier 'reivilibre' 2023-05-07 23:41:44 +01:00
parent 1d29cf2cfa
commit b01cc2b6fa
7 changed files with 18 additions and 31 deletions

View File

@ -1,4 +1,2 @@
#[cfg(feature = "zstd")]
pub mod zstd;

View File

@ -1,8 +1,8 @@
use crate::{AutoDelaminate, AutoLaminate, ByteLamination};
use std::borrow::Cow;
use std::cmp::max;
use std::error::Error;
use std::marker::PhantomData;
use crate::{AutoDelaminate, AutoLaminate, ByteLamination};
/// Wrapper that performs Zstd (de)compression on the bytes.
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
@ -63,7 +63,6 @@ impl<'a, T> Zstd<'a, T> {
}
}
impl<'a, T: AutoLaminate<U> + ByteLamination<'a> + 'a, U> AutoLaminate<U> for Zstd<'a, T> {
fn laminate(item: U) -> Result<Self, Box<dyn Error>> {
let lamination = T::laminate(item)?;
@ -74,7 +73,10 @@ impl<'a, T: AutoLaminate<U> + ByteLamination<'a> + 'a, U> AutoLaminate<U> for Zs
impl<'a, T: AutoDelaminate<U> + ByteLamination<'a>, U> AutoDelaminate<U> for Zstd<'a, T> {
fn delaminate(self) -> Result<U, Box<dyn Error>> {
let memory_limit = max(DEFAULT_MEMORY_LIMIT_MINIMUM, DEFAULT_MEMORY_LIMIT_MULTIPLIER * self.bytes.len());
let memory_limit = max(
DEFAULT_MEMORY_LIMIT_MINIMUM,
DEFAULT_MEMORY_LIMIT_MULTIPLIER * self.bytes.len(),
);
let bytes = self.decompress(memory_limit)?;
T::try_from_bytes(Cow::Owned(bytes))?.delaminate()
}

View File

@ -16,11 +16,10 @@
use std::borrow::Cow;
use std::error::Error;
pub mod raw;
pub mod compression;
pub mod raw;
pub mod serialisation;
/// Helper trait for when it's possible to construct a lamination without any extra inputs at any
/// steps.
pub trait AutoLaminate<T>: Sized {
@ -42,7 +41,6 @@ pub trait AutoDelaminateBorrowed<'a, T> {
fn delaminate(&'a self) -> Result<T, Box<dyn Error>>;
}
pub trait ByteLamination<'a>: Sized {
/// Get the raw bytes from this lamination.
/// If possible, this should return borrowed bytes.

View File

@ -1,6 +1,6 @@
use crate::ByteLamination;
use std::borrow::Cow;
use std::error::Error;
use crate::ByteLamination;
impl<'a> ByteLamination<'a> for Cow<'a, [u8]> {
fn as_cow_bytes(&self) -> Cow<'_, [u8]> {
@ -41,12 +41,8 @@ impl<'a> ByteLamination<'a> for String {
fn try_from_bytes(bytes: Cow<'a, [u8]>) -> Result<Self, Box<dyn Error>> {
Ok(match bytes {
Cow::Borrowed(bslice) => {
std::str::from_utf8(bslice)?.to_owned()
}
Cow::Owned(bvec) => {
String::from_utf8(bvec)?
}
Cow::Borrowed(bslice) => std::str::from_utf8(bslice)?.to_owned(),
Cow::Owned(bvec) => String::from_utf8(bvec)?,
})
}
}
@ -62,12 +58,8 @@ impl<'a> ByteLamination<'a> for Cow<'a, str> {
fn try_from_bytes(bytes: Cow<'a, [u8]>) -> Result<Self, Box<dyn Error>> {
Ok(match bytes {
Cow::Borrowed(bslice) => {
Cow::Borrowed(std::str::from_utf8(bslice)?)
}
Cow::Owned(bvec) => {
Cow::Owned(String::from_utf8(bvec)?)
}
Cow::Borrowed(bslice) => Cow::Borrowed(std::str::from_utf8(bslice)?),
Cow::Owned(bvec) => Cow::Owned(String::from_utf8(bvec)?),
})
}
}
}

View File

@ -1,4 +1,3 @@
#[cfg(feature = "cbor")]
pub mod cbor;

View File

@ -1,9 +1,9 @@
use crate::{AutoDelaminate, AutoLaminate, ByteLamination};
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::borrow::Cow;
use std::error::Error;
use std::marker::PhantomData;
use serde::Serialize;
use serde::de::DeserializeOwned;
use crate::{AutoDelaminate, AutoLaminate, ByteLamination};
/// Wrapper that uses serde to perform BARE serialisation on an arbitrary type.
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
@ -55,7 +55,6 @@ impl<'a, T: DeserializeOwned> SerdeBare<'a, T> {
}
}
impl<'a, T: Serialize> AutoLaminate<T> for SerdeBare<'a, T> {
fn laminate(item: T) -> Result<Self, Box<dyn Error>> {
Self::serialise(&item)

View File

@ -1,9 +1,9 @@
use crate::{AutoDelaminate, AutoDelaminateBorrowed, AutoLaminate, ByteLamination};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::error::Error;
use std::marker::PhantomData;
use serde::{Deserialize, Serialize};
use serde::de::DeserializeOwned;
use crate::{AutoDelaminate, AutoDelaminateBorrowed, AutoLaminate, ByteLamination};
/// Wrapper that uses serde to perform CBOR serialisation on an arbitrary type.
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
@ -55,7 +55,6 @@ impl<'a, T: Deserialize<'a>> SerdeCbor<'a, T> {
}
}
impl<'a, T: Serialize> AutoLaminate<T> for SerdeCbor<'a, T> {
fn laminate(item: T) -> Result<Self, Box<dyn Error>> {
Self::serialise(&item)