use alloc::vec::Vec;
use crate::bytes::{ReturnOutputByteCount, RuntimeStateByteCount};
use super::limits::StepCount;
#[derive(Debug, PartialEq, Eq)]
pub enum RunOutcome {
Stable(RuntimeStateSnapshot),
Return(ReturnOutput),
}
#[derive(Debug, PartialEq, Eq)]
pub struct RuntimeStateSnapshot {
bytes: Vec<u8>,
}
impl RuntimeStateSnapshot {
pub(crate) fn from_vec(bytes: Vec<u8>) -> Self {
Self { bytes }
}
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
&self.bytes
}
#[must_use]
pub fn into_vec(self) -> Vec<u8> {
self.bytes
}
#[must_use]
pub fn byte_count(&self) -> RuntimeStateByteCount {
RuntimeStateByteCount::new(self.bytes.len())
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.bytes.is_empty()
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct ReturnOutput {
bytes: Vec<u8>,
}
impl ReturnOutput {
pub(crate) fn from_vec(bytes: Vec<u8>) -> Self {
Self { bytes }
}
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
&self.bytes
}
#[must_use]
pub fn into_vec(self) -> Vec<u8> {
self.bytes
}
#[must_use]
pub fn byte_count(&self) -> ReturnOutputByteCount {
ReturnOutputByteCount::new(self.bytes.len())
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.bytes.is_empty()
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct RunResult {
steps: StepCount,
outcome: RunOutcome,
}
impl RunResult {
pub(crate) fn stable(output: RuntimeStateSnapshot, steps: StepCount) -> Self {
Self {
steps,
outcome: RunOutcome::Stable(output),
}
}
pub(crate) fn from_return(output: ReturnOutput, steps: StepCount) -> Self {
Self {
steps,
outcome: RunOutcome::Return(output),
}
}
#[must_use]
pub const fn outcome(&self) -> &RunOutcome {
&self.outcome
}
#[must_use]
pub fn into_outcome(self) -> RunOutcome {
self.outcome
}
#[must_use]
pub const fn steps(&self) -> StepCount {
self.steps
}
}