use std::panic::Location;
use crate::key::Key;
use crate::transport::Transport;
use crate::type_name::TypeName;
pub struct Inputs {
pub(crate) keys: Vec<InputKey>,
}
#[derive(Clone)]
pub(crate) struct InputKey {
pub(crate) key: Key,
pub(crate) also: Vec<TypeName>,
pub(crate) location: &'static Location<'static>,
}
impl Inputs {
pub(crate) fn new() -> Self {
Inputs { keys: Vec::new() }
}
#[track_caller]
pub fn input<T: Send + Sync + 'static>(&mut self) -> &mut Self {
self.keys.push(InputKey { key: Key::of::<T, ()>(), also: Vec::new(), location: Location::caller() });
self
}
pub fn also_seeded_by<U: Transport>(&mut self) -> &mut Self {
if let Some(last) = self.keys.last_mut() {
let seeder = TypeName::of::<U>();
if !last.also.contains(&seeder) {
last.also.push(seeder);
}
}
self
}
}