Update depedencies:

* contrib: 'rmp-serde', 'tera', 'memcache', 'mysql', 'postgres', 'redis'.
* examples: 'parking-lot', 'rand'
This commit is contained in:
Razican 2020-01-14 17:20:06 +01:00 committed by Jeb Rosen
parent ff2000293c
commit f4bb8bb511
7 changed files with 46 additions and 26 deletions

View File

@ -49,33 +49,33 @@ log = "0.4"
# Serialization and templating dependencies. # Serialization and templating dependencies.
serde = { version = "1.0", optional = true } serde = { version = "1.0", optional = true }
serde_json = { version = "1.0.26", optional = true } serde_json = { version = "1.0.26", optional = true }
rmp-serde = { version = "^0.13", optional = true } rmp-serde = { version = "0.14.0", optional = true }
# Templating dependencies. # Templating dependencies.
handlebars = { version = "2.0", optional = true } handlebars = { version = "2.0", optional = true }
glob = { version = "0.3", optional = true } glob = { version = "0.3", optional = true }
tera = { version = "0.11", optional = true } tera = { version = "1.0.2", optional = true }
# UUID dependencies. # UUID dependencies.
uuid = { version = ">=0.7.0, <0.9.0", optional = true } uuid = { version = ">=0.7.0, <0.9.0", optional = true }
# Database dependencies # Database dependencies
diesel = { version = "1.0", default-features = false, optional = true } diesel = { version = "1.0", default-features = false, optional = true }
postgres = { version = "0.15", optional = true } postgres = { version = "0.17", optional = true }
r2d2 = { version = "0.8", optional = true } r2d2 = { version = "0.8", optional = true }
r2d2_postgres = { version = "0.14", optional = true } r2d2_postgres = { version = "0.16", optional = true }
mysql = { version = "16.0", optional = true } mysql = { version = "17.0", optional = true }
r2d2_mysql = { version = "16.0", optional = true } r2d2_mysql = { version = "17.0", optional = true }
rusqlite = { version = "0.16.0", optional = true } rusqlite = { version = "0.16.0", optional = true }
r2d2_sqlite = { version = "0.8", optional = true } r2d2_sqlite = { version = "0.8", optional = true }
rusted_cypher = { version = "1", optional = true } rusted_cypher = { version = "1", optional = true }
r2d2_cypher = { version = "0.4", optional = true } r2d2_cypher = { version = "0.4", optional = true }
redis = { version = "0.10", optional = true } redis = { version = "0.13", optional = true }
r2d2_redis = { version = "0.9", optional = true } r2d2_redis = { version = "0.12", optional = true }
mongodb = { version = "0.3.12", optional = true } mongodb = { version = "0.3.12", optional = true }
r2d2-mongodb = { version = "0.2.0", optional = true } r2d2-mongodb = { version = "0.2.0", optional = true }
memcache = { version = "0.11", optional = true } memcache = { version = "0.14", optional = true }
r2d2-memcache = { version = "0.3", optional = true } r2d2-memcache = { version = "0.5", optional = true }
# SpaceHelmet dependencies # SpaceHelmet dependencies
time = { version = "0.1.40", optional = true } time = { version = "0.1.40", optional = true }

View File

