Commit Graph

1483 Commits

Author SHA1 Message Date
Jeb Rosen
bc1b90cbdb Add '#[rocket::main]' attribute and make 'launch()' an 'async fn'.
'#[rocket::main]' works like '#[rocket::async_test]', but it uses
tokio's multithreaded scheduler.
2020-07-11 09:24:29 -07:00
Jeb Rosen
7a62653cdd Add a test verifying that attempting to manage the same state type twice panics. 2020-07-11 09:24:29 -07:00
Jeb Rosen
e72058de81 Add 'config()' and 'state()' functions directly to 'Rocket' for convenience. 2020-07-11 09:24:29 -07:00
Jeb Rosen
85b3259120 Convert assertions in 'form_kitchen_sink' tests to use macros. 2020-07-11 09:24:29 -07:00
Jeb Rosen
b0238e5110 Make 'Fairing::on_attach()' async.
This transitively requires that 'Rocket::inspect()', 'Client::new()',
and 'Client::untracked()' also become async.
2020-07-11 09:24:29 -07:00
Jeb Rosen
dea940c7a8 Defer execution of operations on 'Rocket' until their effects will be
observed.

This is a prerequisite for async on_attach fairings. 'Rocket' is now a
builder wrapper around the 'Manifest' type, with operations being
applied when needed by 'launch()', 'Client::new()', or 'inspect()'.
'inspect()' returns an '&Manifest', which now provides the methods that
could be called on an '&Rocket'.
2020-07-11 09:24:29 -07:00
Jeb Rosen
3796673740 Update UI tests for latest nightly. 2020-07-11 09:24:29 -07:00
Sergio Benitez
8696dd94af Make references to core types absolute in codegen.
Prior to this commit, codegen emitted tokens containing bare types like
'Result' and 'Box' as well as presumed imported variants such as 'None'
and 'Ok'.  However, users are free to shadow these, and if they do, the
generated code will fail to compile, or worse, be incorrect. To avoid
this, this commit makes all references to these core types and imports
absolute.
2020-07-11 09:24:29 -07:00
Jeb Rosen
71b888c2fa Fix AddrParseError when the incoming connection's remote_addr is not known. 2020-07-11 09:24:29 -07:00
Jeb Rosen
2ca15b663a Update minimum nightly to '2019-12-29'.
This version of rustc was the first to ship with a version of cargo that
supports 'proc_macro' without an 'extern crate' declaration.
2020-07-11 09:24:29 -07:00
Sergio Benitez
98a90808b4 Fix an array of broken doc links. 2020-07-11 09:24:29 -07:00
Sergio Benitez
c0c6c79a7f Use 'async_trait' for 'Responder'.
Also:

  * Remove 'response::ResultFuture'.
  * Re-export 'tokio' and 'futures' from the crate root.
  * Make 'ResponseBuilder::sized_body()' and 'async fn'.
  * Remove the 'Future' implementation for 'ResponseBuilder'.
  * Add 'ResponseBuilder::finalize()' for finalizing the builder.
