use std::{fmt, marker::PhantomData};
use serde::{Serialize, de::DeserializeOwned};
pub struct Step<Output> {
name: &'static str,
marker: PhantomData<fn() -> Output>,
}
impl<Output> Copy for Step<Output> {}
impl<Output> Clone for Step<Output> {
fn clone(&self) -> Self {
*self
}
}
impl<Output> Step<Output> {
pub const fn name(self) -> &'static str {
self.name
}
pub fn keyed(self, key: impl Into<String>) -> KeyedStep<Output> {
KeyedStep { step: self, key: key.into() }
}
}
impl<Output> Step<Output>
where
Output: Serialize + DeserializeOwned + Send + 'static,
{
pub const fn new(name: &'static str) -> Self {
Self { name, marker: PhantomData }
}
}
impl<Output> fmt::Debug for Step<Output> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Step").field(&self.name).finish()
}
}
pub struct KeyedStep<Output> {
step: Step<Output>,
key: String,
}
impl<Output> Clone for KeyedStep<Output> {
fn clone(&self) -> Self {
Self { step: self.step, key: self.key.clone() }
}
}
impl<Output> KeyedStep<Output> {
pub const fn step(&self) -> Step<Output> {
self.step
}
pub fn key(&self) -> &str {
&self.key
}
}
impl<Output> fmt::Debug for KeyedStep<Output> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("KeyedStep")
.field("step", &self.step.name())
.field("key", &self.key)
.finish()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Sleep {
name: &'static str,
}
impl Sleep {
pub const fn new(name: &'static str) -> Self {
Self { name }
}
pub const fn name(self) -> &'static str {
self.name
}
}