diff --git a/contrib/lib/Cargo.toml b/contrib/lib/Cargo.toml index a1ab855d..2c7d2016 100644 --- a/contrib/lib/Cargo.toml +++ b/contrib/lib/Cargo.toml @@ -49,33 +49,33 @@ log = "0.4" # Serialization and templating dependencies. serde = { version = "1.0", 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. handlebars = { version = "2.0", optional = true } glob = { version = "0.3", optional = true } -tera = { version = "0.11", optional = true } +tera = { version = "1.0.2", optional = true } # UUID dependencies. uuid = { version = ">=0.7.0, <0.9.0", optional = true } # Database dependencies 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_postgres = { version = "0.14", optional = true } -mysql = { version = "16.0", optional = true } -r2d2_mysql = { version = "16.0", optional = true } +r2d2_postgres = { version = "0.16", optional = true } +mysql = { version = "17.0", optional = true } +r2d2_mysql = { version = "17.0", optional = true } rusqlite = { version = "0.16.0", optional = true } r2d2_sqlite = { version = "0.8", optional = true } rusted_cypher = { version = "1", optional = true } r2d2_cypher = { version = "0.4", optional = true } -redis = { version = "0.10", optional = true } -r2d2_redis = { version = "0.9", optional = true } +redis = { version = "0.13", optional = true } +r2d2_redis = { version = "0.12", optional = true } mongodb = { version = "0.3.12", optional = true } r2d2-mongodb = { version = "0.2.0", optional = true } -memcache = { version = "0.11", optional = true } -r2d2-memcache = { version = "0.3", optional = true } +memcache = { version = "0.14", optional = true } +r2d2-memcache = { version = "0.5", optional = true } # SpaceHelmet dependencies time = { version = "0.1.40", optional = true } diff --git a/contrib/lib/src/databases.rs b/contrib/lib/src/databases.rs index 0270d89e..3ea4e007 100644 --- a/contrib/lib/src/databases.rs +++ b/contrib/lib/src/databases.rs @@ -221,7 +221,7 @@ //! use rocket_contrib::databases::postgres; //! //! #[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 #[cfg(feature = "postgres_pool")] -impl Poolable for postgres::Connection { - type Manager = r2d2_postgres::PostgresConnectionManager; +impl Poolable for postgres::Client { + type Manager = r2d2_postgres::PostgresConnectionManager; type Error = DbError; fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error> { - let manager = r2d2_postgres::PostgresConnectionManager::new(config.url, r2d2_postgres::TlsMode::None) - .map_err(DbError::Custom)?; + let manager = r2d2_postgres::PostgresConnectionManager::new( + config.url.parse().map_err(DbError::Custom)?, + postgres::tls::NoTls, + ); r2d2::Pool::builder().max_size(config.pool_size).build(manager) .map_err(DbError::PoolError) diff --git a/contrib/lib/src/templates/engine.rs b/contrib/lib/src/templates/engine.rs index 14f5e17f..c5c9f199 100644 --- a/contrib/lib/src/templates/engine.rs +++ b/contrib/lib/src/templates/engine.rs @@ -30,7 +30,7 @@ pub(crate) trait Engine: Send + Sync + 'static { /// use rocket_contrib::templates::{Template, Engines}; /// use rocket_contrib::templates::tera::{self, Value}; /// -/// fn my_filter(value: Value, _: HashMap) -> tera::Result { +/// fn my_filter(value: &Value, _: &HashMap) -> tera::Result { /// # /* /// ... /// # */ unimplemented!(); diff --git a/contrib/lib/src/templates/tera_templates.rs b/contrib/lib/src/templates/tera_templates.rs index 9dcccfcf..d841b414 100644 --- a/contrib/lib/src/templates/tera_templates.rs +++ b/contrib/lib/src/templates/tera_templates.rs @@ -1,8 +1,9 @@ use serde::Serialize; +use std::error::Error; use crate::templates::{Engine, TemplateInfo}; -pub use crate::templates::tera::Tera; +pub use crate::templates::tera::{Context, Tera}; impl Engine for Tera { const EXT: &'static str = "tera"; @@ -21,8 +22,11 @@ impl Engine for Tera { // Finally try to tell Tera about all of the templates. if let Err(e) = tera.add_template_files(tera_templates) { 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 @@ -37,12 +41,26 @@ impl Engine for Tera { 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), Err(e) => { 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 diff --git a/examples/pastebin/Cargo.toml b/examples/pastebin/Cargo.toml index e508d89e..ffd1adc7 100644 --- a/examples/pastebin/Cargo.toml +++ b/examples/pastebin/Cargo.toml @@ -7,4 +7,4 @@ publish = false [dependencies] rocket = { path = "../../core/lib" } -rand = "0.6" +rand = "0.7" diff --git a/examples/todo/Cargo.toml b/examples/todo/Cargo.toml index 21662e25..2478841f 100644 --- a/examples/todo/Cargo.toml +++ b/examples/todo/Cargo.toml @@ -15,8 +15,8 @@ diesel_migrations = "1.3" log = "0.4" [dev-dependencies] -parking_lot = { version = "0.8", features = ["nightly"] } -rand = "0.6" +parking_lot = { version = "0.10", features = ["nightly"] } +rand = "0.7" [dependencies.rocket_contrib] path = "../../contrib/lib" diff --git a/examples/todo/src/tests.rs b/examples/todo/src/tests.rs index 1553e9ef..e09a9a3a 100644 --- a/examples/todo/src/tests.rs +++ b/examples/todo/src/tests.rs @@ -83,7 +83,7 @@ fn test_toggle() { fn test_many_insertions() { const ITER: usize = 100; - let mut rng = thread_rng(); + let rng = thread_rng(); run_test!(|client, conn| { // Get the number of tasks initially. let init_num = Task::all(&conn).len();