Commit Graph

164 Commits

Author SHA1 Message Date
Jeb Rosen 560f0977d3 Revamp testing system for async.
* body_string_wait and body_bytes_wait are removed; use `.await` instead
* `dispatch()` is now an async fn and must be .await-ed
* Add `#[rocket::async_test]` macro, similar in purpose to `tokio::test`
* Tests now use either `rocket::async_test(async { })` or
  `#[rocket::async_test]` in order to `.await` the futures returned
  from `dispatch()` and `body_{string,bytes}()`
* Update 'test.sh' to reflect the tests that should be passing.

Broken:

* Cloned dispatch and mut_dispatch() with a live previous response now both fail, due to a (partial) check for mutable aliasing in LocalRequest.
* Some tests are still failing and need example-specific changes.
2020-07-11 09:24:28 -07:00
Jacob Pratt e44c5896b8 Remove stabilized 'async_await' feature gate and update the minimum nightly version. 2020-07-11 09:24:28 -07:00
Jeb Rosen 633e495a6b Update many doc tests in 'core' for async. 2020-07-11 09:24:28 -07:00
Jeb Rosen 7c34a3a93e Make 'Fairing::on_response' and 'Responder::respond_to' async.
This is required to be able to do anything useful with the body in the
outgoing response. Request fairings do not appear to need to be async
as everything on Data that returns a future moves self and on_request only
gets &Data, but the same change in this commit should work for on_request
if desired.
2020-07-11 09:24:28 -07:00
Jeb Rosen 5d439bafc0 Convert core to async and add support for async routes.
Minimum rustc bump required for rust-lang/rust#61775
2020-07-11 09:24:28 -07:00
Sergio Benitez 83925bbae1 Use clearer variables names in guide test macro.
Also removes latent, unnecessary 'guide' test.
2020-06-14 18:56:45 -07:00
Sergio Benitez 74f15a7ab5 Use top-level doc image URLs. 2020-06-11 02:30:14 -07:00
Sergio Benitez 63a4ae0485 Silence warnings on 'extern crate proc_macro'. 2020-06-08 12:25:10 -07:00
Jeb Rosen 91fb0804be Hide docs for more generated items. 2020-06-04 18:01:20 -07:00
Sergio Benitez 53353df633 Fix more broken links. 2020-03-09 02:03:38 -07:00
Sergio Benitez 95c981de79 Test all guide code examples.
Every code example is now fully runnable and testable. As a result, all
examples are now tested and include imports. Relevant imports are shown
by default. Code examples can be expanded to show all imports.

Fixes #432.
2020-02-15 04:02:19 -08:00
Sergio Benitez 9f0e02fe27 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-02-06 21:16:45 -08:00
Jacob Pratt 4e6a7ddd5f Remove use of the 'crate_visibility_modifier' feature.
Most items with 'crate' visibility become 'pub(crate)'.
Items are made 'pub' instead when they would remain private.
2019-09-21 09:16:04 -07:00
Jeb Rosen 335d8f7dbb Adjust '#[catch]' codegen output to fix a UI test regression in latest nightly. 2019-09-21 08:33:16 -07:00
Sergio Benitez 592e441de5 Use proper span in responder codegen output. 2019-09-09 21:57:10 -07:00
Sergio Benitez 0b059e06e5 Update 'devise' to 0.3.
This transitively updates 'syn', 'proc-macro2', and 'quote' to 1.0.
2019-09-05 15:44:25 -07:00
Jeb Rosen 3e4f8453ce Remove use of the 'decl_macro' feature.
Also removes one internal use in the 'typed-uris' codegen test.
2019-07-19 11:39:56 -07:00
Jeb Rosen 2f458b5217 Remove dependence on 'decl_macro' in codegen.
The generated 'uri' helper macros are now re-exports of 'macro_rules'
macros, made possible by the stable 'uniform_paths' feature.
2019-07-19 11:38:35 -07:00
Jeb Rosen be784a7845 Migrate codegen to Rust 2018. 2019-06-25 13:45:27 -04:00
Jeb Rosen 2d924f0f51 Allow 'non_snake_case' for generated query params.
Also adds '#[deny(non_snake_case)]' to the complete route generation
test for regressions.

