use std::collections::HashMap;
use std::hash::Hash;
use crate::event_database::RecordedEvent;
use crate::TestGetValue;
pub trait ExtraKeys {
const ALLOWED_KEYS: &'static [&'static str];
fn into_ffi_extra(self) -> HashMap<String, String>;
}
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum NoExtraKeys {}
impl ExtraKeys for NoExtraKeys {
const ALLOWED_KEYS: &'static [&'static str] = &[];
fn into_ffi_extra(self) -> HashMap<String, String> {
unimplemented!("non-existing extra keys can't be turned into a list")
}
}
pub enum EventRecordingError {
InvalidId,
InvalidExtraKey,
}
impl TryFrom<i32> for NoExtraKeys {
type Error = EventRecordingError;
fn try_from(_value: i32) -> Result<Self, Self::Error> {
Err(EventRecordingError::InvalidExtraKey)
}
}
impl TryFrom<&str> for NoExtraKeys {
type Error = EventRecordingError;
fn try_from(_value: &str) -> Result<Self, Self::Error> {
Err(EventRecordingError::InvalidExtraKey)
}
}
pub trait Event: TestGetValue<Output = Vec<RecordedEvent>> {
type Extra: ExtraKeys;
fn record<M: Into<Option<Self::Extra>>>(&self, extra: M);
}