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(&self, identity: impl Into<String>, kind: AttachmentKind, address: impl Into<String>) -> XAttachment {
37        XAttachment { identity: identity.into(), kind, address: address.into() }
38    }
39}
40
41impl XAttachmentViewAlg for ReferenceXEnv {
42    fn attachment_identity<'a>(&self, attachment: &'a XAttachment) -> &'a str {
43        &attachment.identity
44    }
45
46    fn attachment_kind(&self, attachment: &XAttachment) -> AttachmentKind {
47        attachment.kind
48    }
49
50    fn attachment_address<'a>(&self, attachment: &'a XAttachment) -> &'a str {
51        &attachment.address
52    }
53}