Skip to content

Commit df609a0

Browse files
committed
code fmt
1 parent 1f29aa9 commit df609a0

File tree

256 files changed

+6667
-3981
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+6667
-3981
lines changed

Taskfile.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ version: "3"
55
#
66
includes:
77
rocket:
8-
taskfile: packages/rocket/rocket-0.5.0-rc.2/examples/Taskfile.yml
9-
dir: packages/rocket/rocket-0.5.0-rc.2/examples/
8+
taskfile: packages/rocket/rocket-0.5.0-rc.2/Taskfile.yml
9+
dir: packages/rocket/rocket-0.5.0-rc.2/
1010

1111

1212
#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: "3"
2+
3+
#
4+
# sub namespace: https://taskfile.dev/#/usage?id=including-other-taskfiles
5+
#
6+
includes:
7+
ex:
8+
taskfile: ./examples/Taskfile.yml
9+
dir: ./examples/
10+
11+
#
12+
# global vars: https://taskfile.dev/#/usage?id=variables
13+
#
14+
vars:
15+
VAR1: "some-var"
16+
17+
# global env:
18+
env:
19+
ENV1: testing
20+
21+
# env file:
22+
#dotenv:
23+
# - .env
24+
25+
################################################################################################
26+
27+
tasks:
28+
default:
29+
cmds:
30+
- task: install
31+
- task: run
32+
33+
fmt:
34+
cmds:
35+
- cargo +nightly fmt
36+
37+
run:
38+
cmds:
39+
- task: ex:run:hello
40+
41+
init:
42+
cmds:
43+
- cp .env.local .env
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use proc_macro::TokenStream;
22

3-
use devise::{DeriveGenerator, FromMeta, MapperBuild, Support, ValidatorBuild};
43
use devise::proc_macro2_diagnostics::SpanDiagnosticExt;
54
use devise::syn::{self, spanned::Spanned};
5+
use devise::{DeriveGenerator, FromMeta, MapperBuild, Support, ValidatorBuild};
66