2020-07-11 09:24:29 -07:00
Sergio Benitez
58f81d392e Simplify async 'Response' methods. 2020-07-11 09:24:29 -07:00
Sergio Benitez
431b963774 Use 'async_trait' for 'FromRequest'.
Removes 'FromRequestAsync'.
2020-07-11 09:24:29 -07:00
Sergio Benitez
48c333721c Use 'async_trait' for 'Fairing' trait.
Also re-exports the 'async_trait' attribute from 'rocket'.
2020-07-11 09:24:29 -07:00
Sergio Benitez
a4e7972b4b Remove unnecessary 'extern crate's. 2020-07-11 09:24:29 -07:00
Sergio Benitez
73484f1a88 Implement 'Responder' for 'tokio::fs::File'. 2020-07-11 09:24:29 -07:00
Michael Howell
5f3baf240a Deduplicate response streaming code for sized and chunked bodies. 2020-07-11 09:24:29 -07:00
Jeb Rosen
d5483cb196 Clean up Error handling.
* Implement `std::error::Error` for the new Error type.
* Document the new Error type.
* Remove `LaunchError`'s implementation of `Error::description`, which is deprecated.
2020-07-11 09:24:29 -07:00
Jeb Rosen
70db7fb2ea Add some general documentation on async as it pertains to Rocket. 2020-07-11 09:24:29 -07:00
Jeb Rosen
f2487ccec5 Update the guide for async-related API changes. 2020-07-11 09:24:29 -07:00
Jeb Rosen
85761c08e3 Fix deprecation warning: 'tokio::runtime::Builder::num_threads' -> 'core_threads'. 2020-07-11 09:24:29 -07:00
Michael Howell
c9d0af09d6 Use 'AsyncSeek' for sized bodies in 'Response's.
In order to avoid making 'ResponseBuilder::sized_body' an asynchronous
function, the seeking is deferred until finalization. 'finalize()' is
replaced with '.await', and 'ResponseBuilder::ok()' is an 'async fn'.
2020-07-11 09:24:29 -07:00
Jeb Rosen
dcd4068ca0 Move a debug-only 'use' in 'from_data.rs' to the locations where it is actually used. 2020-07-11 09:24:29 -07:00
Jeb Rosen
e41abc09e5 Update more API documentation to mention futures and async. 2020-07-11 09:24:29 -07:00
Jeb Rosen
9a16aeb2e0 Use async fn instead of impl Future in a few methods in 'Data' and 'Rocket'. 2020-07-11 09:24:29 -07:00
Jeb Rosen
f442642ec2 Fix request URI tests. 2020-07-11 09:24:29 -07:00
Jeb Rosen
49f4641871 Clean up handling of body data:
* Minor code and comment tweaks
* Remove dynamic dispatch inside Data and DataStream
2020-07-11 09:24:29 -07:00
Jeb Rosen
571e2ac845 Revert incoming request URI and header parsing to more closely match 0.4. 2020-07-11 09:24:29 -07:00
Jeb Rosen
c2da8a21d8 Change a panic to an error when a client sends a request but disconnects before a response can be sent. 2020-07-11 09:24:29 -07:00
Jeb Rosen
70096c1bd4 Revert on_response lifetimes to more closely match 0.4. 2020-07-11 09:24:29 -07:00
Jeb Rosen
4bb4c61528 Allow implementations of on_request fairings to return a Future that borrows from self, request, and data. 2020-07-11 09:24:29 -07:00
Jeb Rosen
cc3298c3e4 Allow implementations of FromData to return a Future that borrows from the request. 2020-07-11 09:24:29 -07:00
Jeb Rosen
468f4d9314 Simplify FromRequestAsync trait definition. 2020-07-11 09:24:29 -07:00
Paolo Barbolini
003bf77c29 Upgrade to tokio 0.2.0.
* Update 'tokio', 'tokio-rustls', and 'hyper'.
* Remove unused dependencies on some `futures-*` crates.
* Rework 'spawn_on', which is now 'serve'.
* Simplify Ctrl-C handling.
2020-07-11 09:24:29 -07:00
Jeb Rosen
7c4cd068d1 Update for rust-lang/rust#64856.
Raise the nightly version to one that accepts '...(format!(...)).await'.

This additionally reverts commit bdbf80f2da.
2020-07-11 09:24:29 -07:00
Jeb Rosen
6321797a74 Update compile error tests for databases. 2020-07-11 09:24:29 -07:00
Jeb Rosen
df52616074 Update error positions after changes for async #[catch] support. 2020-07-11 09:24:29 -07:00
Jeb Rosen
2fa2d636e4 Implement FromRequestAsync instead of FromRequest for Option and Result. 2020-07-11 09:24:29 -07:00
Jeb Rosen
4e5b889358 Add async-routes test for #[get] and #[catch]. 2020-07-11 09:24:29 -07:00
Follpvosten
189fd65b17 Add 'Request::local_cache_async' for use in async request guards. 2020-07-11 09:24:29 -07:00
Jeb Rosen
5317664893 Fix UI tests for FromRequestAsync. 2020-07-11 09:24:29 -07:00
Jeb Rosen
1c28a9413b Allow catchers to be async fn. 2020-07-11 09:24:29 -07:00
Jeb Rosen
0ab787e216 Use 'tokio_executor::blocking' when acquiring connections from synchronous database pools to avoid tying up the executor. 2020-07-11 09:24:29 -07:00
Jeb Rosen
adf7e4233a Add 'FromRequestAsync' and use it in route codegen.
'FromRequestAsync' is automatically implemented for all types
that implement 'FromRequest'.
2020-07-11 09:24:29 -07:00
Jeb Rosen
ea06878581 Update 'hyper', 'futures-*-preview', and 'tokio-*' dependencies.
Use I/O traits and types from 'tokio-io' as much as possible.

A few adapters only exist in futures-io-preview and use
futures-tokio-compat as a bridge for now.
2020-07-11 09:24:29 -07:00
Jeb Rosen
0d89637e8b Propagate errors while writing out response instead of panicking. 2020-07-11 09:24:28 -07:00
Jeb Rosen
8718561bf8 Emit an error when #[async_test] is applied to a function with parameters. 2020-07-11 09:24:28 -07:00
Jeb Rosen
76ef92a2e1 Use a tokio timer instead of std:🧵:sleep in template reload test. 2020-07-11 09:24:28 -07:00
Jeb Rosen
d1815e527f Update 'hyper', 'tokio', and 'tokio-rustls'.
* hyper -> 0.13.0-alpha.2
* tokio -> 0.2.0-alpha.5
* tokio-rustls -> 0.12.0-alpha.3
2020-07-11 09:24:28 -07:00