[−][src]Struct bottle::remote::Remote
A thread-safe actor pointer.
Thread Safety
Remote<T>
will implement Send
and Sync
even if T
does not.
This is possible because in most cases, the underlying data is never accessed directly.
The only way to access the data directly is via [Remote::read
] and [Remote::write
],
but thoses two functions are only implemented when T
implements Send
and Sync
.
Accessing the underlying value
The value is indirectly accessed via message passing using the non-blocking methods
[send
] and [send_mut
].
Breaking cycles with WeakRemote
The [downgrade
][downgrade] method can be used to create a non-owning
[WeakRemote
][weak] pointer. A [WeakRemote
][weak] pointer can be [upgrade
][upgrade]d
to an Remote
, but this will return None
if the value has already been
dropped.
A cycle between Remote
pointers will never be deallocated. For this reason,
WeakRemote
is used to break cycles. For example, a tree could have
strong Remote
pointers from parent nodes to children, and WeakRemote
pointers from children back to their parents.
Cloning references
Creating a new reference from an existing reference remote pointer is done using the
Clone
trait implemented for [Remote<T>
][arc] and [WeakRemote<T>
][weak].
Methods
impl<T: 'static + ?Sized> Remote<T>
[src]
pub fn from<F: 'static + FnOnce(Remote<T>) -> T + Send>(
thread: &Arc<Thread>,
constructor: F
) -> Remote<T> where
T: Sized,
[src]
thread: &Arc<Thread>,
constructor: F
) -> Remote<T> where
T: Sized,
Create from a constructor.
Note that the value is not created right away. This actually sends a query to the target
thread. The value will be initialized when the thread process the query.
Until then, any direct access to the value through [read
] or write
will fail.
If it is executed in the target thread, then value is directly initialized.
pub fn new(thread: &Arc<Thread>, t: T) -> Remote<T> where
T: Send + Sized,
[src]
T: Send + Sized,
Create a remote pointer on the given thread.
pub fn local(t: T) -> Result<Remote<T>, T> where
T: Sized,
[src]
T: Sized,
Create a remote pointer on the current thread. Return back the value as an error when there are no current thread.
pub fn send<S: Signal + 'static>(&self, msg: S) -> Future<S::Response> where
T: Handler<S>,
[src]
T: Handler<S>,
pub fn send_mut<S: Signal + 'static>(&self, msg: S) -> Future<S::Response> where
T: MutHandler<S>,
[src]
T: MutHandler<S>,
impl<T: ?Sized> Remote<T>
[src]
pub fn ptr(&self) -> *const T
[src]
Return a pointer to the underlying value.
pub fn ptr_mut(&self) -> *mut T
[src]
Return a mutable pointer to the underlying value.
pub fn is_initialized(&self) -> bool
[src]
pub fn get<D>(&self) -> Option<D> where
T: Expose<D>,
[src]
T: Expose<D>,
pub fn receiver(&self) -> Receiver
[src]
pub fn downgrade(&self) -> WeakRemote<T>
[src]
Creates a new [WeakRemote
][weak] pointer to this value.
Trait Implementations
impl<S: Signal, T: 'static + ?Sized + Handler<Subscription<S>>> Emitter<S> for Remote<T>
[src]
fn subscribe(&self, actor: Remote<dyn Handler<S> + 'static>)
[src]
Subscribe to an emitter.
fn subscribe_mut(&self, actor: Remote<dyn MutHandler<S> + 'static>)
[src]
Subscribe mutabily to an emitter.
impl<T: 'static + ?Sized> Clone for Remote<T>
[src]
fn clone(&self) -> Remote<T>
[src]
Makes a clone of the Remote
pointer.
This creates another pointer to the same inner value, increasing the strong reference count.
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: ?Sized> Sync for Remote<T>
[src]
impl<T: ?Sized> Drop for Remote<T>
[src]
fn drop(&mut self)
[src]
Drops the Remote
.
This will decrement the strong reference count. If the strong reference
count reaches zero then the only other references (if any) are
WeakRemote
, so we drop
the inner value.
impl<T: ?Sized> PartialEq<Remote<T>> for Remote<T>
[src]
fn eq(&self, other: &Remote<T>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T: ?Sized> Eq for Remote<T>
[src]
impl<T: ?Sized> Send for Remote<T>
[src]
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Remote<U>> for Remote<T>
[src]
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Remote<U>> for Remote<T>
[src]
Auto Trait Implementations
impl<T: ?Sized> Unpin for Remote<T> where
T: Unpin,
T: Unpin,
impl<T> !UnwindSafe for Remote<T>
impl<T> !RefUnwindSafe for Remote<T>
Blanket Implementations
impl<T, S> Handler<Subscription<S>> for T where
S: Signal,
T: Emitter<S>,
[src]
S: Signal,
T: Emitter<S>,
fn handle(&Self, Subscription<S>)
[src]
impl<S, T> MutHandler<S> for T where
S: Signal,
T: Handler<S> + ?Sized,
[src]
S: Signal,
T: Handler<S> + ?Sized,
fn handle_mut(&mut Self, S) -> <S as Signal>::Response
[src]
impl<T> AsReceiver for T
[src]
fn as_receiver(&Self) -> Result<Remote<T>, NotReceiver>
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,