use std::fmt;
use crate::{CoreError, types::MAX_INPUT_BYTES};
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct InputId(pub(crate) u64);
impl fmt::Debug for InputId {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("InputId(<opaque>)")
}
}
impl InputId {
pub const fn get(self) -> u64 {
self.0
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InputRequest {
id: InputId,
bytes: Vec<u8>,
}
impl InputRequest {
pub(crate) fn new(id: InputId, bytes: Vec<u8>) -> Result<Self, CoreError> {
if bytes.is_empty() || bytes.len() > MAX_INPUT_BYTES {
return Err(CoreError::InputTooLarge { size: bytes.len() });
}
Ok(Self { id, bytes })
}
pub const fn id(&self) -> InputId {
self.id
}
pub fn bytes(&self) -> &[u8] {
&self.bytes
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum InputOutcome {
Accepted,
Rejected,
Uncertain,
Superseded,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct InputResult {
pub id: InputId,
pub outcome: InputOutcome,
}