1
0
Fork 0

Require PartialEq on plain parameter types

So you can compare them in parameter widgets.
This commit is contained in:
Robbert van der Helm 2022-03-05 19:50:12 +01:00
parent b70af50fcd
commit 03eef2c832
3 changed files with 7 additions and 7 deletions

View file

@ -201,7 +201,7 @@ impl DiopserParams {
} }
} }
#[derive(Enum, Debug)] #[derive(Enum, Debug, PartialEq)]
enum SpreadStyle { enum SpreadStyle {
Octaves, Octaves,
Linear, Linear,

View file

@ -22,7 +22,7 @@ pub use integer::IntParam;
/// Describes a single parameter of any type. /// Describes a single parameter of any type.
pub trait Param: Display { pub trait Param: Display {
/// The plain parameter type. /// The plain parameter type.
type Plain; type Plain: PartialEq;
/// Get the human readable name for this parameter. /// Get the human readable name for this parameter.
fn name(&self) -> &'static str; fn name(&self) -> &'static str;

View file

@ -46,7 +46,7 @@ pub trait Enum {
/// An [`IntParam`]-backed categorical parameter that allows convenient conversion to and from a /// An [`IntParam`]-backed categorical parameter that allows convenient conversion to and from a
/// simple enum. This enum must derive the re-exported [Enum] trait. Check the trait's documentation /// simple enum. This enum must derive the re-exported [Enum] trait. Check the trait's documentation
/// for more information on how this works. /// for more information on how this works.
pub struct EnumParam<T: Enum> { pub struct EnumParam<T: Enum + PartialEq> {
/// A type-erased version of this parameter so the wrapper can do its thing without needing to /// A type-erased version of this parameter so the wrapper can do its thing without needing to
/// know about `T`. /// know about `T`.
inner: EnumParamInner, inner: EnumParamInner,
@ -65,7 +65,7 @@ pub struct EnumParamInner {
variants: &'static [&'static str], variants: &'static [&'static str],
} }
impl<T: Enum + Default> Default for EnumParam<T> { impl<T: Enum + PartialEq + Default> Default for EnumParam<T> {
fn default() -> Self { fn default() -> Self {
let variants = T::variants(); let variants = T::variants();
@ -86,7 +86,7 @@ impl<T: Enum + Default> Default for EnumParam<T> {
} }
} }
impl<T: Enum> Display for EnumParam<T> { impl<T: Enum + PartialEq> Display for EnumParam<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f) self.inner.fmt(f)
} }
@ -98,7 +98,7 @@ impl Display for EnumParamInner {
} }
} }
impl<T: Enum> Param for EnumParam<T> { impl<T: Enum + PartialEq> Param for EnumParam<T> {
type Plain = T; type Plain = T;
fn name(&self) -> &'static str { fn name(&self) -> &'static str {
@ -237,7 +237,7 @@ impl Param for EnumParamInner {
} }
} }
impl<T: Enum + 'static> EnumParam<T> { impl<T: Enum + PartialEq + 'static> EnumParam<T> {
/// Build a new [Self]. Use the other associated functions to modify the behavior of the /// Build a new [Self]. Use the other associated functions to modify the behavior of the
/// parameter. /// parameter.
pub fn new(name: &'static str, default: T) -> Self { pub fn new(name: &'static str, default: T) -> Self {