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