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

ambee/giterated

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

Base protocol refactor complete

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨079d544

⁨giterated-models/src/values/mod.rs⁩ - ⁨2236⁩ bytes
Raw
1 use std::{fmt::Debug, marker::PhantomData};
2
3 use serde::{de::DeserializeOwned, Deserialize, Serialize};
4 use serde_json::Value;
5 use thiserror::Error;
6
7 use crate::{
8 model::settings::Setting,
9 operation::{GiteratedObject, GiteratedObjectValue, GiteratedOperation},
10 };
11
12 pub mod instance;
13 pub mod repository;
14 pub mod user;
15
16 // #[derive(Serialize, Deserialize)]
17 // pub struct GetRequest<V: GiteratedObjectValue> {
18 // value_name: String,
19 // _marker: PhantomData<V>,
20 // }
21
22 // impl<O: GiteratedObject, V: GiteratedObjectValue<Object = O> + Send> GiteratedOperation<O>
23 // for GetRequest<V>
24 // {
25 // type Success = V;
26
27 // type Failure = GetValueError;
28 // }
29
30 // #[derive(Error, Debug, Serialize, Deserialize)]
31 // pub enum GetValueError {}
32
33 #[derive(Serialize, Deserialize, Debug, Clone)]
34 pub struct GetSetting<S: Setting + std::fmt::Debug + Clone> {
35 pub setting_name: String,
36 pub _marker: PhantomData<S>,
37 }
38
39 impl<O: GiteratedObject, S: Setting + Send + DeserializeOwned + Debug + Clone> GiteratedOperation<O>
40 for GetSetting<S>
41 {
42 fn operation_name() -> &'static str {
43 "get_setting"
44 }
45
46 type Success = S;
47
48 type Failure = GetSettingError;
49 }
50
51 #[derive(Error, Debug, Serialize, Deserialize)]
52 pub enum GetSettingError {}
53 #[derive(Serialize, Deserialize, Debug, Clone)]
54 #[serde(bound(deserialize = "S: Setting"))]
55 pub struct SetSetting<S: Setting> {
56 pub setting_name: String,
57 pub value: S,
58 }
59
60 impl<O: GiteratedObject, S: Setting + Send> GiteratedOperation<O> for SetSetting<S> {
61 fn operation_name() -> &'static str {
62 "set_setting"
63 }
64
65 type Success = ();
66
67 type Failure = SetSettingError;
68 }
69
70 #[derive(Error, Debug, Serialize, Deserialize)]
71 pub enum SetSettingError {}
72
73 #[derive(Debug, Clone, Deserialize, Serialize)]
74 #[serde(transparent)]
75 pub struct AnyValue<O> {
76 value: Value,
77 #[serde(skip)]
78 _marker: PhantomData<O>,
79 }
80
81 impl<O: GiteratedObject> AnyValue<O> {
82 pub unsafe fn from_raw(value: Value) -> Self {
83 Self {
84 value,
85 _marker: Default::default(),
86 }
87 }
88 }
89
90 impl<O: GiteratedObject> GiteratedObjectValue for AnyValue<O> {
91 type Object = O;
92
93 fn value_name() -> &'static str {
94 todo!()
95 }
96 }
97