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

ambee/giterated

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

The long awaited, exhalted huge networking stack change.

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨21b6a72

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