#[repr(C)]pub struct DatasetMergeCallback {
pub cb: DatasetMergeCallbackType,
pub callable: OptionRefAny,
}Expand description
A callback function used to merge the state of an old dataset into a new one.
This enables components with heavy internal state (video players, WebGL contexts) to preserve their resources across frames, while the DOM tree is recreated.
The callback receives both the old and new datasets as RefAny (cheap shallow clones)
and returns the dataset that should be used for the new node.
§Example
fn merge_video_state(new_data: RefAny, old_data: RefAny) -> RefAny {
// Transfer heavy resources from old to new
if let (Some(mut new), Some(old)) = (
new_data.downcast_mut::<VideoState>(),
old_data.downcast_ref::<VideoState>()
) {
new.decoder = old.decoder.take();
new.gl_texture = old.gl_texture.take();
}
new_data // Return the merged state
}Fields§
§cb: DatasetMergeCallbackTypeThe function pointer that performs the merge.
Signature: fn(new_data: RefAny, old_data: RefAny) -> RefAny
callable: OptionRefAnyOptional callable for FFI language bindings (Python, etc.)
When set, the FFI layer can invoke this instead of cb.
Implementations§
Source§impl DatasetMergeCallback
impl DatasetMergeCallback
Sourcepub fn from_ptr(cb: DatasetMergeCallbackType) -> Self
pub fn from_ptr(cb: DatasetMergeCallbackType) -> Self
Build from a raw DatasetMergeCallbackType function pointer (callable =
None). The concrete parameter is a coercion site, so callers can pass a
bare extern "C" fn item without an as DatasetMergeCallbackType cast.
Trait Implementations§
Source§impl Clone for DatasetMergeCallback
impl Clone for DatasetMergeCallback
Source§fn clone(&self) -> DatasetMergeCallback
fn clone(&self) -> DatasetMergeCallback
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DatasetMergeCallback
impl Debug for DatasetMergeCallback
impl Eq for DatasetMergeCallback
Source§impl From<extern "C" fn(RefAny, RefAny) -> RefAny> for DatasetMergeCallback
Allow creating DatasetMergeCallback from a raw function pointer.
This enables the Into<DatasetMergeCallback> pattern for Python bindings.
impl From<extern "C" fn(RefAny, RefAny) -> RefAny> for DatasetMergeCallback
Allow creating DatasetMergeCallback from a raw function pointer.
This enables the Into<DatasetMergeCallback> pattern for Python bindings.