1 |
use std::{convert::Infallible, fmt::Display, str::FromStr};
|
2 |
|
3 |
use serde::{Deserialize, Serialize};
|
4 |
|
5 |
use crate::{instance::Instance, operation::GiteratedOperation};
|
6 |
|
7 |
use super::GiteratedObject;
|
8 |
|
9 |
#[derive(Debug, Serialize, Deserialize, Clone)]
|
10 |
pub struct ObjectRequest(pub String);
|
11 |
|
12 |
#[derive(Serialize, Deserialize)]
|
13 |
pub struct ObjectResponse(pub String);
|
14 |
|
15 |
impl GiteratedOperation<Instance> for ObjectRequest {
|
16 |
type Success = ObjectResponse;
|
17 |
|
18 |
type Failure = ObjectRequestError;
|
19 |
}
|
20 |
|
21 |
#[derive(Debug, thiserror::Error, Serialize, Deserialize)]
|
22 |
pub enum ObjectRequestError {
|
23 |
#[error("error decoding the object")]
|
24 |
Deserialization(String),
|
25 |
}
|
26 |
|
27 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
28 |
#[serde(transparent)]
|
29 |
#[repr(transparent)]
|
30 |
pub struct AnyObject(pub String);
|
31 |
|
32 |
impl GiteratedObject for AnyObject {
|
33 |
fn object_name() -> &'static str {
|
34 |
"any"
|
35 |
}
|
36 |
|
37 |
fn from_object_str(object_str: &str) -> Result<Self, anyhow::Error> {
|
38 |
Ok(Self(object_str.to_string()))
|
39 |
}
|
40 |
}
|
41 |
|
42 |
impl Display for AnyObject {
|
43 |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
44 |
f.write_str(&self.0)
|
45 |
}
|
46 |
}
|
47 |
|
48 |
impl FromStr for AnyObject {
|
49 |
type Err = Infallible;
|
50 |
|
51 |
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
52 |
Ok(Self(s.to_owned()))
|
53 |
}
|
54 |
}
|
55 |
|