#[cfg(feature = "std")]
use std::io::{Read, Result as IoResult};
use fearless_simd::Level;
use super::{
hash256_with_level,
vperm::{CpuBackend, detect_level},
};
use crate::stream::{StreamCore, impl_stream_api};
#[derive(Clone, Debug)]
pub struct Stream {
core: StreamCore,
level: Level,
}
impl Stream {
#[must_use]
#[inline]
pub fn new(data: &[u8]) -> Self {
Self::with_level(data, detect_level())
}
#[must_use]
#[inline]
pub fn with_level(data: &[u8], level: Level) -> Self {
Self::from_root_with_level(hash256_with_level(data, level), level)
}
#[must_use]
#[inline]
pub fn from_root(root: [u8; 32]) -> Self {
Self::from_root_with_level(root, detect_level())
}
#[must_use]
#[inline]
pub const fn from_root_with_level(root: [u8; 32], level: Level) -> Self {
Self {
core: StreamCore::from_root(root),
level,
}
}
#[inline(always)]
const fn backend(&self) -> CpuBackend {
CpuBackend(self.level)
}
}
impl_stream_api!(Stream, core);
impl PartialEq for Stream {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.core == other.core
}
}
impl Eq for Stream {}