From fb0c1acbed51a7a370e227770034463d11e1b236 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 24 Jun 2022 21:09:25 +0200 Subject: [PATCH] Update documentation on PersistentField --- src/param/internals.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/param/internals.rs b/src/param/internals.rs index 3491f70a..2e0aef39 100644 --- a/src/param/internals.rs +++ b/src/param/internals.rs @@ -90,16 +90,22 @@ pub enum ParamPtr { unsafe impl Send for ParamPtr {} unsafe impl Sync for ParamPtr {} -/// The functinoality needed for persisting a field to the plugin's state, and for restoring values -/// when loading old state. +/// Handles the functionality needed for persisting a non-parameter fields in a plugin's state. +/// These types can be used with [`Params`]' `#[persist = "..."]` attributes. /// -/// TODO: Modifying these fields (or any parameter for that matter) should mark the plugin's state -/// as dirty. +/// This should be implemented for some type with interior mutability containing a `T`. +// +// TODO: Modifying these fields (or any parameter for that matter) should mark the plugin's state +// as dirty. pub trait PersistentField<'a, T>: Send + Sync where T: serde::Serialize + serde::Deserialize<'a>, { + /// Update the stored `T` value using interior mutability. fn set(&self, new_value: T); + + /// Get a reference to the stored `T` value, and apply a function to it. This is used to + /// serialize the `T` value. fn map(&self, f: F) -> R where F: Fn(&T) -> R;