Skip to main content

scosh_core/
input.rs

1//! Bounded, ordered input values for the host-to-session path.
2
3use std::fmt;
4
5use crate::{CoreError, types::MAX_INPUT_BYTES};
6
7/// Opaque identifier for one input submission.
8#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
9pub struct InputId(pub(crate) u64);
10
11impl fmt::Debug for InputId {
12    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
13        formatter.write_str("InputId(<opaque>)")
14    }
15}
16
17impl InputId {
18    pub const fn get(self) -> u64 {
19        self.0
20    }
21}
22
23/// Input bytes emitted by the core for the host's transport adapter.
24#[derive(Clone, Debug, Eq, PartialEq)]
25pub struct InputRequest {
26    id: InputId,
27    bytes: Vec<u8>,
28}
29
30impl InputRequest {
31    pub(crate) fn new(id: InputId, bytes: Vec<u8>) -> Result<Self, CoreError> {
32        if bytes.is_empty() || bytes.len() > MAX_INPUT_BYTES {
33            return Err(CoreError::InputTooLarge { size: bytes.len() });
34        }
35        Ok(Self { id, bytes })
36    }
37
38    pub const fn id(&self) -> InputId {
39        self.id
40    }
41
42    pub fn bytes(&self) -> &[u8] {
43        &self.bytes
44    }
45}
46
47/// Result reported by the transport adapter for one input request.
48#[derive(Clone, Copy, Debug, Eq, PartialEq)]
49pub enum InputOutcome {
50    Accepted,
51    Rejected,
52    Uncertain,
53    Superseded,
54}
55
56/// Owned input result returned to a host after transport completion.
57#[derive(Clone, Copy, Debug, Eq, PartialEq)]
58pub struct InputResult {
59    pub id: InputId,
60    pub outcome: InputOutcome,
61}