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

ambee/giterated

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

Progress on refactor

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨c9f076f

⁨giterated-models/src/values/mod.rs⁩ - ⁨1910⁩ 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 type Success = S;
43
44 type Failure = GetSettingError;
45 }
46
47 #[derive(Error, Debug, Serialize, Deserialize)]
48 pub enum GetSettingError {}
49 #[derive(Serialize, Deserialize, Debug, Clone)]
50 #[serde(bound(deserialize = "S: Setting"))]
51 pub struct SetSetting<S: Setting> {
52 pub setting_name: String,
53 pub value: S,
54 }
55
56 impl<O: GiteratedObject, S: Setting + Send> GiteratedOperation<O> for SetSetting<S> {
57 type Success = ();
58
59 type Failure = SetSettingError;
60 }
61
62 #[derive(Error, Debug, Serialize, Deserialize)]
63 pub enum SetSettingError {}
64
65 #[derive(Debug, Clone, Deserialize, Serialize)]
66 #[serde(transparent)]
67 pub struct AnyValue<O> {
68 value: Value,
69 #[serde(skip)]
70 _marker: PhantomData<O>,
71 }
72
73 impl<O: GiteratedObject> GiteratedObjectValue for AnyValue<O> {
74 type Object = O;
75
76 fn value_name() -> &'static str {
77 todo!()
78 }
79 }
80