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

ambee/giterated

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

Fix internal call values

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨8e8ab90

⁨giterated-models/src/value.rs⁩ - ⁨1595⁩ 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(Debug, Clone, Deserialize, Serialize)]
43 #[serde(transparent)]
44 pub struct AnyValue<O> {
45 value: Value,
46 #[serde(skip)]
47 _marker: PhantomData<O>,
48 }
49
50 impl<O> AnyValue<O> {
51 pub unsafe fn from_raw(value: Value) -> Self {
52 Self {
53 value,
54 _marker: Default::default(),
55 }
56 }
57
58 pub fn into_inner(self) -> Value {
59 self.value
60 }
61 }
62
63 impl<O: GiteratedObject> GiteratedObjectValue for AnyValue<O> {
64 type Object = O;
65
66 fn value_name() -> &'static str {
67 todo!()
68 }
69 }
70