use super::super::engine::EncodeContext;
pub(in crate::transcode) struct EncodeAttempt<'a, Value, Unit> {
value: &'a Value,
input_index: usize,
output: &'a mut [Unit],
output_index: usize,
}
impl<'a, Value, Unit> EncodeAttempt<'a, Value, Unit> {
#[must_use]
#[inline]
pub(in crate::transcode) fn new(
value: &'a Value,
input_index: usize,
output: &'a mut [Unit],
output_index: usize,
) -> Self {
Self {
value,
input_index,
output,
output_index,
}
}
#[must_use = "the borrowed input value should be inspected"]
#[inline]
pub(in crate::transcode) fn value(&self) -> &Value {
self.value
}
#[must_use]
#[inline]
pub(in crate::transcode) const fn input_index(&self) -> usize {
self.input_index
}
#[must_use]
#[inline]
pub(in crate::transcode) fn available_output(&self) -> usize {
self.output.len().saturating_sub(self.output_index)
}
#[must_use]
#[inline]
pub(in crate::transcode) fn context(&self) -> EncodeContext<'_, Value> {
EncodeContext::new(self.value, self.input_index, self.output_index, self.available_output())
}
#[must_use = "the encode attempt parts must be used"]
#[inline]
pub(in crate::transcode) fn into_parts(self) -> (&'a Value, usize, &'a mut [Unit], usize) {
(self.value, self.input_index, self.output, self.output_index)
}
}