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

ambee/giterated

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

Remove unwrap statements and return OperationError's

erremilia - ⁨2⁩ years ago

parent: tbd commit: ⁨cf491a4

⁨giterated-models/src/settings/operations.rs⁩ - ⁨1062⁩ bytes
Raw
1 use std::fmt::Debug;
2
3 use serde::{Deserialize, Serialize};
4 use serde_json::Value;
5 use thiserror::Error;
6
7 use crate::{object::GiteratedObject, operation::GiteratedOperation};
8
9 #[derive(Serialize, Deserialize, Debug, Clone)]
10 pub struct GetSetting {
11 pub setting_name: String,
12 }
13
14 impl<O: GiteratedObject> GiteratedOperation<O> for GetSetting {
15 fn operation_name() -> &'static str {
16 "get_setting"
17 }
18
19 type Success = Value;
20
21 type Failure = GetSettingError;
22 }
23
24 #[derive(Error, Debug, Serialize, Deserialize, Clone)]
25 pub enum GetSettingError {}
26 #[derive(Serialize, Deserialize, Debug, Clone)]
27 pub struct SetSetting {
28 pub setting_name: String,
29 pub value: Value,
30 }
31
32 impl<O: GiteratedObject> GiteratedOperation<O> for SetSetting {
33 fn operation_name() -> &'static str {
34 "set_setting"
35 }
36
37 type Success = ();
38
39 type Failure = SetSettingError;
40 }
41
42 #[derive(Error, Debug, Serialize, Deserialize, Clone)]
43 pub enum SetSettingError {
44 #[error("Invalid setting `{0}` on object `{0}`")]
45 InvalidSetting(String, String)
46 }
47