ferroui_dynamic_data/list/
virtual_change_set.rs1use super::{ChangeSet, IChangeSet};
4use crate::cache::VirtualResponse;
5use std::fmt;
6use std::ops::Deref;
7
8pub trait IVirtualChangeSet<T>: IChangeSet<T> {
10 fn response(&self) -> &VirtualResponse;
12}
13
14pub struct VirtualChangeSet<T> {
18 changes: ChangeSet<T>,
19 response: VirtualResponse,
20}
21
22impl<T> Clone for VirtualChangeSet<T> {
23 fn clone(&self) -> Self {
24 Self { changes: self.changes.clone(), response: self.response }
25 }
26}
27
28impl<T> VirtualChangeSet<T> {
29 pub fn new(changes: ChangeSet<T>, response: VirtualResponse) -> Self {
31 Self { changes, response }
32 }
33
34 pub fn response(&self) -> &VirtualResponse {
36 &self.response
37 }
38
39 pub fn changes(&self) -> &ChangeSet<T> {
41 &self.changes
42 }
43}
44
45impl<T> Deref for VirtualChangeSet<T> {
46 type Target = ChangeSet<T>;
47
48 fn deref(&self) -> &Self::Target {
49 &self.changes
50 }
51}
52
53impl<'a, T> IntoIterator for &'a VirtualChangeSet<T> {
54 type Item = &'a super::Change<T>;
55 type IntoIter = std::slice::Iter<'a, super::Change<T>>;
56
57 fn into_iter(self) -> Self::IntoIter {
58 self.changes.changes().iter()
59 }
60}
61
62impl<T: 'static> IChangeSet<T> for VirtualChangeSet<T> {
63 fn change_set(&self) -> &ChangeSet<T> {
64 &self.changes
65 }
66}
67
68impl<T: 'static> IVirtualChangeSet<T> for VirtualChangeSet<T> {
69 fn response(&self) -> &VirtualResponse {
70 &self.response
71 }
72}
73
74impl<T: PartialEq> PartialEq for VirtualChangeSet<T> {
75 fn eq(&self, other: &Self) -> bool {
76 self.changes == other.changes && self.response == other.response
77 }
78}
79
80impl<T: fmt::Debug> fmt::Debug for VirtualChangeSet<T> {
81 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82 f.debug_struct("VirtualChangeSet").field("changes", &self.changes).field("response", &self.response).finish()
83 }
84}