@ -221,7 +221,7 @@
//! use rocket_contrib::databases::postgres; //! use rocket_contrib::databases::postgres;
//! //!
//! #[database("my_pg_db")] //! #[database("my_pg_db")]
//! struct MyPgDatabase(postgres::Connection); //! struct MyPgDatabase(postgres::Client);
//! # } //! # }
//! ``` //! ```
//! //!
@ -756,13 +756,15 @@ impl Poolable for diesel::MysqlConnection {
// TODO: Come up with a way to handle TLS // TODO: Come up with a way to handle TLS
#[cfg(feature = "postgres_pool")] #[cfg(feature = "postgres_pool")]
impl Poolable for postgres::Connection { impl Poolable for postgres::Client {
type Manager = r2d2_postgres::PostgresConnectionManager; type Manager = r2d2_postgres::PostgresConnectionManager<postgres::tls::NoTls>;
type Error = DbError<postgres::Error>; type Error = DbError<postgres::Error>;
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> { fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = r2d2_postgres::PostgresConnectionManager::new(config.url, r2d2_postgres::TlsMode::None) let manager = r2d2_postgres::PostgresConnectionManager::new(
.map_err(DbError::Custom)?; config.url.parse().map_err(DbError::Custom)?,
postgres::tls::NoTls,
);
r2d2::Pool::builder().max_size(config.pool_size).build(manager) r2d2::Pool::builder().max_size(config.pool_size).build(manager)
.map_err(DbError::PoolError) .map_err(DbError::PoolError)

View File

@ -30,7 +30,7 @@ pub(crate) trait Engine: Send + Sync + 'static {
/// use rocket_contrib::templates::{Template, Engines}; /// use rocket_contrib::templates::{Template, Engines};
/// use rocket_contrib::templates::tera::{self, Value}; /// use rocket_contrib::templates::tera::{self, Value};
/// ///
/// fn my_filter(value: Value, _: HashMap<String, Value>) -> tera::Result<Value> { /// fn my_filter(value: &Value, _: &HashMap<String, Value>) -> tera::Result<Value> {
/// # /* /// # /*
/// ... /// ...
/// # */ unimplemented!(); /// # */ unimplemented!();

View File

@ -1,8 +1,9 @@
use serde::Serialize; use serde::Serialize;
use std::error::Error;
use crate::templates::{Engine, TemplateInfo}; use crate::templates::{Engine, TemplateInfo};
pub use crate::templates::tera::Tera; pub use crate::templates::tera::{Context, Tera};
impl Engine for Tera { impl Engine for Tera {
const EXT: &'static str = "tera"; const EXT: &'static str = "tera";
@ -21,8 +22,11 @@ impl Engine for Tera {
// Finally try to tell Tera about all of the templates. // Finally try to tell Tera about all of the templates.
if let Err(e) = tera.add_template_files(tera_templates) { if let Err(e) = tera.add_template_files(tera_templates) {
error!("Failed to initialize Tera templating."); error!("Failed to initialize Tera templating.");
for error in e.iter() {
info_!("{}", error); let mut error = Some(&e as &dyn Error);
while let Some(err) = error {
info_!("{}", err);
error = err.source();
} }
None None
@ -37,12 +41,26 @@ impl Engine for Tera {
return None; return None;
}; };
match Tera::render(self, name, &context) { let tera_ctx = match Context::from_serialize(context) {
Ok(ctx) => ctx,
Err(_) => {
error_!(
"Error generating context when rendering Tera template '{}'.",
name
);
return None;
}
};
match Tera::render(self, name, &tera_ctx) {
Ok(string) => Some(string), Ok(string) => Some(string),
Err(e) => { Err(e) => {
error_!("Error rendering Tera template '{}'.", name); error_!("Error rendering Tera template '{}'.", name);
for error in e.iter() {
error_!("{}", error); let mut error = Some(&e as &dyn Error);
while let Some(err) = error {
error_!("{}", err);
error = err.source();
} }
None None

View File

@ -7,4 +7,4 @@ publish = false
[dependencies] [dependencies]
rocket = { path = "../../core/lib" } rocket = { path = "../../core/lib" }
rand = "0.6" rand = "0.7"

View File

@ -15,8 +15,8 @@ diesel_migrations = "1.3"
log = "0.4" log = "0.4"
[dev-dependencies] [dev-dependencies]
parking_lot = { version = "0.8", features = ["nightly"] } parking_lot = { version = "0.10", features = ["nightly"] }
rand = "0.6" rand = "0.7"
[dependencies.rocket_contrib] [dependencies.rocket_contrib]
path = "../../contrib/lib" path = "../../contrib/lib"

View File

@ -83,7 +83,7 @@ fn test_toggle() {
fn test_many_insertions() { fn test_many_insertions() {
const ITER: usize = 100; const ITER: usize = 100;
let mut rng = thread_rng(); let rng = thread_rng();
run_test!(|client, conn| { run_test!(|client, conn| {
// Get the number of tasks initially. // Get the number of tasks initially.
let init_num = Task::all(&conn).len(); let init_num = Task::all(&conn).len();