Skip to content

Commit 4a30e3f

Browse files
committed
Format manually written files
1 parent fb78ea4 commit 4a30e3f

29 files changed

+1342
-460
lines changed

rust/src/api/client.rs

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
use std::{sync::Arc, time::Duration};
1+
use std::{
2+
sync::Arc,
3+
time::Duration,
4+
};
25

3-
use hyper_util::{client::legacy::Client as HyperClient, rt::TokioExecutor};
6+
use hyper_util::{
7+
client::legacy::Client as HyperClient,
8+
rt::TokioExecutor,
9+
};
410

511
use crate::Configuration;
612

@@ -64,20 +70,25 @@ pub struct Svix {
6470
}
6571

6672
impl Svix {
67-
pub fn new(token: String, options: Option<SvixOptions>) -> Self {
73+
pub fn new(
74+
token: String,
75+
options: Option<SvixOptions>,
76+
) -> Self {
6877
let options = options.unwrap_or_default();
6978

70-
let cfg = Arc::new(Configuration {
71-
user_agent: Some(format!("svix-libs/{CRATE_VERSION}/rust")),
72-
client: HyperClient::builder(TokioExecutor::new())
73-
.build(crate::make_connector(options.proxy_address)),
74-
timeout: options.timeout,
75-
// These fields will be set by `with_token` below
76-
base_path: String::new(),
77-
bearer_access_token: None,
78-
num_retries: options.num_retries.unwrap_or(2),
79-
retry_schedule: options.retry_schedule,
80-
});
79+
let cfg = Arc::new(
80+
Configuration {
81+
user_agent: Some(format!("svix-libs/{CRATE_VERSION}/rust")),
82+
client: HyperClient::builder(TokioExecutor::new())
83+
.build(crate::make_connector(options.proxy_address)),
84+
timeout: options.timeout,
85+
// These fields will be set by `with_token` below
86+
base_path: String::new(),
87+
bearer_access_token: None,
88+
num_retries: options.num_retries.unwrap_or(2),
89+
retry_schedule: options.retry_schedule,
90+
},
91+
);
8192
let svix = Self {
8293
cfg,
8394
server_url: options.server_url,
@@ -91,27 +102,34 @@ impl Svix {
91102
///
92103
/// This can be used to change the token without incurring
93104
/// the cost of TLS initialization.
94-
pub fn with_token(&self, token: String) -> Self {
95-
let base_path = self.server_url.clone().unwrap_or_else(|| {
96-
match token.split('.').next_back() {
97-
Some("us") => "https://api.us.svix.com",
98-
Some("eu") => "https://api.eu.svix.com",
99-
Some("in") => "https://api.in.svix.com",
100-
Some("ca") => "https://api.ca.svix.com",
101-
Some("au") => "https://api.au.svix.com",
102-
_ => "https://api.svix.com",
103-
}
104-
.to_string()
105-
});
106-
let cfg = Arc::new(Configuration {
107-
base_path,
108-
user_agent: self.cfg.user_agent.clone(),
109-
bearer_access_token: Some(token),
110-
client: self.cfg.client.clone(),
111-
timeout: self.cfg.timeout,
112-
num_retries: self.cfg.num_retries,
113-
retry_schedule: self.cfg.retry_schedule.clone(),
114-
});
105+
pub fn with_token(
106+
&self,
107+
token: String,
108+
) -> Self {
109+
let base_path = self.server_url.clone().unwrap_or_else(
110+
|| {
111+
match token.split('.').next_back() {
112+
Some("us") => "https://api.us.svix.com",
113+
Some("eu") => "https://api.eu.svix.com",
114+
Some("in") => "https://api.in.svix.com",
115+
Some("ca") => "https://api.ca.svix.com",
116+
Some("au") => "https://api.au.svix.com",
117+
_ => "https://api.svix.com",
118+
}
119+
.to_string()
120+
},
121+
);
122+
let cfg = Arc::new(
123+
Configuration {
124+
base_path,
125+
user_agent: self.cfg.user_agent.clone(),
126+
bearer_access_token: Some(token),
127+
client: self.cfg.client.clone(),
128+
timeout: self.cfg.timeout,
129+
num_retries: self.cfg.num_retries,
130+
retry_schedule: self.cfg.retry_schedule.clone(),
131+
},
132+
);
115133

116134
Self {
117135
cfg,
@@ -133,9 +151,15 @@ mod tests {
133151
fn test_future_send_sync() {
134152
fn require_send_sync<T: Send + Sync>(_: T) {}
135153

136-
let svix = Svix::new(String::new(), None);
154+
let svix = Svix::new(
155+
String::new(),
156+
None,
157+
);
137158
let message_api = svix.message();
138-
let fut = message_api.expunge_content(String::new(), String::new());
159+
let fut = message_api.expunge_content(
160+
String::new(),
161+
String::new(),
162+
);
139163
require_send_sync(fut);
140164
}
141165
}

rust/src/connector.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
use std::{future::Future, pin::Pin};
1+
use std::{
2+
future::Future,
3+
pin::Pin,
4+
};
25

36
use http1::Uri;
47
use hyper_util::{
58
client::legacy::connect::{
6-
proxy::{SocksV5, Tunnel},
9+
proxy::{
10+
SocksV5,
11+
Tunnel,
12+
},
713
HttpConnector,
814
},
915
rt::TokioIo,
@@ -19,11 +25,17 @@ type MaybeHttpsStream<T> = T;
1925

2026
// If only native TLS is enabled, use that.
2127
#[cfg(all(feature = "native-tls", not(feature = "rustls-tls")))]
22-
use hyper_tls::{HttpsConnector as HttpsIfAvailable, MaybeHttpsStream};
28+
use hyper_tls::{
29+
HttpsConnector as HttpsIfAvailable,
30+
MaybeHttpsStream,
31+
};
2332

2433
// If rustls is enabled, use that.
2534
#[cfg(feature = "rustls-tls")]
26-
use hyper_rustls::{HttpsConnector as HttpsIfAvailable, MaybeHttpsStream};
35+
use hyper_rustls::{
36+
HttpsConnector as HttpsIfAvailable,
37+
MaybeHttpsStream,
38+
};
2739

2840
fn wrap_connector<H>(conn: H) -> HttpsIfAvailable<H> {
2941
#[cfg(not(any(feature = "native-tls", feature = "rustls-tls")))]
@@ -64,7 +76,12 @@ pub(crate) enum Connector {
6476
// to be fallible and bubble the error up from `Svix::new`.
6577
pub(crate) fn make_connector(proxy_addr: Option<String>) -> Connector {
6678
let mut http = hyper_util::client::legacy::connect::HttpConnector::new();
67-
if cfg!(any(feature = "native-tls", feature = "rustls-tls")) {
79+
if cfg!(
80+
any(
81+
feature = "native-tls",
82+
feature = "rustls-tls"
83+
)
84+
) {
6885
http.enforce_http(false);
6986
}
7087

@@ -84,15 +101,22 @@ pub(crate) fn make_connector(proxy_addr: Option<String>) -> Connector {
84101

85102
match proxy_addr.scheme_str() {
86103
Some("http" | "https") => {
87-
let tunnel = Tunnel::new(proxy_addr, http);
104+
let tunnel = Tunnel::new(
105+
proxy_addr, http,
106+
);
88107
Connector::HttpProxy(wrap_connector(tunnel))
89108
}
90109
Some("socks5") => {
91-
let socks = SocksV5::new(proxy_addr, http).local_dns(true);
110+
let socks = SocksV5::new(
111+
proxy_addr, http,
112+
)
113+
.local_dns(true);
92114
Connector::Socks5Proxy(wrap_connector(socks))
93115
}
94116
Some("socks5h") => {
95-
let socks = SocksV5::new(proxy_addr, http);
117+
let socks = SocksV5::new(
118+
proxy_addr, http,
119+
);
96120
Connector::Socks5Proxy(wrap_connector(socks))
97121
}
98122
scheme => {
@@ -121,7 +145,10 @@ impl Service<Uri> for Connector {
121145
}
122146
}
123147

124-
fn call(&mut self, req: Uri) -> Self::Future {
148+
fn call(
149+
&mut self,
150+
req: Uri,
151+
) -> Self::Future {
125152
match self {
126153
Self::Regular(inner) => Box::pin(inner.call(req)),
127154
Self::Socks5Proxy(inner) => Box::pin(inner.call(req)),

rust/src/error.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,27 @@ impl Error {
2626
Self::Generic(format!("{err:?}"))
2727
}
2828

29-
pub(crate) async fn from_response(status_code: http1::StatusCode, body: Incoming) -> Self {
29+
pub(crate) async fn from_response(
30+
status_code: http1::StatusCode,
31+
body: Incoming,
32+
) -> Self {
3033
match body.collect().await {
3134
Ok(collected) => {
3235
let bytes = collected.to_bytes();
3336
if status_code == http1::StatusCode::UNPROCESSABLE_ENTITY {
34-
Self::Validation(HttpErrorContent {
35-
status: http02::StatusCode::UNPROCESSABLE_ENTITY,
36-
payload: serde_json::from_slice(&bytes).ok(),
37-
})
37+
Self::Validation(
38+
HttpErrorContent {
39+
status: http02::StatusCode::UNPROCESSABLE_ENTITY,
40+
payload: serde_json::from_slice(&bytes).ok(),
41+
},
42+
)
3843
} else {
39-
Error::Http(HttpErrorContent {
40-
status: http1_to_02_status_code(status_code),
41-
payload: serde_json::from_slice(&bytes).ok(),
42-
})
44+
Error::Http(
45+
HttpErrorContent {
46+
status: http1_to_02_status_code(status_code),
47+
payload: serde_json::from_slice(&bytes).ok(),
48+
},
49+
)
4350
}
4451
}
4552
Err(e) => Self::Generic(e.to_string()),
@@ -55,11 +62,22 @@ impl From<Error> for String {
5562
}
5663

5764
impl fmt::Display for Error {
58-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65+
fn fmt(
66+
&self,
67+
f: &mut fmt::Formatter,
68+
) -> fmt::Result {
5969
match self {
6070
Error::Generic(s) => s.fmt(f),
61-
Error::Http(e) => format!("Http error (status={}) {:?}", e.status, e.payload).fmt(f),
62-
Error::Validation(e) => format!("Validation error {:?}", e.payload).fmt(f),
71+
Error::Http(e) => format!(
72+
"Http error (status={}) {:?}",
73+
e.status, e.payload
74+
)
75+
.fmt(f),
76+
Error::Validation(e) => format!(
77+
"Validation error {:?}",
78+
e.payload
79+
)
80+
.fmt(f),
6381
}
6482
}
6583
}

rust/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ mod models;
2121
mod request;
2222
pub mod webhooks;
2323

24-
pub(crate) use connector::{make_connector, Connector};
24+
pub(crate) use connector::{
25+
make_connector,
26+
Connector,
27+
};
2528

2629
pub struct Configuration {
2730
pub base_path: String,

rust/src/model_ext.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use std::str::FromStr;
55
use serde_json::json;
66

77
use crate::{
8-
api::{MessageStatus, Ordering, StatusCodeClass},
8+
api::{
9+
MessageStatus,
10+
Ordering,
11+
StatusCodeClass,
12+
},
913
models::MessageIn,
1014
};
1115

@@ -22,15 +26,24 @@ impl MessageIn {
2226
/// The default `content-type` of `application/json` will still be used for
2327
/// the webhook sent by Svix, unless overwritten with
2428
/// [`with_content_type`][Self::with_content_type].
25-
pub fn new_raw_payload(event_type: String, payload: String) -> Self {
29+
pub fn new_raw_payload(
30+
event_type: String,
31+
payload: String,
32+
) -> Self {
2633
Self {
2734
transformations_params: Some(json!({ "rawPayload": payload })),
28-
..Self::new(event_type, json!({}))
35+
..Self::new(
36+
event_type,
37+
json!({}),
38+
)
2939
}
3040
}
3141

3242
/// Set the `content-type` header to use for the webhook sent by Svix.
33-
pub fn with_content_type(mut self, content_type: String) -> Self {
43+
pub fn with_content_type(
44+
mut self,
45+
content_type: String,
46+
) -> Self {
3447
let transformations_params = self.transformations_params.get_or_insert_with(|| json!({}));
3548

3649
// This will panic if transformations_params, its headers field, or the

rust/src/models/http_error_out.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
#[allow(unused_imports)]
1212
use crate::models;
1313
#[allow(unused_imports)]
14-
use serde::{Deserialize, Serialize};
14+
use serde::{
15+
Deserialize,
16+
Serialize,
17+
};
1518

1619
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
1720
pub struct HttpErrorOut {
@@ -22,7 +25,13 @@ pub struct HttpErrorOut {
2225
}
2326

2427
impl HttpErrorOut {
25-
pub fn new(code: String, detail: String) -> HttpErrorOut {
26-
HttpErrorOut { code, detail }
28+
pub fn new(
29+
code: String,
30+
detail: String,
31+
) -> HttpErrorOut {
32+
HttpErrorOut {
33+
code,
34+
detail,
35+
}
2736
}
2837
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use serde::{Deserialize, Serialize};
1+
use serde::{
2+
Deserialize,
3+
Serialize,
4+
};
25

36
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
47
pub struct HttpValidationError {
@@ -8,6 +11,8 @@ pub struct HttpValidationError {
811

912
impl HttpValidationError {
1013
pub fn new(detail: Vec<super::ValidationError>) -> HttpValidationError {
11-
HttpValidationError { detail }
14+
HttpValidationError {
15+
detail,
16+
}
1217
}
1318
}

0 commit comments

Comments
 (0)