Fixes #1003.
2019-05-29 19:18:46 -07:00
Sergio Benitez 1caf87eb21 Move to 0.5.0-dev on master. 2019-05-13 16:18:48 -07:00
Jacob Pratt 9b219ddc01 Remove stabilized feature gates.
* try_from
* transpose_result
2019-04-12 18:48:51 -07:00
Oliver Scherer c86f4312fb Always produce a valid, if conservative, subspan. 2019-02-08 18:03:53 -08:00
Sergio Benitez ca5623c641 Type encoding to fix encoding issues once and for all.
Fixes #849.
2018-12-12 17:38:36 -08:00
Sergio Benitez 5056705884 Improve query string routing and typed URI docs. 2018-12-07 12:09:15 -08:00
Sergio Benitez a4dcb0cf4c New version: 0.4.0. 2018-12-06 09:19:11 -08:00
Sergio Benitez 7fb6ba9be5 Generate 'FromUriParam' impls in 'UriDisplayPath'. 2018-12-06 09:00:01 -08:00
Sergio Benitez d7933dd6fd Implement ignorable 'uri!' expressions.
Closes #840.
2018-12-06 08:43:24 -08:00
Sergio Benitez 90a6749313 New version: 0.4.0-rc.2. 2018-11-30 21:00:18 -08:00
Sergio Benitez ac823861c8 Systematically name and span codegen variables.
Fixes #839.
2018-11-30 08:43:31 -08:00
Sergio Benitez b7db74144f Parameterize 'UriDisplay' with 'Path' or 'Query'.
This commit introduces the sealed `UriPart` marker trait as well as the
implementing `Path` and `Query` marker types, allowing for parts of a
URI to be distinguished at the type level. Consequently, `UriDisplay`
has been parameterized with `P: UriPart`, creating `UriDisplay<Path>`
and `UriDisplay<Query>`. The effect of this change is improved type
safely for URI rendering as well as the ability to omit rendering values
in query parts via `Option` and `Result`.

The `UriDisplay` derive was replaced by `UriDisplayQuery` and
`UriDisplayPath` which derive implementations for `UriDisplay<Path>`
and `UriDisplay<Query>`, respectively.

This commit also works around a rustdoc visibility issue by creating a
hidden `http::private` module.

Finally, this commit also removes the now vestigial use of the
`rustc_private` feature in codegen.

