#[cfg(not(feature = "no-std"))]
use crate::ToCLSource;
use super::{Combiner, Eval};
#[cfg_attr(not(feature = "no-std"), doc = "```")]
#[cfg_attr(feature = "no-std", doc = "```ignore")]
#[derive(Debug, Clone, Copy)]
pub struct Resolve<T> {
pub val: T,
pub marker: &'static str,
}
pub trait ToMarker<T, R> {
#[cfg_attr(not(feature = "no-std"), doc = "```")]
#[cfg_attr(feature = "no-std", doc = "```ignore")]
fn to_marker(self) -> R;
}
impl<T: Default> ToMarker<T, Resolve<T>> for &'static str {
#[inline]
fn to_marker(self) -> Resolve<T> {
Resolve::with_marker(self)
}
}
impl<T: Default> ToMarker<T, (Resolve<T>, Resolve<T>)> for (&'static str, &'static str) {
#[inline]
fn to_marker(self) -> (Resolve<T>, Resolve<T>) {
(Resolve::with_marker(self.0), Resolve::with_marker(self.1))
}
}
pub trait ToVal<T = Self> {
fn to_val(self) -> Resolve<T>;
}
impl<T> ToVal<T> for T {
#[inline]
fn to_val(self) -> Resolve<T> {
Resolve::with_val(self)
}
}
impl<T: Default> Default for Resolve<T> {
#[inline]
fn default() -> Self {
Self {
val: T::default(),
marker: "x",
}
}
}
impl<T> Resolve<T> {
#[cfg_attr(not(feature = "no-std"), doc = "```")]
#[cfg_attr(feature = "no-std", doc = "```ignore")]
#[inline]
pub fn with_val(val: T) -> Self {
Resolve { val, marker: "x" }
}
#[cfg_attr(not(feature = "no-std"), doc = "```")]
#[cfg_attr(feature = "no-std", doc = "```ignore")]
#[inline]
pub fn with_marker(marker: &'static str) -> Self
where
T: Default,
{
Resolve {
val: T::default(),
marker,
}
}
}
impl<T> Eval<T> for Resolve<T> {
#[inline]
fn eval(self) -> T {
self.val
}
}
#[cfg(not(feature = "no-std"))]
impl<T> ToCLSource for Resolve<T> {
#[inline]
fn to_cl_source(&self) -> String {
self.marker.to_string()
}
}
impl<T> Combiner for Resolve<T> {}