Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update time 0.3 and postgres 0.19 #241

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ serde = "1"
serde_derive = "1"
serde_json = "1"
sha1 = "0.6.0"
time = "0.2"
time = { version = "0.3", features = [ "local-offset" ] }
tiny_http = "0.8.1"
url = "2"
threadpool = "1"
num_cpus = "1"
byteorder = "1.4.3"

[dev-dependencies]
postgres = { version = "0.15.2", default-features = false }
postgres = { version = "0.19", default-features = false }
log = "0.4"
14 changes: 6 additions & 8 deletions examples/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ extern crate serde_derive;

use std::sync::Mutex;

use postgres::transaction::Transaction;
use postgres::Connection;
use postgres::TlsMode;
use postgres::{Client, NoTls, Transaction};

use rouille::Request;
use rouille::Response;
Expand All @@ -38,7 +36,7 @@ fn main() {
// Not wrapping a mutex around the database would lead to a compilation error when we attempt
// to use the variable `db` from within the closure passed to `start_server`.
let db = {
let db = Connection::connect("postgres://test:test@localhost/test", TlsMode::None);
let db = Client::connect("postgres://test:test@localhost/test", NoTls);
Mutex::new(db.expect("Failed to connect to database"))
};

Expand Down Expand Up @@ -80,14 +78,14 @@ fn main() {
// In addition to this, if a panic happens while the `Mutex` is locked then the database
// connection will likely be in a corrupted state and the next time the mutex is locked
// it will panic. This is another good reason to use multiple connections.
let db = db.lock().unwrap();
let mut db = db.lock().unwrap();

// Start a transaction so that if a panic happens during the processing of the request,
// any change made to the database will be rolled back.
let db = db.transaction().unwrap();
let mut db = db.transaction().unwrap();

// For better readability, we handle the request in a separate function.
let response = note_routes(&request, &db);
let response = note_routes(&request, &mut db);

// If the response is a success, we commit the transaction before returning. It's only at
// this point that data are actually written in the database.
Expand All @@ -100,7 +98,7 @@ fn main() {
}

// This function actually handles the request.
fn note_routes(request: &Request, db: &Transaction) -> Response {
fn note_routes(request: &Request, db: &mut Transaction) -> Response {
router!(request,
(GET) (/) => {
// For the sake of the example we just put a dummy route for `/` so that you see
Expand Down
3 changes: 1 addition & 2 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ where
Err(_) => return Response::empty_404(),
};

let now =
time::OffsetDateTime::try_now_local().unwrap_or_else(|_| time::OffsetDateTime::now_utc());
let now = time::OffsetDateTime::now_local().unwrap_or_else(|_| time::OffsetDateTime::now_utc());
let etag: String = (fs::metadata(&potential_file)
.map(|meta| filetime::FileTime::from_last_modification_time(&meta).unix_seconds() as u64)
.unwrap_or(now.nanosecond() as u64)
Expand Down