Fixes #827.
2018-11-27 10:01:47 -06:00
Sergio Benitez 543b07a4ba Use upstream 'Literal::subspan()'. 2018-11-23 19:15:13 -06:00
jeb ed4055925d Use 'dyn' in codegen to silence 'bare_trait_objects' lint. 2018-11-19 02:34:46 -08:00
Sergio Benitez 3b6c4d2a5f Prefix codegen imports to avoid name collisions.
Fixes #817.
2018-11-12 13:08:39 -08:00
Sergio Benitez 4dbd87a36f New version: 0.4.0-rc.1. 2018-10-31 14:35:30 -07:00
Sergio Benitez 16a65a9a45 Mention selective importing in 'rocket_codegen' docs. 2018-10-30 02:53:51 -07:00
jeb 328bf4b32e Support 'uri' macro in 2018 edition crates. 2018-10-30 02:44:22 -07:00
Sergio Benitez 4ef179cc59 Migrate from 'derive_utils' to published 'devise'.
Resolves #800.
2018-10-29 04:58:56 -07:00
Sergio Benitez 7090e2a1ee Use 'unreachable' to silence clippy on route codegen.
Closes #794.
2018-10-29 01:33:30 -07:00
Sergio Benitez c1b39a016b Improve 'Redirect' and 'rocket_codegen' documentation. 2018-10-28 20:17:44 -07:00
Sergio Benitez 556206e8b3 Version all URLs to 'rocket.rs'. 2018-10-26 21:20:12 -07:00
Sergio Benitez 3798cd3e65 Document and test 'UriDisplay', its derive, and 'Formatter'. 2018-10-25 02:53:04 -07:00
Divyahans Gupta cda4c520f1 Add derive for 'UriDisplay'. 2018-10-24 22:14:12 -07:00
Sergio Benitez 9ef0b731c8 Rename 'codegen_next' to 'codegen'. 2018-10-22 00:01:41 -07:00
Sergio Benitez b9bf1ee37d Fix typed URI generation for query reform. 2018-10-09 04:31:08 -07:00
Sergio Benitez 61f107f550 Reimplement route attribute as a proc-macro.
This commits also implement the query reform from #608. It also consists
of many, many breaking changes. Among them are:

  * Query parts in route paths use new query reform syntax.
  * Routing for queries is now lenient.
    - Default ranking has changed to reflect query reform.
  * Format routing matching has been fixed.
    - Routes with formats matching "accept" will always collide.
    - Routes with formats matching "content-type" require requests to
      have an equivalent content-type header to match.
    - Requests with imprecise content-types are treated as not having a
      content-type.
  * Generated routes and catchers respect visibility modifiers.
  * Raw getter methods from request were renamed and retooled.
    - In particular, the index parameter is based on segments in the
      route path, not dynamic parameters.
  * The method-based attributes no longer accept a keyed 'path'.
  * The 'rocket_codegen' crate is gone and will no longer be public.
  * The 'FormItems' iterator emits values of type 'FormItem'.
    - The internal form items' string can no longer be retrieved.
  * In general, routes are more strictly validated.
  * Logging from codegen now funnels through logging infrastructure.
  * Routing has been optimized by caching routing metadata.

Resolves #93.
Resolves #608.
Resolves #693.
Resolves #476.
2018-10-09 04:18:04 -07:00
jeb 7624aaf3e4 Reimplement 'uri!' as a proc-macro. 2018-10-03 21:56:37 -07:00
Sergio Benitez ec4cc3a293 Allow transforms in 'FromData'. Add 'FromDataSimple'.
The new 'FromData' trait allows an implementor to instruct the caller to
maintain state on its stack and later pass a borrow for processing.
Among other things, it greatly simplifies the 'Form' type, removing a
use of unsafe, and allows references in deserialized data guards.
2018-09-26 21:33:02 -07:00
Sergio Benitez 7926ffd6f0 Tidy 'routes!' and 'catchers!' proc-macros. 2018-09-16 20:38:02 -07:00
jeb 8e779610c4 Reimplement 'routes!' and 'catchers!' as proc-macros. 2018-09-16 18:52:23 -07:00
Sergio Benitez 112e700836 Reimplement 'catch' attribute as a proc-macro. 2018-09-16 01:32:40 -07:00
jeb 59e9f7fcc9 Update codegen for 2018-08-23 nightly. 2018-08-24 00:40:56 -06:00
messense 135b7d29ae Update codegen for 2018-08-14 nightly. 2018-08-14 22:01:33 -07:00
Sean Stangl 9bf585496c Apply more Clippy suggestions. 2018-08-11 23:41:35 -07:00
Sergio Benitez d7f6d82fe4 Implement 'FromForm[Value]', 'Responder' proc-macro derives.
This completes the migration of custom derives to proc-macros, removing
the need for the `custom_derive` feature in consumer code. This commit
also includes documentation, unit tests, and compile UI tests for each
of the derives.

Additionally, this commit improves the existing `FromForm` and
`FromFormValue` derives. The generated code for `FromForm` now returns
an error value indicating the error condition. The `FromFormValue`
derive now accepts a `form` attribute on variants for specifying the
exact value string to match against.

