Skip to main content

RustObjAccess

Struct RustObjAccess 

Source
pub struct RustObjAccess<T: ?Sized> { /* private fields */ }
Expand description

Manages shared access to a Rust object across the Rust/C++ boundary.

When Rust calls into C++ and C++ calls back into Rust, the inner callback cannot re-borrow the RefCell without panicking. This struct solves this by caching a raw pointer before crossing into C++ and restoring it as a reference on the way back, avoiding a second borrow while preserving a valid borrow stack per the “Stacked Borrows” aliasing model.

Implementations§

Source§

impl<T: ?Sized> RustObjAccess<T>

Source

pub fn new_strong(ptr: Rc<RefCell<T>>) -> Self

Create an instance that hold a strong reference to the Rust object. This is the case for objects created on the QML Side (QML Element).

Source

pub fn new_weak(ptr: Weak<RefCell<T>>) -> Self

Create an instance that holds a weak (Weak<RefCell<T>>) reference to the Rust object. This is the case for objects created on the Rust Side.

Source

pub fn try_call_rust_with_handle<F, R>( &self, f: F, ) -> Result<R, RustObjAccessError>
where F: FnOnce(&T) -> R,

Source

pub fn try_call_rust_with_handle_mut<F, R>( &self, f: F, ) -> Result<R, RustObjAccessError>
where F: FnOnce(&mut T) -> R,

Source

pub fn try_store_handle_and_call_cpp<F, R>( &self, rust_obj: &T, f: F, ) -> Result<R, RustObjAccessError>
where F: FnOnce() -> R,

Source

pub fn try_store_handle_and_call_cpp_mut<F, R>( &self, rust_obj: &mut T, f: F, ) -> Result<R, RustObjAccessError>
where F: FnOnce() -> R,

Source

pub fn get_rc(&self) -> Option<Rc<RefCell<T>>>

Auto Trait Implementations§

§

impl<T> !Freeze for RustObjAccess<T>

§

impl<T> !RefUnwindSafe for RustObjAccess<T>

§

impl<T> !Send for RustObjAccess<T>

§

impl<T> !Sync for RustObjAccess<T>

§

impl<T> Unpin for RustObjAccess<T>
where T: ?Sized,

§

impl<T> UnsafeUnpin for RustObjAccess<T>
where T: ?Sized,

§

impl<T> !UnwindSafe for RustObjAccess<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.