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

ambee/giterated

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

Beginning of `stack-next` refactor

-Refactoring the protocol stack into something similar to a runtime. -Handles merging handler builders which is placing the ground work for plugins in. - Increased metadata generation during compilation enables less ser/de during execution. - Goal is to have an O(1) time from incoming operation to calling handlers. - Decreased penalty for using the statically typed API from within your code, now avoids some allocation. # Changes - Added `GiteratedRuntime` which is to replace the current unified stack - Added `RuntimeBuilder` which does what the current `OperationHandlers` struct does, but much better. - Added `RuntimeMetadata` to store type metadata for new `Any` based internals - Refactored serde_json out of the internal operation handling

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨708dea4

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