Skip to main content

ListPatch

Struct ListPatch 

Source
pub struct ListPatch<S> { /* private fields */ }
Expand description

Item changes to list signals of S, sent without the rest of each list.

Build one with Sig::patch_append, Sig::patch_prepend, Sig::patch_upsert, or Sig::patch_remove, and combine with ListPatch::and. The browser applies the changes in order to the list it holds, so a list the server sends one message of at a time grows in the browser without the server keeping a copy of it.

use hypersig::{Patches, Signals};
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct Message {
    body: String,
}

#[derive(Signals, Serialize, Deserialize)]
struct Room {
    messages: Vec<Message>,
}

let hello = Message { body: "hello".into() };
let patches: Patches<Room> = Room::messages().patch_append(&[hello]).into();
assert_eq!(
    patches.to_event_stream(),
    "event: hs-list\ndata: [\"append\",\"messages\",[\"lit\",[{\"body\":\"hello\"}]]]\n\n",
);

Implementations§

Source§

impl<S> ListPatch<S>

Source

pub fn and(self, other: Self) -> Self

Adds the changes in other, applied after the ones in self.

Trait Implementations§

Source§

impl<S> Debug for ListPatch<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Signals> From<ListPatch<S>> for ActionResponse<S>

Source§

fn from(patch: ListPatch<S>) -> Self

Converts to this type from the input type.
Source§

impl<S: Signals> From<ListPatch<S>> for Patches<S>

Source§

fn from(patch: ListPatch<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for ListPatch<S>

§

impl<S> RefUnwindSafe for ListPatch<S>

§

impl<S> Send for ListPatch<S>

§

impl<S> Sync for ListPatch<S>

§

impl<S> Unpin for ListPatch<S>

§

impl<S> UnsafeUnpin for ListPatch<S>

§

impl<S> UnwindSafe for ListPatch<S>

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.