use std::ops;
use crate::{
base::num::bounded::U32,
buffer::{
self,
bytes::{self, bounded},
},
};
#[repr(transparent)]
pub struct Input<T, const MAX: usize = { bounded::MAX }>(T);
impl<T, const MAX: usize> Input<T, MAX> {
pub(in crate::buffer) fn into_inner(self) -> T {
self.0
}
pub const unsafe fn new(value: T) -> Self {
Self(value)
}
}
impl<'a, const MAX: usize> Input<&'a [u8], MAX> {
pub(in crate::buffer) const fn into_slice(self) -> &'a [u8] {
self.0
}
}
impl<S: ?Sized> Input<buffer::View<'_, S>> {
pub unsafe fn select(mut self, range: ops::Range<usize>) -> Self {
self.0.bytes = unsafe { self.0.bytes.get_unchecked(range) };
self
}
}
impl<T: AsRef<[u8]>> Input<T> {
pub(in crate::buffer) fn count(value: &bounded::Value<T>) -> U32<0, { bounded::MAX as u32 }> {
use crate::base::num::bounded;
let len = value.as_ref().len();
unsafe { bounded::raw::u32(len as u32) }
}
}
impl Input<&[u8]> {
pub(in crate::buffer) const fn prefix<const MAX: usize, const END: u32>(
prefix: &bytes::Prefix<'_, MAX>,
) -> U32<0, END> {
use crate::base::num::bounded;
const { assert!(MAX <= END as usize) };
let len = prefix.as_slice().len();
unsafe { bounded::raw::u32(len as u32) }
}
}