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, method should_check has to return false.
  • After invocation of make_checked, method should_check has to return true.
  • get() call should invoke either require_valid or require_valid_2.

Required Associated Types

Required Methods

Get underlying ReaperPointer.

Get underlying ReaperPointer with validity check.

Turn validity checks off.

Turn validity checks on.

State of validity checks.

Provided Methods

Return ReaperError::NullPtr if check failed.

Note

Will not check if turned off by WithReaperPtr::make_unchecked.

Return ReaperError::NullPtr if check failed.

Note

Will not check if turned off by WithReaperPtr::make_unchecked.

Perform function with only one validity check.

Returns ReaperError::NullPtr if the first check failed. Also propagates any error returned from function.

Implementors