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

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.

Get value from ext state.

Returns None if no value saved in REAPER.

Panics

If value of the wrong type stored in the same section/key.

Set the value to ext state.

Erase ext value, but keep the object.

Trait Implementations

Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
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 more
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more
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
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.