[][src]Trait herald::herald::observer::PayloadCopy

pub trait PayloadCopy: Clone {
#[must_use]    fn payload_copy(&self) -> Self { ... }
}

There are situations in which rxRust needs to copy items/errors, for example when you use subjects or cloned observables. All items/errors which are copyable (= implement Copy) work in such situations out of the box. Items/errors which implement just Clone but not Copy don't work out of the box (because rxRust wants to prevent you from accidentally introducing poorly performing observable chains). If you have such items/errors, you might want to implement PayloadCopy for them. You can use it just like a marker trait because there's a default method definition which simply calls clone() to make the copy. However, take care to only implement it for types that are cheap to clone! In multi-observer scenarios (e.g. when using subjects), payload_copy() will be called for each single observer!

Example

use rxrust::prelude::*;
use std::rc::Rc;

#[derive(Clone)]
struct MyCloneableItem {
  text: Rc<String>,
}

impl PayloadCopy for MyCloneableItem {}

Provided methods

#[must_use]fn payload_copy(&self) -> Self

Should return a copy of the value. Unlike Copy, this can be more than just a bitwise copy. Unlike Clone, this should still be a cheap operation.

Loading content...

Implementors

impl<'a, T: Herald<'a>> PayloadCopy for RefChangeEvent<'a, T>[src]

impl<T> PayloadCopy for T where
    T: Copy
[src]

Loading content...