stellation_bridge/
bridge.rs1use std::fmt;
2use std::rc::Rc;
3
4use yew::prelude::*;
5use yew::suspense::SuspensionResult;
6
7use crate::hooks::{
8 use_bridged_mutation, use_bridged_query, use_bridged_query_value, UseBridgedMutationHandle,
9 UseBridgedQueryHandle, UseBridgedQueryValueHandle,
10};
11use crate::links::Link;
12use crate::routines::{BridgedMutation, BridgedQuery};
13
14pub struct Bridge<L> {
16 pub(crate) link: L,
17}
18
19impl<L> Clone for Bridge<L>
20where
21 L: Clone,
22{
23 fn clone(&self) -> Self {
24 Self {
25 link: self.link.clone(),
26 }
27 }
28}
29
30impl<L> fmt::Debug for Bridge<L> {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 f.debug_struct("Bridge").finish_non_exhaustive()
33 }
34}
35
36impl<L> PartialEq for Bridge<L>
37where
38 L: Link,
39{
40 fn eq(&self, other: &Self) -> bool {
41 self.link == other.link
42 }
43}
44impl<L> Eq for Bridge<L> where L: Link {}
45
46impl<L> Bridge<L>
47where
48 L: Link,
49{
50 pub fn new(link: L) -> Self {
52 Self { link }
53 }
54
55 pub fn link(&self) -> &L {
57 &self.link
58 }
59
60 pub fn use_mutation<T>() -> impl Hook<Output = UseBridgedMutationHandle<T, L>>
62 where
63 T: 'static + BridgedMutation,
64 L: 'static,
65 {
66 use_bridged_mutation()
67 }
68
69 pub fn use_query<T>(
71 input: Rc<T::Input>,
72 ) -> impl Hook<Output = SuspensionResult<UseBridgedQueryHandle<T, L>>>
73 where
74 T: 'static + BridgedQuery,
75 L: 'static,
76 {
77 use_bridged_query(input)
78 }
79
80 pub fn use_query_value<T>(
87 input: Rc<T::Input>,
88 ) -> impl Hook<Output = UseBridgedQueryValueHandle<T, L>>
89 where
90 T: 'static + BridgedQuery,
91 L: 'static,
92 {
93 use_bridged_query_value(input)
94 }
95}