JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

More progress :)

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨92c3f32

⁨giterated-models/src/object/operations.rs⁩ - ⁨1467⁩ bytes
Raw
1 use std::{convert::Infallible, fmt::Display, str::FromStr};
2
3 use serde::{Deserialize, Serialize};
4
5 use crate::{instance::Instance, operation::GiteratedOperation};
6
7 use super::GiteratedObject;
8
9 #[derive(Debug, Serialize, Deserialize, Clone)]
10 pub struct ObjectRequest(pub String);
11
12 #[derive(Serialize, Deserialize, Clone, Debug)]
13 pub struct ObjectResponse(pub String);
14
15 impl GiteratedOperation<Instance> for ObjectRequest {
16 type Success = ObjectResponse;
17
18 type Failure = ObjectRequestError;
19
20 fn operation_name() -> &'static str {
21 "object_request"
22 }
23 }
24
25 #[derive(Debug, Clone, thiserror::Error, Serialize, Deserialize)]
26 pub enum ObjectRequestError {
27 #[error("error decoding the object")]
28 Deserialization(String),
29 }
30
31 #[derive(Clone, Debug, Serialize, Deserialize)]
32 #[serde(transparent)]
33 #[repr(transparent)]
34 pub struct NetworkAnyObject(pub String);
35
36 impl GiteratedObject for NetworkAnyObject {
37 fn object_name() -> &'static str {
38 "any"
39 }
40
41 fn from_object_str(object_str: &str) -> Result<Self, anyhow::Error> {
42 Ok(Self(object_str.to_string()))
43 }
44
45 fn home_uri(&self) -> String {
46 todo!()
47 }
48 }
49
50 impl Display for NetworkAnyObject {
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 f.write_str(&self.0)
53 }
54 }
55
56 impl FromStr for NetworkAnyObject {
57 type Err = Infallible;
58
59 fn from_str(s: &str) -> Result<Self, Self::Err> {
60 Ok(Self(s.to_owned()))
61 }
62 }
63