-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproxy.rs
71 lines (63 loc) · 1.77 KB
/
proxy.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::fmt;
use crate::{
foundation::patterns::facade::BaseFacade,
prelude::{Facade, Interest, Notifier, Proxy, Singleton},
};
/// A base [Proxy] implementation.
///
/// In PureMVC, [Proxy] classes are used to manage parts of the
/// application's data model.
///
/// A [Proxy] might simply manage a reference to a local data object,
/// in which case interacting with it might involve setting and
/// getting of its data in synchronous fashion.
///
/// [Proxy] classes are also used to encapsulate the application's
/// interaction with remote services to save or retrieve data, in which case,
/// we adopt an asyncronous idiom; setting data (or calling a method) on the
/// [Proxy] and listening for a [Notification] to be sent
/// when the [Proxy] has retrieved the data from the service.
///
/// [Notification]: crate::prelude::Notification
pub struct BaseProxy<Body>
where
Body: fmt::Debug + 'static,
{
/// Represens data object
pub data: Option<Body>,
}
impl<Body> BaseProxy<Body>
where
Body: fmt::Debug + 'static,
{
/// Constructor
pub fn new(data: Option<Body>) -> Self {
Self { data }
}
}
impl<Body> Proxy for BaseProxy<Body>
where
Body: fmt::Debug + 'static,
{
fn on_register(&self) {}
fn on_remove(&self) {}
}
impl<Body> Notifier<Body> for BaseProxy<Body>
where
Body: fmt::Debug + 'static,
{
fn send(&self, interest: Interest, body: Option<Body>) {
log::error!("You should implement yourself Proxy");
BaseFacade::<Body>::global().send(interest, body);
}
}
impl<Body> fmt::Debug for BaseProxy<Body>
where
Body: fmt::Debug + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Proxy<Body>")
// .field("x", &self.x)
.finish()
}
}