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: 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<V: GiteratedObjectValue> {
|
16 |
pub value_name: String,
|
17 |
pub(crate) _marker: PhantomData<V>,
|
18 |
}
|
19 |
|
20 |
impl<O: GiteratedObject + Send, V: GiteratedObjectValue<Object = O> + Send> GiteratedOperation<O>
|
21 |
for GetValue<V>
|
22 |
{
|
23 |
fn operation_name() -> &'static str {
|
24 |
"get_value"
|
25 |
}
|
26 |
type Success = V;
|
27 |
type Failure = GetValueError;
|
28 |
}
|
29 |
|
30 |
#[derive(Debug, Clone, Deserialize, Serialize)]
|
31 |
#[serde(transparent)]
|
32 |
pub struct AnyValue<O> {
|
33 |
value: Value,
|
34 |
#[serde(skip)]
|
35 |
_marker: PhantomData<O>,
|
36 |
}
|
37 |
|
38 |
impl<O: GiteratedObject> AnyValue<O> {
|
39 |
pub unsafe fn from_raw(value: Value) -> Self {
|
40 |
Self {
|
41 |
value,
|
42 |
_marker: Default::default(),
|
43 |
}
|
44 |
}
|
45 |
}
|
46 |
|
47 |
impl<O: GiteratedObject> GiteratedObjectValue for AnyValue<O> {
|
48 |
type Object = O;
|
49 |
|
50 |
fn value_name() -> &'static str {
|
51 |
todo!()
|
52 |
}
|
53 |
}
|
54 |
|