use alloc::format;
use core::any::type_name;
use crate::EtError;
pub mod agilent;
pub mod common;
pub mod fasta;
pub mod fastq;
pub mod flow;
pub mod inficon;
#[cfg(feature = "std")]
pub mod png;
pub mod sam;
pub mod thermo;
pub mod tsv;
pub mod tsv_inference;
pub trait FromSlice<'b: 's, 's>: Sized + Default {
type State: core::fmt::Debug + Default + 's;
fn parse(
_buffer: &[u8],
_eof: bool,
_consumed: &mut usize,
_state: &mut Self::State,
) -> Result<bool, EtError> {
Ok(true)
}
fn get(&mut self, _buffer: &'b [u8], _state: &'s Self::State) -> Result<(), EtError> {
Ok(())
}
fn extract(buffer: &'b [u8], state: &'s Self::State) -> Result<Self, EtError>
where
Self::State: 'static,
Self: 's,
{
let mut val = Self::default();
Self::get(&mut val, buffer, state)?;
Ok(val)
}
}
#[inline]
pub(crate) fn extract<'b: 's, 's, T>(
buffer: &'b [u8],
consumed: &mut usize,
state: &'s mut <T as FromSlice<'b, 's>>::State,
) -> Result<T, EtError>
where
T: FromSlice<'b, 's> + Default,
{
match extract_opt(buffer, false, consumed, state)? {
None => Err(format!(
"Tried to extract {}, but parser indicated no more.",
type_name::<T>()
)
.into()),
Some(value) => Ok(value),
}
}
#[inline]
pub(crate) fn extract_opt<'b: 's, 's, T>(
buffer: &'b [u8],
eof: bool,
consumed: &mut usize,
state: &'s mut <T as FromSlice<'b, 's>>::State,
) -> Result<Option<T>, EtError>
where
T: FromSlice<'b, 's> + Default,
{
let start = *consumed;
if !T::parse(&buffer[start..], eof, consumed, state)? {
return Ok(None);
}
let mut record = T::default();
T::get(&mut record, &buffer[start..*consumed], state)?;
Ok(Some(record))
}
#[derive(Clone, Copy, Debug, Default)]
pub enum Endian {
Big,
#[default]
Little,
}