Skip to main content

rsynko_memory/
x.rs

1use rsynko_x::*;
2
3/// Asks about tweets by writing down the address that would be asked.
4///
5/// Nothing here reaches anywhere: a request is the address itself, which is what makes what a
6/// tweet source decides before it asks anything readable without asking anything.
7#[derive(Clone, Copy, Debug, Default)]
8pub struct ReferenceXEnv;
9
10/// Holds one file a tweet carries.
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct XAttachment {
13    identity: String,
14    kind: AttachmentKind,
15    address: String,
16}
17
18impl XSorts for ReferenceXEnv {
19    type Request = String;
20    type Attachment = XAttachment;
21}
22
23impl XRequestAlg for ReferenceXEnv {
24    fn tweet_request(&self, address: impl Into<String>) -> String {
25        address.into()
26    }
27}
28
29impl XRequestViewAlg for ReferenceXEnv {
30    fn request_address<'a>(&self, request: &'a String) -> &'a str {
31        request
32    }
33}
34
35impl XAttachmentAlg for ReferenceXEnv {
36    fn attachment(
37        &self,
38        identity: impl Into<String>,
39        kind: AttachmentKind,
40        address: impl Into<String>,
41    ) -> XAttachment {
42        XAttachment {
43            identity: identity.into(),
44            kind,
45            address: address.into(),
46        }
47    }
48}
49
50impl XAttachmentViewAlg for ReferenceXEnv {
51    fn attachment_identity<'a>(&self, attachment: &'a XAttachment) -> &'a str {
52        &attachment.identity
53    }
54
55    fn attachment_kind(&self, attachment: &XAttachment) -> AttachmentKind {
56        attachment.kind
57    }
58
59    fn attachment_address<'a>(&self, attachment: &'a XAttachment) -> &'a str {
60        &attachment.address
61    }
62}