77
const ONE_DATABASE_ATTR: &str = "missing `#[database(\"name\")]` attribute";
88
const ONE_UNNAMED_FIELD: &str = "struct must have exactly one unnamed field";
@@ -16,95 +16,89 @@ struct DatabaseAttribute {
1616
pub fn derive_database(input: TokenStream) -> TokenStream {
1717
DeriveGenerator::build_for(input, quote!(impl rocket_db_pools::Database))
1818
.support(Support::TupleStruct)
19-
.validator(ValidatorBuild::new()
20-
.struct_validate(|_, s| {
21-
if s.fields.len() == 1 {
22-
Ok(())
23-
} else {
24-
Err(s.span().error(ONE_UNNAMED_FIELD))
25-
}
26-
})
27-
)
28-
.outer_mapper(MapperBuild::new()
29-
.struct_map(|_, s| {
30-
let pool_type = match &s.fields {
31-
syn::Fields::Unnamed(f) => &f.unnamed[0].ty,
32-
_ => unreachable!("Support::TupleStruct"),
33-
};
34-
35-
let decorated_type = &s.ident;
36-
let db_ty = quote_spanned!(decorated_type.span() =>
37-
<#decorated_type as rocket_db_pools::Database>
38-
);
39-
40-
quote_spanned! { decorated_type.span() =>
41-
impl From<#pool_type> for #decorated_type {
42-
fn from(pool: #pool_type) -> Self {
43-
Self(pool)
44-
}
19+
.validator(ValidatorBuild::new().struct_validate(|_, s| {
20+
if s.fields.len() == 1 {
21+
Ok(())
22+
} else {
23+
Err(s.span().error(ONE_UNNAMED_FIELD))
24+
}
25+
}))
26+
.outer_mapper(MapperBuild::new().struct_map(|_, s| {
27+
let pool_type = match &s.fields {
28+
syn::Fields::Unnamed(f) => &f.unnamed[0].ty,
29+
_ => unreachable!("Support::TupleStruct"),
30+
};
31+
32+
let decorated_type = &s.ident;
33+
let db_ty = quote_spanned!(decorated_type.span() =>
34+
<#decorated_type as rocket_db_pools::Database>
35+
);
36+
37+
quote_spanned! { decorated_type.span() =>
38+
impl From<#pool_type> for #decorated_type {
39+
fn from(pool: #pool_type) -> Self {
40+
Self(pool)
4541
}
42+
}
4643

47-
impl std::ops::Deref for #decorated_type {
48-
type Target = #pool_type;
44+
impl std::ops::Deref for #decorated_type {
45+
type Target = #pool_type;
4946

50-
fn deref(&self) -> &Self::Target {
51-
&self.0
52-
}
47+
fn deref(&self) -> &Self::Target {
48+
&self.0
5349
}
50+
}
5451

55-
impl std::ops::DerefMut for #decorated_type {
56-
fn deref_mut(&mut self) -> &mut Self::Target {
57-
&mut self.0
58-
}
52+
impl std::ops::DerefMut for #decorated_type {
53+
fn deref_mut(&mut self) -> &mut Self::Target {
54+
&mut self.0
5955
}
56+
}
6057

61-
#[rocket::async_trait]
62-
impl<'r> rocket::request::FromRequest<'r> for &'r #decorated_type {
63-
type Error = ();
64-
65-
async fn from_request(
66-
req: &'r rocket::request::Request<'_>
67-
) -> rocket::request::Outcome<Self, Self::Error> {
68-
match #db_ty::fetch(req.rocket()) {
69-
Some(db) => rocket::outcome::Outcome::Success(db),
70-
None => rocket::outcome::Outcome::Failure((
71-
rocket::http::Status::InternalServerError, ()))
72-
}
58+
#[rocket::async_trait]
59+
impl<'r> rocket::request::FromRequest<'r> for &'r #decorated_type {
60+
type Error = ();
61+
62+
async fn from_request(
63+
req: &'r rocket::request::Request<'_>
64+
) -> rocket::request::Outcome<Self, Self::Error> {
65+
match #db_ty::fetch(req.rocket()) {
66+
Some(db) => rocket::outcome::Outcome::Success(db),
67+
None => rocket::outcome::Outcome::Failure((
68+
rocket::http::Status::InternalServerError, ()))
7369
}
7470
}
71+
}
7572

76-
impl rocket::Sentinel for &#decorated_type {
77-
fn abort(rocket: &rocket::Rocket<rocket::Ignite>) -> bool {
78-
#db_ty::fetch(rocket).is_none()
79-
}
73+
impl rocket::Sentinel for &#decorated_type {
74+
fn abort(rocket: &rocket::Rocket<rocket::Ignite>) -> bool {
75+
#db_ty::fetch(rocket).is_none()
8076
}
8177
}
82-
})
83-
)
78+
}
79+
}))
8480
.outer_mapper(quote!(#[rocket::async_trait]))
85-
.inner_mapper(MapperBuild::new()
86-
.try_struct_map(|_, s| {
87-
let db_name = DatabaseAttribute::one_from_attrs("database", &s.attrs)?
88-
.map(|attr| attr.name)
89-
.ok_or_else(|| s.span().error(ONE_DATABASE_ATTR))?;
81+
.inner_mapper(MapperBuild::new().try_struct_map(|_, s| {
82+
let db_name = DatabaseAttribute::one_from_attrs("database", &s.attrs)?
83+
.map(|attr| attr.name)
84+
.ok_or_else(|| s.span().error(ONE_DATABASE_ATTR))?;
9085

91-
let fairing_name = format!("'{}' Database Pool", db_name);
86+
let fairing_name = format!("'{}' Database Pool", db_name);
9287

93-
let pool_type = match &s.fields {
94-
syn::Fields::Unnamed(f) => &f.unnamed[0].ty,
95-
_ => unreachable!("Support::TupleStruct"),
96-
};
88+
let pool_type = match &s.fields {
89+
syn::Fields::Unnamed(f) => &f.unnamed[0].ty,
90+
_ => unreachable!("Support::TupleStruct"),
91+
};
9792

98-
Ok(quote_spanned! { pool_type.span() =>
99-
type Pool = #pool_type;
93+
Ok(quote_spanned! { pool_type.span() =>
94+
type Pool = #pool_type;
10095

101-
const NAME: &'static str = #db_name;
96+
const NAME: &'static str = #db_name;
10297

103-
fn init() -> rocket_db_pools::Initializer<Self> {
104-
rocket_db_pools::Initializer::with_name(#fairing_name)
105-
}
106-
})
98+
fn init() -> rocket_db_pools::Initializer<Self> {
99+
rocket_db_pools::Initializer::with_name(#fairing_name)
100+
}
107101
})
108-
)
102+
}))
109103
.to_tokens()
110104
}

packages/rocket/rocket-0.5.0-rc.2/contrib/db_pools/codegen/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![recursion_limit="256"]
1+
#![recursion_limit = "256"]
22
#![warn(rust_2018_idioms)]
33

44
//! # `rocket_db_pool` - Code Generation
@@ -7,7 +7,8 @@
77
//! is an implementation detail. This create should never be depended on
88
//! directly.
99
10-
#[macro_use] extern crate quote;
10+
#[macro_use]
11+
extern crate quote;
1112

1213
mod database;
1314

packages/rocket/rocket-0.5.0-rc.2/contrib/db_pools/codegen/tests/ui-fail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
fn ui() {
33
let path = match version_check::is_feature_flaggable() {
44
Some(true) => "ui-fail-nightly",
5-
_ => "ui-fail-stable"
5+
_ => "ui-fail-stable",
66
};
77

88
let t = trybuild::TestCases::new();

packages/rocket/rocket-0.5.0-rc.2/contrib/db_pools/lib/src/database.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::marker::PhantomData;
22
use std::ops::{Deref, DerefMut};
33

4-
use rocket::{error, info_, Build, Ignite, Phase, Rocket, Sentinel};
54
use rocket::fairing::{self, Fairing, Info, Kind};
6-
use rocket::request::{FromRequest, Outcome, Request};
75
use rocket::http::Status;
6+
use rocket::request::{FromRequest, Outcome, Request};
7+
use rocket::{error, info_, Build, Ignite, Phase, Rocket, Sentinel};
88

9-
use rocket::yansi::Paint;
109
use rocket::figment::providers::Serialized;
10+
use rocket::yansi::Paint;
1111

1212
use crate::Pool;
1313

@@ -33,7 +33,9 @@ use crate::Pool;
3333
/// ```
3434
///
3535
/// See the [`Database` derive](derive@crate::Database) for details.
36-
pub trait Database: From<Self::Pool> + DerefMut<Target = Self::Pool> + Send + Sync + 'static {
36+
pub trait Database:
37+
From<Self::Pool> + DerefMut<Target = Self::Pool> + Send + Sync + 'static
38+
{
3739
/// The [`Pool`] type of connections to this database.
3840
///
3941
/// When `Database` is derived, this takes the value of the `Inner` type in
@@ -124,8 +126,14 @@ pub trait Database: From<Self::Pool> + DerefMut<Target = Self::Pool> + Send + Sy
124126

125127
let dbtype = std::any::type_name::<Self>();
126128
let fairing = Paint::default(format!("{}::init()", dbtype)).bold();
127-
error!("Attempted to fetch unattached database `{}`.", Paint::default(dbtype).bold());
128-
info_!("`{}` fairing must be attached prior to using this database.", fairing);
129+
error!(
130+
"Attempted to fetch unattached database `{}`.",
131+
Paint::default(dbtype).bold()
132+
);
133+
info_!(
134+
"`{}` fairing must be attached prior to using this database.",
135+
fairing
136+
);
129137
None
130138
}
131139
}
@@ -255,11 +263,13 @@ impl<D: Database> Fairing for Initializer<D> {
255263
}
256264

257265
async fn on_ignite(&self, rocket: Rocket<Build>) -> fairing::Result {
258-
let workers: usize = rocket.figment()
266+
let workers: usize = rocket
267+
.figment()
259268
.extract_inner(rocket::Config::WORKERS)
260269
.unwrap_or_else(|_| rocket::Config::default().workers);
261270

262-
let figment = rocket.figment()
271+
let figment = rocket
272+
.figment()
263273
.focus(&format!("databases.{}", D::NAME))
264274
.merge(Serialized::default("max_connections", workers * 4))
265275
.merge(Serialized::default("connect_timeout", 5));

packages/rocket/rocket-0.5.0-rc.2/contrib/db_pools/lib/src/error.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ impl<A: fmt::Display, B: fmt::Display> fmt::Display for Error<A, B> {
2626
}
2727

2828
impl<A, B> std::error::Error for Error<A, B>
29-
where A: fmt::Debug + fmt::Display, B: fmt::Debug + fmt::Display {}
29+
where
30+
A: fmt::Debug + fmt::Display,
31+
B: fmt::Debug + fmt::Display,
32+
{
33+
}
3034

3135
impl<A, B> From<crate::figment::Error> for Error<A, B> {
3236
fn from(e: crate::figment::Error) -> Self {

packages/rocket/rocket-0.5.0-rc.2/contrib/db_pools/lib/src/lib.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -212,27 +212,30 @@
212212
#![doc(html_root_url = "https://api.rocket.rs/master/rocket_db_pools")]
213213
#![doc(html_favicon_url = "https://rocket.rs/images/favicon.ico")]
214214
#![doc(html_logo_url = "https://rocket.rs/images/logo-boxed.png")]
215-
216215
#![deny(missing_docs)]
217216

218217
/// Re-export of the `figment` crate.
219218
#[doc(inline)]
220219
pub use rocket::figment;
221220

221+
#[cfg(feature = "deadpool_postgres")]
222+
pub use deadpool_postgres;
223+
#[cfg(feature = "deadpool_redis")]
224+
pub use deadpool_redis;
225+
#[cfg(feature = "mongodb")]
226+
pub use mongodb;
222227
pub use rocket;
223-
#[cfg(feature = "deadpool_postgres")] pub use deadpool_postgres;
224-
#[cfg(feature = "deadpool_redis")] pub use deadpool_redis;
225-
#[cfg(feature = "mongodb")] pub use mongodb;
226-
#[cfg(feature = "sqlx")] pub use sqlx;
228+
#[cfg(feature = "sqlx")]
229+
pub use sqlx;
227230

231+
mod config;
228232
mod database;
229233
mod error;
230234
mod pool;
231-
mod config;
232235

236+
pub use self::config::Config;
233237
pub use self::database::{Connection, Database, Initializer};
234238
pub use self::error::Error;
235239
pub use self::pool::Pool;
236-
pub use self::config::Config;
237240

238241
pub use rocket_db_pools_codegen::*;

0 commit comments

Comments
 (0)