Closes #590.
Closes #670.
2018-08-06 19:58:07 -07:00
Sergio Benitez 56c6a96f6a Overhaul URI types.
This is fairly large commit with several entangled logical changes.

The primary change in this commit is to completely overhaul how URI
handling in Rocket works. Prior to this commit, the `Uri` type acted as
an origin API. Its parser was minimal and lenient, allowing URIs that
were invalid according to RFC 7230. By contrast, the new `Uri` type
brings with it a strict RFC 7230 compliant parser. The `Uri` type now
represents any kind of valid URI, not simply `Origin` types. Three new
URI types were introduced:

  * `Origin` - represents valid origin URIs
  * `Absolute` - represents valid absolute URIs
  * `Authority` - represents valid authority URIs

The `Origin` type replaces `Uri` in many cases:

  * As fields and method inputs of `Route`
  * The `&Uri` request guard is now `&Origin`
  * The `uri!` macro produces an `Origin` instead of a `Uri`

The strict nature of URI parsing cascaded into the following changes:

  * Several `Route` methods now `panic!` on invalid URIs
  * The `Rocket::mount()` method is (correctly) stricter with URIs
  * The `Redirect` constructors take a `TryInto<Uri>` type
  * Dispatching of a `LocalRequest` correctly validates URIs

Overall, URIs are now properly and uniformly handled throughout Rocket's
codebase, resulting in a more reliable and correct system.

In addition to these URI changes, the following changes are also part of
this commit:

  * The `LocalRequest::cloned_dispatch()` method was removed in favor of
    chaining `.clone().dispatch()`.
  * The entire Rocket codebase uses `crate` instead of `pub(crate)` as a
    visibility modifier.
  * Rocket uses the `crate_visibility_modifier` and `try_from` features.

A note on unsafety: this commit introduces many uses of `unsafe` in the
URI parser. All of these uses are a result of unsafely transforming byte
slices (`&[u8]` or similar) into strings (`&str`). The parser ensures
that these casts are safe, but of course, we must label their use
`unsafe`. The parser was written to be as generic and efficient as
possible and thus can parse directly from byte sources. Rocket, however,
does not make use of this fact and so would be able to remove all uses
of `unsafe` by parsing from an existing `&str`. This should be
considered in the future.

Fixes #443.
Resolves #263.
2018-07-29 00:17:33 -07:00
Sean Stangl a7cc5542ab Fix various clippy warnings in core and codegen. 2018-07-25 15:28:35 -07:00
Sergio Benitez 9c7b868371 Update codegen for 2018-07-15 nightly. 2018-07-16 14:30:20 -07:00
jeb 648eb1a5eb Prefix 'uri!' format args to allow ignored parameters. 2018-06-25 11:24:59 -07:00
jeb 5b8f8eebc6 Update codegen for 2018-06-22 nightly (2/2). 2018-06-22 23:49:22 -07:00
Sergio Benitez 69c953edc9 Update codegen for 2018-06-22 nightly (1/2). 2018-06-22 23:46:42 -07:00
Sergio Benitez df7111143e Split the 'http' module into its own 'rocket_http' crate. 2018-06-07 15:34:47 +02:00
Sergio Benitez 900e716ea6 Update to Pear 0.1. 2018-06-04 18:06:08 +02:00
Sergio Benitez f171dc9d09 Reorganize repository.
The directory structure has changed to better isolate crates serving
core and contrib. The new directory structure is:

  contrib/
    lib/ - the contrib library
  core/
    lib/ - the core Rocket library
    codegen/ - the "compile extension" codegen library
    codegen_next/ - the new proc-macro library
  examples/ - unchanged
  scripts/ - unchanged
  site/ - unchanged

This commit also removes the following files:

  appveyor.yml - AppVeyor (Rust on Windows) is far too spotty for use
  rustfmt.toml - rustfmt is, unfortunately, not mature enough for use

Finally, all example Cargo crates were marked with 'publish = false'.
2018-06-03 18:44:38 +02:00