pub mod bytes;
pub use bytes::BytesInput;
pub mod encoded;
pub use encoded::*;
pub mod gramatron;
pub use gramatron::*;
pub mod generalized;
pub use generalized::*;
#[cfg(feature = "nautilus")]
pub mod nautilus;
use alloc::{
string::{String, ToString},
vec::Vec,
};
use core::{clone::Clone, fmt::Debug};
#[cfg(feature = "std")]
use std::{fs::File, hash::Hash, io::Read, path::Path};
#[cfg(feature = "nautilus")]
pub use nautilus::*;
use serde::{Deserialize, Serialize};
#[cfg(feature = "std")]
use crate::bolts::fs::write_file_atomic;
use crate::{bolts::ownedref::OwnedSlice, Error};
#[cfg(not(feature = "std"))]
pub trait Input: Clone + Serialize + serde::de::DeserializeOwned + Debug {
fn to_file<P>(&self, _path: P) -> Result<(), Error> {
Err(Error::not_implemented("Not supported in no_std"))
}
fn from_file<P>(_path: P) -> Result<Self, Error> {
Err(Error::not_implemented("Not supprted in no_std"))
}
fn generate_name(&self, idx: usize) -> String;
fn wrapped_as_testcase(&mut self) {}
}
#[cfg(feature = "std")]
pub trait Input: Clone + Serialize + serde::de::DeserializeOwned + Debug {
fn to_file<P>(&self, path: P) -> Result<(), Error>
where
P: AsRef<Path>,
{
write_file_atomic(path, &postcard::to_allocvec(self)?)
}
fn from_file<P>(path: P) -> Result<Self, Error>
where
P: AsRef<Path>,
{
let mut file = File::open(path)?;
let mut bytes: Vec<u8> = vec![];
file.read_to_end(&mut bytes)?;
Ok(postcard::from_bytes(&bytes)?)
}
fn generate_name(&self, idx: usize) -> String;
fn wrapped_as_testcase(&mut self) {}
}
#[derive(Copy, Clone, Serialize, Deserialize, Debug, Hash)]
pub struct NopInput {}
impl Input for NopInput {
fn generate_name(&self, _idx: usize) -> String {
"nop-input".to_string()
}
}
impl HasTargetBytes for NopInput {
fn target_bytes(&self) -> OwnedSlice<u8> {
OwnedSlice::from(vec![0])
}
}
pub trait HasTargetBytes {
fn target_bytes(&self) -> OwnedSlice<u8>;
}
pub trait HasBytesVec {
fn bytes(&self) -> &[u8];
fn bytes_mut(&mut self) -> &mut Vec<u8>;
}