cargo fmt
This commit is contained in:
parent
1d29cf2cfa
commit
b01cc2b6fa
@ -1,4 +1,2 @@
|
|||||||
|
|
||||||
#[cfg(feature = "zstd")]
|
#[cfg(feature = "zstd")]
|
||||||
pub mod zstd;
|
pub mod zstd;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use crate::{AutoDelaminate, AutoLaminate, ByteLamination};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use crate::{AutoDelaminate, AutoLaminate, ByteLamination};
|
|
||||||
|
|
||||||
/// Wrapper that performs Zstd (de)compression on the bytes.
|
/// Wrapper that performs Zstd (de)compression on the bytes.
|
||||||
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
#[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> {
|
impl<'a, T: AutoLaminate<U> + ByteLamination<'a> + 'a, U> AutoLaminate<U> for Zstd<'a, T> {
|
||||||
fn laminate(item: U) -> Result<Self, Box<dyn Error>> {
|
fn laminate(item: U) -> Result<Self, Box<dyn Error>> {
|
||||||
let lamination = T::laminate(item)?;
|
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> {
|
impl<'a, T: AutoDelaminate<U> + ByteLamination<'a>, U> AutoDelaminate<U> for Zstd<'a, T> {
|
||||||
fn delaminate(self) -> Result<U, Box<dyn Error>> {
|
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)?;
|
let bytes = self.decompress(memory_limit)?;
|
||||||
T::try_from_bytes(Cow::Owned(bytes))?.delaminate()
|
T::try_from_bytes(Cow::Owned(bytes))?.delaminate()
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,10 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
pub mod raw;
|
|
||||||
pub mod compression;
|
pub mod compression;
|
||||||
|
pub mod raw;
|
||||||
pub mod serialisation;
|
pub mod serialisation;
|
||||||
|
|
||||||
|
|
||||||
/// Helper trait for when it's possible to construct a lamination without any extra inputs at any
|
/// Helper trait for when it's possible to construct a lamination without any extra inputs at any
|
||||||
/// steps.
|
/// steps.
|
||||||
pub trait AutoLaminate<T>: Sized {
|
pub trait AutoLaminate<T>: Sized {
|
||||||
@ -42,7 +41,6 @@ pub trait AutoDelaminateBorrowed<'a, T> {
|
|||||||
fn delaminate(&'a self) -> Result<T, Box<dyn Error>>;
|
fn delaminate(&'a self) -> Result<T, Box<dyn Error>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub trait ByteLamination<'a>: Sized {
|
pub trait ByteLamination<'a>: Sized {
|
||||||
/// Get the raw bytes from this lamination.
|
/// Get the raw bytes from this lamination.
|
||||||
/// If possible, this should return borrowed bytes.
|
/// If possible, this should return borrowed bytes.
|
||||||
|
20
src/raw.rs
20
src/raw.rs
@ -1,6 +1,6 @@
|
|||||||
|
use crate::ByteLamination;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use crate::ByteLamination;
|
|
||||||
|
|
||||||
impl<'a> ByteLamination<'a> for Cow<'a, [u8]> {
|
impl<'a> ByteLamination<'a> for Cow<'a, [u8]> {
|
||||||
fn as_cow_bytes(&self) -> Cow<'_, [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>> {
|
fn try_from_bytes(bytes: Cow<'a, [u8]>) -> Result<Self, Box<dyn Error>> {
|
||||||
Ok(match bytes {
|
Ok(match bytes {
|
||||||
Cow::Borrowed(bslice) => {
|
Cow::Borrowed(bslice) => std::str::from_utf8(bslice)?.to_owned(),
|
||||||
std::str::from_utf8(bslice)?.to_owned()
|
Cow::Owned(bvec) => String::from_utf8(bvec)?,
|
||||||
}
|
|
||||||
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>> {
|
fn try_from_bytes(bytes: Cow<'a, [u8]>) -> Result<Self, Box<dyn Error>> {
|
||||||
Ok(match bytes {
|
Ok(match bytes {
|
||||||
Cow::Borrowed(bslice) => {
|
Cow::Borrowed(bslice) => Cow::Borrowed(std::str::from_utf8(bslice)?),
|
||||||
Cow::Borrowed(std::str::from_utf8(bslice)?)
|
Cow::Owned(bvec) => Cow::Owned(String::from_utf8(bvec)?),
|
||||||
}
|
|
||||||
Cow::Owned(bvec) => {
|
|
||||||
Cow::Owned(String::from_utf8(bvec)?)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#[cfg(feature = "cbor")]
|
#[cfg(feature = "cbor")]
|
||||||
pub mod cbor;
|
pub mod cbor;
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
use crate::{AutoDelaminate, AutoLaminate, ByteLamination};
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
use serde::Serialize;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::marker::PhantomData;
|
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.
|
/// Wrapper that uses serde to perform BARE serialisation on an arbitrary type.
|
||||||
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
#[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> {
|
impl<'a, T: Serialize> AutoLaminate<T> for SerdeBare<'a, T> {
|
||||||
fn laminate(item: T) -> Result<Self, Box<dyn Error>> {
|
fn laminate(item: T) -> Result<Self, Box<dyn Error>> {
|
||||||
Self::serialise(&item)
|
Self::serialise(&item)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
use crate::{AutoDelaminate, AutoDelaminateBorrowed, AutoLaminate, ByteLamination};
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::marker::PhantomData;
|
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.
|
/// Wrapper that uses serde to perform CBOR serialisation on an arbitrary type.
|
||||||
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
#[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> {
|
impl<'a, T: Serialize> AutoLaminate<T> for SerdeCbor<'a, T> {
|
||||||
fn laminate(item: T) -> Result<Self, Box<dyn Error>> {
|
fn laminate(item: T) -> Result<Self, Box<dyn Error>> {
|
||||||
Self::serialise(&item)
|
Self::serialise(&item)
|
||||||
|
Loading…
Reference in New Issue
Block a user