use core::{cell::RefCell, marker::PhantomData};
use serde::{Deserialize, Serialize};
use crate::{
Error,
corpus::{Corpus, CorpusId, Testcase},
};
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
pub struct NopCorpus<I> {
empty: Option<CorpusId>,
phantom: PhantomData<I>,
}
impl<I> Corpus<I> for NopCorpus<I> {
#[inline]
fn count(&self) -> usize {
0
}
fn count_disabled(&self) -> usize {
0
}
#[inline]
fn count_all(&self) -> usize {
0
}
#[inline]
fn add(&mut self, _testcase: Testcase<I>) -> Result<CorpusId, Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
}
#[inline]
fn add_disabled(&mut self, _testcase: Testcase<I>) -> Result<CorpusId, Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
}
#[inline]
fn replace(&mut self, _id: CorpusId, _testcase: Testcase<I>) -> Result<Testcase<I>, Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
}
#[inline]
fn remove(&mut self, _id: CorpusId) -> Result<Testcase<I>, Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
}
#[inline]
fn get(&self, _id: CorpusId) -> Result<&RefCell<Testcase<I>>, Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
}
#[inline]
fn get_from_all(&self, _id: CorpusId) -> Result<&RefCell<Testcase<I>>, Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
}
#[inline]
fn current(&self) -> &Option<CorpusId> {
&self.empty
}
#[inline]
fn current_mut(&mut self) -> &mut Option<CorpusId> {
&mut self.empty
}
#[inline]
fn next(&self, _id: CorpusId) -> Option<CorpusId> {
None
}
#[inline]
fn peek_free_id(&self) -> CorpusId {
CorpusId::from(0_usize)
}
#[inline]
fn prev(&self, _id: CorpusId) -> Option<CorpusId> {
None
}
#[inline]
fn first(&self) -> Option<CorpusId> {
None
}
#[inline]
fn last(&self) -> Option<CorpusId> {
None
}
#[inline]
fn nth(&self, _nth: usize) -> CorpusId {
CorpusId::from(0_usize)
}
#[inline]
fn nth_from_all(&self, _nth: usize) -> CorpusId {
CorpusId::from(0_usize)
}
#[inline]
fn load_input_into(&self, _testcase: &mut Testcase<I>) -> Result<(), Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
}
#[inline]
fn store_input_from(&self, _testcase: &Testcase<I>) -> Result<(), Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
}
}
impl<I> NopCorpus<I> {
#[must_use]
pub fn new() -> Self {
Self {
empty: None,
phantom: PhantomData {},
}
}
}