dioxus_query/captured.rs
1use std::{hash::Hash, ops::Deref};
2
3/// Capture values to use later inside Queries or Mutations, but with a catch, if the capture value changes the mutation will not recapture it because
4/// the [PartialEq] implementation always returns `true`.
5///
6/// So in other words `Capture(1) == Capture(5)` will be `true`.
7///
8/// **This is intended to use for value types that are not mean to be diffed and that are expected to maintain their value across time.
9/// Like "Clients" of external resources such as API Clients.**
10///
11/// Just so its clear, you might or not need this, use carefully.
12#[derive(Clone)]
13pub struct Captured<T: Clone>(pub T);
14
15impl<T: Clone> Hash for Captured<T> {
16 fn hash<H: std::hash::Hasher>(&self, _state: &mut H) {}
17}
18
19impl<T: Clone> PartialEq for Captured<T> {
20 fn eq(&self, _other: &Self) -> bool {
21 true
22 }
23}
24
25impl<T: Clone> Eq for Captured<T> {}
26
27impl<T: Clone> Deref for Captured<T> {
28 type Target = T;
29
30 fn deref(&self) -> &Self::Target {
31 &self.0
32 }
33}