Trait rea_rs::utils::WithReaperPtr
source · [−]pub trait WithReaperPtr<'a> {
type Ptr: Into<ReaperPointer<'a>>;
fn get_pointer(&self) -> Self::Ptr;
fn get(&self) -> Self::Ptr;
fn make_unchecked(&mut self);
fn make_checked(&mut self);
fn should_check(&self) -> bool;
fn require_valid(&self) -> ReaperResult<()> { ... }
fn require_valid_2(&self, project: &Project) -> ReaperResult<()> { ... }
fn with_valid_ptr(
&mut self,
f: impl FnMut(&mut Self) -> ReaperResult<()>
) -> ReaperResult<()> { ... }
}
Expand description
Guarantees that REAPER object has valid pointer.
Gives the API user as much control, as he wishes.
By default, implementation has to check validity with every access to the pointer e.g. with every method call. But the amount of checks can be reduced by the WithReaperPtr::with_valid_ptr() method, or by manually turning validation checks off and on by WithReaperPtr::make_unchecked and WithReaperPtr::make_checked respectively.
Implementation
get_pointer
should return raw NonNull unchecked ReaperPointer.- After invocation of
make_unchecked
, methodshould_check
has to returnfalse
. - After invocation of
make_checked
, methodshould_check
has to returntrue
. get()
call should invoke eitherrequire_valid
orrequire_valid_2
.
Required Associated Types
type Ptr: Into<ReaperPointer<'a>>
Required Methods
sourcefn get_pointer(&self) -> Self::Ptr
fn get_pointer(&self) -> Self::Ptr
Get underlying ReaperPointer.
sourcefn make_unchecked(&mut self)
fn make_unchecked(&mut self)
Turn validity checks off.
sourcefn make_checked(&mut self)
fn make_checked(&mut self)
Turn validity checks on.
sourcefn should_check(&self) -> bool
fn should_check(&self) -> bool
State of validity checks.
Provided Methods
sourcefn require_valid(&self) -> ReaperResult<()>
fn require_valid(&self) -> ReaperResult<()>
Return ReaperError::NullPtr if check failed.
Note
Will not check if turned off by
WithReaperPtr::make_unchecked
.
sourcefn require_valid_2(&self, project: &Project) -> ReaperResult<()>
fn require_valid_2(&self, project: &Project) -> ReaperResult<()>
Return ReaperError::NullPtr if check failed.
Note
Will not check if turned off by
WithReaperPtr::make_unchecked
.
sourcefn with_valid_ptr(
&mut self,
f: impl FnMut(&mut Self) -> ReaperResult<()>
) -> ReaperResult<()>
fn with_valid_ptr(
&mut self,
f: impl FnMut(&mut Self) -> ReaperResult<()>
) -> ReaperResult<()>
Perform function with only one validity check.
Returns ReaperError::NullPtr if the first check failed. Also propagates any error returned from function.