Skip to content

Commit ce3159c

Browse files
committed
glib: provide a trait to return a ParamSpec builder with builtin default
This will be used by the `Properties` macro to use a default value as defined by the type's own `Default` implementation. As a first blanket implementation we set it for enums.
1 parent 9c05265 commit ce3159c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

glib/src/param_spec.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,20 @@ pub trait HasParamSpec {
21742174
fn param_spec_builder() -> Self::BuilderFn;
21752175
}
21762176

2177+
// unless a custom `default` attribute is specified, the macro will use this trait.
2178+
pub trait HasParamSpecDefaulted: HasParamSpec + Default {
2179+
type BuilderFnDefaulted;
2180+
fn param_spec_builder_defaulted() -> Self::BuilderFnDefaulted;
2181+
}
2182+
2183+
// Manually implement the trait for every Enum
2184+
impl<T: HasParamSpec<ParamSpec = ParamSpecEnum> + StaticType + FromGlib<i32> + IntoGlib<GlibType = i32> + Default> HasParamSpecDefaulted for T {
2185+
type BuilderFnDefaulted = fn(name: &str) -> ParamSpecEnumBuilder<T>;
2186+
fn param_spec_builder_defaulted() -> Self::BuilderFnDefaulted {
2187+
|name| Self::ParamSpec::builder(name)
2188+
}
2189+
}
2190+
21772191
impl<T: crate::value::ToValueOptional + HasParamSpec> HasParamSpec for Option<T> {
21782192
type ParamSpec = T::ParamSpec;
21792193
type SetValue = T::SetValue;

0 commit comments

Comments
 (0)