1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)]
use async_trait::async_trait;
use futures::Stream;
use std::error::Error;
use std::task::{Poll, Context};
use swagger::{ApiError, ContextWrapper};
use serde::{Serialize, Deserialize};
type ServiceError = Box<dyn Error + Send + Sync + 'static>;
pub const BASE_PATH: &'static str = "";
pub const API_VERSION: &'static str = "1.0.0";
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[must_use]
pub enum AddApplicationResponse {
SuccessfulOperation
(models::Application)
,
InvalidInput
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[must_use]
pub enum UpdateApplicationResponse {
SuccessfulOperation
(models::Application)
,
InvalidIDSupplied
,
PetNotFound
,
ValidationException
}
#[async_trait]
pub trait Api<C: Send + Sync> {
fn poll_ready(&self, _cx: &mut Context) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>> {
Poll::Ready(Ok(()))
}
async fn add_application(
&self,
application: models::Application,
context: &C) -> Result<AddApplicationResponse, ApiError>;
async fn update_application(
&self,
application_id: i64,
application: models::Application,
context: &C) -> Result<UpdateApplicationResponse, ApiError>;
}
#[async_trait]
pub trait ApiNoContext<C: Send + Sync> {
fn poll_ready(&self, _cx: &mut Context) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>>;
fn context(&self) -> &C;
async fn add_application(
&self,
application: models::Application,
) -> Result<AddApplicationResponse, ApiError>;
async fn update_application(
&self,
application_id: i64,
application: models::Application,
) -> Result<UpdateApplicationResponse, ApiError>;
}
pub trait ContextWrapperExt<C: Send + Sync> where Self: Sized
{
fn with_context(self: Self, context: C) -> ContextWrapper<Self, C>;
}
impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ContextWrapperExt<C> for T {
fn with_context(self: T, context: C) -> ContextWrapper<T, C> {
ContextWrapper::<T, C>::new(self, context)
}
}
#[async_trait]
impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for ContextWrapper<T, C> {
fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), ServiceError>> {
self.api().poll_ready(cx)
}
fn context(&self) -> &C {
ContextWrapper::context(self)
}
async fn add_application(
&self,
application: models::Application,
) -> Result<AddApplicationResponse, ApiError>
{
let context = self.context().clone();
self.api().add_application(application, &context).await
}
async fn update_application(
&self,
application_id: i64,
application: models::Application,
) -> Result<UpdateApplicationResponse, ApiError>
{
let context = self.context().clone();
self.api().update_application(application_id, application, &context).await
}
}
#[cfg(feature = "client")]
pub mod client;
#[cfg(feature = "client")]
pub use client::Client;
#[cfg(feature = "server")]
pub mod server;
#[cfg(feature = "server")]
pub use self::server::Service;
#[cfg(feature = "server")]
pub mod context;
pub mod models;
#[cfg(any(feature = "client", feature = "server"))]
pub(crate) mod header;