pub struct ExtState<'a, T: Serialize + DeserializeOwned + Clone + Debug, O: HasExtState> { /* private fields */ }
Expand description
Serializes extension data.
This struct should be used instead of simple set_ext_state
and get_ext_state
calls.
The features, that make it better are:
- It serializes not strings, but anything, can be serialized by serde crate.
- It provides the similar interface as for global ext state values, as well as to project or other objects ext data. Currently supported: Project, Track, TrackSend, Envelope, Item
- it erases data, if in process of development you decided to turn the persistence off.
- it can be initialized with value, but only once, if persistence is needed.
Also, it is very idiomatic and type-safe, so it ideally suits as gui state etc.
Note
Be careful with ext section and key. If two different states of different types are saved for one key — it will panic at get().
Usage
use rea_rs::{ExtState, HasExtState, Reaper, Project};
let rpr = Reaper::get();
let mut state =
ExtState::new("test section", "first", Some(10), true, rpr);
assert_eq!(state.get().expect("can not get value"), 10);
state.set(56);
assert_eq!(state.get().expect("can not get value"), 56);
state.delete();
assert!(state.get().is_none());
let mut pr = rpr.current_project();
let mut state: ExtState<u32, Project> =
ExtState::new("test section", "first", None, true, &pr);
assert_eq!(state.get().expect("can not get value"), 10);
state.set(56);
assert_eq!(state.get().expect("can not get value"), 56);
state.delete();
assert!(state.get().is_none());
let tr = pr.get_track_mut(0).unwrap();
let mut state = ExtState::new("testsection", "first", 45, false, &tr);
assert_eq!(state.get().expect("can not get value"), 45);
state.set(15);
assert_eq!(state.get().expect("can not get value"), 15);
state.delete();
assert_eq!(state.get(), None);
Implementations
sourceimpl<'a, T: Serialize + DeserializeOwned + Clone + Debug, O: HasExtState> ExtState<'a, T, O>
impl<'a, T: Serialize + DeserializeOwned + Clone + Debug, O: HasExtState> ExtState<'a, T, O>
sourcepub fn new(
section: impl Into<String>,
key: impl Into<String>,
value: impl Into<Option<T>>,
persist: bool,
object: &'a O
) -> Self
pub fn new(
section: impl Into<String>,
key: impl Into<String>,
value: impl Into<Option<T>>,
persist: bool,
object: &'a O
) -> Self
Create ext state object.
If Some(value) provided, but persist is true, only first call to the ExtState::new will initialize it. Later will keep previous value.
Trait Implementations
sourceimpl<'a, T: Debug + Serialize + DeserializeOwned + Clone + Debug, O: Debug + HasExtState> Debug for ExtState<'a, T, O>
impl<'a, T: Debug + Serialize + DeserializeOwned + Clone + Debug, O: Debug + HasExtState> Debug for ExtState<'a, T, O>
sourceimpl<'a, T: PartialEq + Serialize + DeserializeOwned + Clone + Debug, O: PartialEq + HasExtState> PartialEq<ExtState<'a, T, O>> for ExtState<'a, T, O>
impl<'a, T: PartialEq + Serialize + DeserializeOwned + Clone + Debug, O: PartialEq + HasExtState> PartialEq<ExtState<'a, T, O>> for ExtState<'a, T, O>
impl<'a, T: Serialize + DeserializeOwned + Clone + Debug, O: HasExtState> StructuralPartialEq for ExtState<'a, T, O>
Auto Trait Implementations
impl<'a, T, O> RefUnwindSafe for ExtState<'a, T, O>where
O: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, O> Send for ExtState<'a, T, O>where
O: Sync,
T: Send,
impl<'a, T, O> Sync for ExtState<'a, T, O>where
O: Sync,
T: Sync,
impl<'a, T, O> Unpin for ExtState<'a, T, O>where
T: Unpin,
impl<'a, T, O> UnwindSafe for ExtState<'a, T, O>where
O: RefUnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read moresourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read moresourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read moresourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more