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

ambee/giterated

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

More restructuring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨10b7b7c

⁨giterated-core/giterated-models/src/value.rs⁩ - ⁨1378⁩ bytes
Raw
1 use std::{fmt::Debug, marker::PhantomData};
2
3 use serde::{de::DeserializeOwned, Deserialize, Serialize};
4 use serde_json::Value;
5
6 use crate::{error::GetValueError, object::GiteratedObject, operation::GiteratedOperation};
7
8 pub trait GiteratedObjectValue: Send + Sync + Serialize + DeserializeOwned {
9 type Object: GiteratedObject;
10
11 fn value_name() -> &'static str;
12 }
13
14 #[derive(Serialize, Deserialize, Debug, Clone)]
15 pub struct GetValue {
16 pub value_name: String,
17 }
18
19 impl<O: GiteratedObject + Send> GiteratedOperation<O> for GetValue {
20 fn operation_name() -> &'static str {
21 "get_value"
22 }
23 type Success = Vec<u8>;
24 type Failure = GetValueError;
25 }
26
27 #[derive(Serialize, Deserialize, Debug, Clone)]
28 pub struct GetValueTyped<V: GiteratedObjectValue> {
29 pub ty: PhantomData<V>,
30 }
31
32 impl<O: GiteratedObject + Send, V: GiteratedObjectValue<Object = O>> GiteratedOperation<O>
33 for GetValueTyped<V>
34 {
35 fn operation_name() -> &'static str {
36 "get_value"
37 }
38 type Success = V;
39 type Failure = GetValueError;
40 }
41
42 #[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
43 pub struct ObjectValuePair<'s> {
44 pub object_kind: &'s str,
45 pub value_name: &'s str,
46 }
47
48 impl<'s> ObjectValuePair<'s> {
49 pub fn new(object_kind: &'s str, value_name: &'s str) -> Self {
50 Self {
51 object_kind,
52 value_name,
53 }
54 }
55 }
56