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, Clone, Debug)]
|
13 |
pub struct ObjectResponse(pub String);
|
14 |
|
15 |
impl GiteratedOperation<Instance> for ObjectRequest {
|
16 |
type Success = ObjectResponse;
|
17 |
|
18 |
type Failure = ObjectRequestError;
|
19 |
|
20 |
fn operation_name() -> &'static str {
|
21 |
"object_request"
|
22 |
}
|
23 |
}
|
24 |
|
25 |
#[derive(Debug, Clone, thiserror::Error, Serialize, Deserialize)]
|
26 |
pub enum ObjectRequestError {
|
27 |
#[error("error decoding the object")]
|
28 |
Deserialization(String),
|
29 |
#[error("invalid object type")]
|
30 |
Invalid,
|
31 |
}
|
32 |
|
33 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
34 |
#[serde(transparent)]
|
35 |
#[repr(transparent)]
|
36 |
pub struct NetworkAnyObject(pub String);
|
37 |
|
38 |
impl GiteratedObject for NetworkAnyObject {
|
39 |
fn object_name() -> &'static str {
|
40 |
"any"
|
41 |
}
|
42 |
|
43 |
fn from_object_str(object_str: &str) -> Result<Self, anyhow::Error> {
|
44 |
Ok(Self(object_str.to_string()))
|
45 |
}
|
46 |
|
47 |
fn home_uri(&self) -> String {
|
48 |
todo!()
|
49 |
}
|
50 |
}
|
51 |
|
52 |
impl Display for NetworkAnyObject {
|
53 |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
54 |
f.write_str(&self.0)
|
55 |
}
|
56 |
}
|
57 |
|
58 |
impl FromStr for NetworkAnyObject {
|
59 |
type Err = Infallible;
|
60 |
|
61 |
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
62 |
Ok(Self(s.to_owned()))
|
63 |
}
|
64 |
}
|
65 |
|