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

ambee/giterated

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

More progress :)

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨92c3f32

⁨giterated-models/src/operation.rs⁩ - ⁨1019⁩ bytes
Raw
1 use std::{any::type_name, collections::HashMap, fmt::Debug};
2
3 use serde::{de::DeserializeOwned, Deserialize, Serialize};
4
5 use crate::{ffi::FfiLabel, object::GiteratedObject};
6
7 pub trait GiteratedOperation<O: GiteratedObject>:
8 Send + Sync + Serialize + DeserializeOwned
9 {
10 type Success: Serialize + DeserializeOwned + Send;
11 type Failure: Serialize + DeserializeOwned + Send;
12
13 fn operation_name() -> &'static str {
14 type_name::<Self>()
15 }
16 }
17
18 #[derive(Clone, Debug, Serialize, Deserialize)]
19 #[serde(transparent)]
20 #[repr(transparent)]
21 pub struct NetworkAnyOperation(pub Vec<u8>);
22
23 impl<O: GiteratedObject> GiteratedOperation<O> for NetworkAnyOperation {
24 type Success = Vec<u8>;
25
26 type Failure = Vec<u8>;
27 }
28
29 #[derive(Clone, Debug, Default)]
30 pub struct OperationState {
31 states: HashMap<String, Vec<u8>>,
32 }
33
34 impl FfiLabel for OperationState {
35 fn prefix(&self) -> &'static str {
36 "dev.giterated"
37 }
38
39 fn type_label(&self) -> &'static str {
40 "operation_state"
41 }
42 }
43