1
0
Fork 0

Implement Params for Arc<P: Params>

This is useful for partial generic UIs.
This commit is contained in:
Robbert van der Helm 2022-07-23 18:12:02 +02:00
parent 278ae227a7
commit dc97fb1019

View file

@ -1,6 +1,7 @@
//! Implementation details for the parameter management.
use std::collections::BTreeMap;
use std::sync::Arc;
use super::{Param, ParamFlags, ParamMut};
@ -95,6 +96,21 @@ pub unsafe trait Params: 'static + Send + Sync {
fn deserialize_fields(&self, serialized: &BTreeMap<String, String>) {}
}
/// This may be useful when building generic UIs using nested `Params` objects.
unsafe impl<P: Params> Params for Arc<P> {
fn param_map(&self) -> Vec<(String, ParamPtr, String)> {
self.as_ref().param_map()
}
fn serialize_fields(&self) -> BTreeMap<String, String> {
self.as_ref().serialize_fields()
}
fn deserialize_fields(&self, serialized: &BTreeMap<String, String>) {
self.as_ref().deserialize_fields(serialized)
}
}
/// Internal pointers to parameters. This is an implementation detail used by the wrappers for type
/// erasure.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]