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

ambee/giterated

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

Fixes

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨73a5af5

⁨giterated-models/src/object/operations.rs⁩ - ⁨1257⁩ 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)]
10 pub struct ObjectRequest(pub String);
11
12 #[derive(Serialize, Deserialize)]
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, 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 #[repr(transparent)]
29 pub struct AnyObject(pub String);
30
31 impl GiteratedObject for AnyObject {
32 fn object_name() -> &'static str {
33 "any"
34 }
35
36 fn from_object_str(object_str: &str) -> Result<Self, anyhow::Error> {
37 Ok(Self(object_str.to_string()))
38 }
39 }
40
41 impl Display for AnyObject {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 f.write_str(&self.0)
44 }
45 }
46
47 impl FromStr for AnyObject {
48 type Err = Infallible;
49
50 fn from_str(s: &str) -> Result<Self, Self::Err> {
51 Ok(Self(s.to_owned()))
52 }
53 }
54