Fix all broken links. Update some outdated docs.

This commit is contained in:
Sergio Benitez 2021-03-19 18:09:13 -07:00
parent def9b4dcd2
commit b3021e2acb
21 changed files with 122 additions and 88 deletions

View File

@ -4,6 +4,8 @@ use rocket::figment;
///
/// This type is only relevant to implementors of the [`Poolable`] trait. See
/// the [`Poolable`] documentation for more information on how to use this type.
///
/// [`Poolable`]: crate::databases::Poolable
#[derive(Debug)]
pub enum Error<T> {
/// A custom error of type `T`.

View File

@ -118,7 +118,7 @@ pub enum Referrer {
NoReferrerWhenDowngrade,
/// Only send the origin of part of the URL, e.g. the origin of
/// https://foo.com/bob.html is https://foo.com
/// `https://foo.com/bob.html` is `https://foo.com`.
Origin,
/// Send full URL for same-origin requests, only send origin part when

View File

@ -27,8 +27,8 @@ use rocket::form::{self, FromFormField, ValueField};
/// UUID data and form guard: consume UUID values.
///
/// `Uuid` implements [`FromParam`] and [`FromForm`], allowing UUID values to be
/// accepted directly in paths, queries, and forms.
/// `Uuid` implements [`FromParam`] and [`FromFormField`], allowing UUID values
/// to be accepted directly in paths, queries, and forms.
///
/// # Usage
///

View File

@ -262,14 +262,14 @@ macro_rules! route_attribute {
/// 3. A macro used by [`uri!`] to type-check and generate an
/// [`Origin`].
///
/// [`Handler`]: ../rocket/trait.Handler.html
/// [`Handler`]: rocket::handler::Handler
/// [`routes!`]: macro.routes.html
/// [`uri!`]: macro.uri.html
/// [`Origin`]: ../rocket/http/uri/struct.Origin.html
/// [`Outcome`]: ../rocket/outcome/enum.Outcome.html
/// [`Response`]: ../rocket/struct.Response.html
/// [`FromRequest` Outcomes]: ../rocket/request/trait.FromRequest.html#outcomes
/// [`FromData` Outcomes]: ../rocket/data/trait.FromData.html#outcomes
/// [`Origin`]: rocket::http::uri::Origin
/// [`Outcome`]: rocket::outcome::Outcome
/// [`Response`]: rocket::Response
/// [`FromRequest` Outcomes]: rocket::request::FromRequest#outcomes
/// [`FromData` Outcomes]: rocket::data::FromData#outcomes
#[proc_macro_attribute]
pub fn $name(args: TokenStream, input: TokenStream) -> TokenStream {
emit!(attribute::route::route_attribute($method, args, input))
@ -343,13 +343,13 @@ route_attribute!(options => Method::Options);
/// name (the function's name) and status code from the route attribute or
/// `None` if `default`. The handler is set to the generated handler.
///
/// [`&Request`]: ../rocket/struct.Request.html
/// [`Status`]: ../rocket/http/struct.Status.html
/// [`ErrorHandler`]: ../rocket/type.ErrorHandler.html
/// [`&Request`]: rocket::Request
/// [`Status`]: rocket::http::Status
/// [`ErrorHandler`]: rocket::catcher::ErrorHandler
/// [`catchers!`]: macro.catchers.html
/// [`Catcher`]: ../rocket/struct.Catcher.html
/// [`Response`]: ../rocket/struct.Response.html
/// [`Responder`]: ../rocket/response/trait.Responder.html
/// [`Catcher`]: rocket::Catcher
/// [`Response`]: rocket::Response
/// [`Responder`]: rocket::Responder
#[proc_macro_attribute]
pub fn catch(args: TokenStream, input: TokenStream) -> TokenStream {
emit!(attribute::catch::catch_attribute(args, input))
@ -425,9 +425,8 @@ pub fn launch(args: TokenStream, input: TokenStream) -> TokenStream {
/// variant. In the example above, the the strings `"fourth"`, `"FOUrth"` and so
/// on would parse as `MyValue::Third`.
///
/// [`FromFormField`]: ../rocket/request/trait.FromFormField.html
/// [`FromFormField::Error`]: ../rocket/request/trait.FromFormField.html#associatedtype.Error
// FIXME(rustdoc): We should be able to refer to items in `rocket`.
/// [`FromFormField`]: rocket::form::FromFormField
/// [`FromFormField::Error`]: rocket::form::FromFormField::Error
#[proc_macro_derive(FromFormField, attributes(field))]
pub fn derive_from_form_field(input: TokenStream) -> TokenStream {
emit!(derive::from_form_field::derive_from_form_field(input))
@ -441,35 +440,43 @@ pub fn derive_from_form_field(input: TokenStream) -> TokenStream {
/// # #[macro_use] extern crate rocket;
/// #
/// #[derive(FromForm)]
/// struct MyStruct {
/// struct MyStruct<'r> {
/// field: usize,
/// other: String
/// #[field(name = "renamed_field")]
/// #[field(name = uncased("RenamedField"))]
/// other: &'r str,
/// #[field(validate = range(1..))]
/// r#type: usize,
/// }
/// ```
///
/// Each field's type is required to implement [`FromFormField`].
/// Each field's type is required to implement [`FromForm`].
///
/// The derive generates an implementation of the [`FromForm`] trait. The
/// implementation parses a form whose field names match the field names of the
/// structure on which the derive was applied. Each field's value is parsed with
/// the [`FromFormField`] implementation of the field's type. The `FromForm`
/// implementation succeeds only when all of the field parses succeed. If
/// parsing fails, an error ([`FromForm::Error`]) of type [`FormParseError`] is
/// returned.
/// the [`FromForm`] implementation of the field's type. The `FromForm`
/// implementation succeeds only when all of the field parses succeed or return
/// a default. Errors are collected into a [`form::Errors`] and return if
/// non-empty after parsing all fields.
///
/// The derive accepts one field attribute: `field`, with the following syntax:
///
/// ```text
/// field := name? validate*
///
/// name := 'name' '=' '"' IDENT '"'
/// name := 'name' '=' name_val
/// name_val := '"' FIELD_NAME '"'
/// | 'uncased(' '"' FIELD_NAME '"' ')
///
/// validate := 'validate' '=' EXPR
///
/// IDENT := valid identifier, as defined by Rust
/// FIELD_NAME := valid field name, according to the HTML5 spec
/// EXPR := valid expression, as defined by Rust
/// ```
///
/// When applied, the attribute looks as follows:
/// The attribute can be applied any number of times on a field. When applied,
/// the attribute looks as follows:
///
/// ```rust
/// # #[macro_use] extern crate rocket;
@ -478,20 +485,30 @@ pub fn derive_from_form_field(input: TokenStream) -> TokenStream {
/// struct MyStruct {
/// field: usize,
/// #[field(name = "renamed_field")]
/// #[field(name = uncased("anotherName"))]
/// #[field(validate = eq("banana"))]
/// #[field(validate = neq("orange"))]
/// other: String
/// }
/// ```
///
/// The field attribute directs that a different incoming field name is
/// expected, the value of `name`, which is used instead of the structure's
/// actual field name when parsing a form. In the example above, the value of
/// the `MyStruct::other` struct field will be parsed from the incoming form's
/// `renamed_field` field.
/// **`name`**
///
/// [`FromForm`]: ../rocket/request/trait.FromForm.html
/// [`FromFormField`]: ../rocket/request/trait.FromFormField.html
/// [`FormParseError`]: ../rocket/request/enum.FormParseError.html
/// [`FromForm::Error`]: ../rocket/request/trait.FromForm.html#associatedtype.Error
/// A `name` attribute changes the name to match against when parsing the form
/// field. The value is either an exact string to match against (`"foo"`), or
/// `uncased("foo")`, which causes the match to be case-insensitive but
/// case-preserving. When more than one `name` attribute is applied, the field
/// will match against _any_ of the names.
///
/// **`validate`**
///
/// The validation expression will be run if the field type parses successfully.
/// The expression must return a value of type `Result<(), form::Errors>`. On
/// `Err`, the errors are added to the thus-far collected errors. If more than
/// one `validate` attribute is applied, _all_ validations are run.
///
/// [`FromForm`]: rocket::form::FromForm
/// [`form::Errors`]: rocket::form::Errors
#[proc_macro_derive(FromForm, attributes(field))]
pub fn derive_from_form(input: TokenStream) -> TokenStream {
emit!(derive::from_form::derive_from_form(input))

View File

@ -45,12 +45,7 @@ use crate::uncased::UncasedStr;
/// # Usage
///
/// A `RawStr` is a dynamically sized type (just like `str`). It is always used
/// through a reference an as `&RawStr` (just like &str). You'll likely
/// encounter an `&RawStr` as a parameter via [`FromParam`] or as a form value
/// via [`FromFormValue`].
///
/// [`FromParam`]: rocket::request::FromParam
/// [`FromFormValue`]: rocket::request::FromFormValue
/// through a reference an as `&RawStr` (just like &str).
#[repr(transparent)]
#[derive(RefCast, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RawStr(str);

View File

@ -95,7 +95,7 @@ pub type ErrorHandlerFuture<'r> = BoxFuture<'r, Result<'r>>;
///
/// See the [`catch`] documentation for full details.
///
/// [`catch`]: rocket_codegen::catch
/// [`catch`]: crate::catch
/// [`Responder`]: crate::response::Responder
/// [`&Request`]: crate::request::Request
/// [`Status`]: crate::http::Status

View File

@ -46,7 +46,7 @@
//! A custom provider can be set via [`rocket::custom()`], which replaces calls to
//! [`rocket::ignite()`]. The configured provider can be built on top of
//! [`Config::figment()`], [`Config::default()`], both, or neither. The
//! [Figment](@figment) documentation has full details on instantiating existing
//! [Figment](figment) documentation has full details on instantiating existing
//! providers like [`Toml`]() and [`Env`] as well as creating custom providers for
//! more complex cases.
//!

View File

@ -66,7 +66,7 @@ pub use self::cookie::{Cookie, SameSite, Iter};
/// [`add()`], [`add_private()`], [`remove()`], and [`remove_private()`]
/// methods.
///
/// [`Request::cookies()`]: rocket::Request::cookies()
/// [`Request::cookies()`]: crate::Request::cookies()
/// [`get()`]: #method.get
/// [`get_private()`]: #method.get_private
/// [`get_pending()`]: #method.get_pending

View File

@ -47,6 +47,8 @@ use either::Either;
/// | `limits.file` | 1MiB | Default limit for all file extensions. |
/// | `limits.file/$ext` | _N/A_ | Limit for files with extension `$ext`. |
///
/// [`env::temp_dir()`]: std::env::temp_dir()
///
/// When used as a form guard, the extension `$ext` is identified by the form
/// field's `Content-Type` ([`ContentType::extension()`]). When used as a data
/// guard, the extension is identified by the Content-Type of the request, if

View File

@ -233,7 +233,7 @@ pub use self::info_kind::{Info, Kind};
///
/// Imagine that we want to record the number of `GET` and `POST` requests that
/// our application has received. While we could do this with [request guards]
/// and [managed state](crate::request::State), it would require us to annotate every
/// and [managed state](crate::State), it would require us to annotate every
/// `GET` and `POST` request with custom types, polluting handler signatures.
/// Instead, we can create a simple fairing that acts globally.
///

View File

@ -339,7 +339,8 @@ impl<'v> Errors<'v> {
/// Returns the highest [`Error::status()`] of all of the errors in `self`
/// or [`Status::InternalServerError`] if `self` is empty. This is the
/// status that is set by the [`Form`] data guard on failure.
/// status that is set by the [`Form`](crate::form::Form) data guard on
/// failure.
///
/// # Example
///

View File

@ -42,6 +42,8 @@ use crate::http::uncased::AsUncased;
/// [`FromForm`]. Form fields with the struct field's name are [shifted] and
/// then pushed to the struct field's `FromForm` parser.
///
/// [shifted]: NameView::shift()
///
/// ```rust
/// use rocket::form::FromForm;
///

View File

@ -284,7 +284,7 @@ impl<L, T: Len<L>> Len<L> for Result<'_, T> {
/// The value must implement [`Len`]. On failure, returns an [`InvalidLength`]
/// error. See [`Len`] for supported types and how their length is computed.
///
/// [`InvalidLength`]: rocket::form::error::ErrorKind::InvalidLength
/// [`InvalidLength`]: crate::form::error::ErrorKind::InvalidLength
///
/// # Data Limits
///
@ -559,7 +559,7 @@ pub fn verbose_omits<'v, V, I>(value: V, item: I) -> Result<'v, ()>
/// The value must be an integer type that implement `TryInto<isize> + Copy`. On
/// failure, returns an [`OutOfRange`] error.
///
/// [`OutOfRange`]: rocket::form::error::ErrorKind::OutOfRange
/// [`OutOfRange`]: crate::form::error::ErrorKind::OutOfRange
///
/// # Example
///
@ -609,7 +609,7 @@ pub fn range<'v, V, R>(value: &V, range: R) -> Result<'v, ()>
/// On failure, returns a [`InvalidChoice`] error with the debug representation
/// of each item in `items`.
///
/// [`InvalidChoice`]: rocket::form::error::ErrorKind::InvalidChoice
/// [`InvalidChoice`]: crate::form::error::ErrorKind::InvalidChoice
///
/// # Example
///

View File

@ -146,7 +146,7 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
///
/// _This implementation always returns successfully._
///
/// * **&[`Config`](crate::config::Config)**
/// * **&[`Config`]**
///
/// Extracts the application [`Config`].
///
@ -185,6 +185,8 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
/// returned in `Err`. If the derivation is a `Forward`, the request is
/// forwarded.
///
/// [`Config`]: crate::config::Config
///
/// # Example
///
/// Imagine you're running an authenticated API service that requires that some

View File

@ -695,9 +695,8 @@ impl<'r> Request<'r> {
}
/// Retrieves and parses into `T` the query value with field name `name`.
/// `T` must implement [`FromFormValue`], which is used to parse the query's
/// value. Key matching is performed case-sensitively. If there are multiple
/// pairs with key `key`, the _first_ one is returned.
/// `T` must implement [`FromForm`], which is used to parse the query's
/// value. Key matching is performed case-sensitively.
///
/// # Warning
///
@ -710,7 +709,7 @@ impl<'r> Request<'r> {
/// # Error
///
/// If a query segment with name `name` isn't present, returns `None`. If
/// parsing the value fails, returns `Some(Err(T:Error))`.
/// parsing the value fails, returns `Some(Err(_))`.
///
/// # Example
///

View File

@ -1,3 +1,5 @@
//! Routing types: [`Route`] and [`RouteUri`].
mod collider;
mod route;
mod segment;

View File

@ -52,6 +52,7 @@ use crate::router::segment::Segment;
/// ```
///
/// [`Rocket::mount()`]: crate::Rocket::mount()
/// [`Route::new()`]: crate::Route::new()
#[derive(Clone)]
pub struct RouteUri<'a> {
/// The source string for this URI.

View File

@ -935,7 +935,7 @@ struct MyForm<'v> {
# rocket_guide_tests::assert_form_parses_ok!(MyForm, "");
```
[`Errors<'_>`]: @api/rocket/forms/struct.Errors.html
[`Errors<'_>`]: @api/rocket/form/struct.Errors.html
### Collections

View File

@ -278,7 +278,6 @@ library. Among these are:
* [`Json`] - Automatically serializes values into JSON.
* [`MsgPack`] - Automatically serializes values into MessagePack.
* [`Template`] - Renders a dynamic template using handlebars or Tera.
* [`Compress`] - Compresses a response at the HTTP layer.
[`status`]: @api/rocket/response/status/
[`response`]: @api/rocket/response/
@ -288,7 +287,6 @@ library. Among these are:
[`Stream`]: @api/rocket/response/struct.Stream.html
[`Flash`]: @api/rocket/response/struct.Flash.html
[`MsgPack`]: @api/rocket_contrib/msgpack/struct.MsgPack.html
[`Compress`]: @api/rocket_contrib/compression/struct.Compress.html
### Streaming

View File

@ -50,33 +50,32 @@ instance. Usage is straightforward:
```
[`local`]: @api/rocket/local/
[`Client`]: @api/rocket/local/struct.Client.html
[`LocalRequest`]: @api/rocket/local/struct.LocalRequest.html
[`Client`]: @api/rocket/local/#client
[`LocalRequest`]: @api/rocket/local/#localrequest
[`Rocket`]: @api/rocket/struct.Rocket.html
## Validating Responses
A `dispatch` of a `LocalRequest` returns a [`LocalResponse`] which can be used
transparently as a [`Response`] value. During testing, the response is usually
validated against expected properties. These includes things like the response
HTTP status, the inclusion of headers, and expected body data.
A `dispatch` of a `LocalRequest` returns a [`LocalResponse`] which can be
inspected for validaty. During testing, the response is usually validated
against expected properties. These includes things like the response HTTP
status, the inclusion of headers, and expected body data.
The [`Response`] type provides methods to ease this sort of validation. We list
[`LocalResponse`] type provides methods to ease this sort of validation. We list
a few below:
* [`status`]: returns the HTTP status in the response.
* [`content_type`]: returns the Content-Type header in the response.
* [`headers`]: returns a map of all of the headers in the response.
* [`body_string`]: returns the body data as a `String`.
* [`body_bytes`]: returns the body data as a `Vec<u8>`.
* [`into_string`]: reads the body data into a `String`.
* [`into_bytes`]: reads the body data into a `Vec<u8>`.
[`LocalResponse`]: @api/rocket/local/struct.LocalResponse.html
[`Response`]: @api/rocket/struct.Response.html
[`status`]: @api/rocket/struct.Response.html#method.status
[`content_type`]: @api/rocket/struct.Response.html#method.content_type
[`headers`]: @api/rocket/struct.Response.html#method.headers
[`body_string`]: @api/rocket/struct.Response.html#method.body_string
[`body_bytes`]: @api/rocket/struct.Response.html#method.body_bytes
[`LocalResponse`]: @api/rocket/local/blocking/struct.LocalResponse.html
[`status`]: @api/rocket/local/blocking/struct.LocalResponse.html#method.status
[`content_type`]: @api/rocket/local/blocking/struct.LocalResponse.html#method.content_type
[`headers`]: @api/rocket/local/blocking/struct.LocalResponse.html#method.headers
[`into_string`]: @api/rocket/local/blocking/struct.LocalResponse.html#method.into_string
[`into_bytes`]: @api/rocket/local/blocking/struct.LocalResponse.html#method.into_bytes
These methods are typically used in combination with the `assert_eq!` or
`assert!` macros as follows:
@ -283,18 +282,32 @@ During compilation, you should see output like:
```rust,ignore
note: emitting Rocket code generation debug output
--> examples/hello_world/src/main.rs:7:1
|
7 | #[get("/")]
| ^^^^^^^^^^^
|
= note:
fn rocket_route_fn_hello<'_b>(
__req: &'_b ::rocket::Request,
__data: ::rocket::Data
) -> ::rocket::handler::Outcome<'_b> {
let responder = hello();
::rocket::handler::Outcome::from(__req, responder)
--> examples/hello_world/src/main.rs:14:1
|
14 | #[get("/world")]
| ^^^^^^^^^^^^^^^^
|
= note:
impl From<world> for rocket::StaticRouteInfo {
fn from(_: world) -> rocket::StaticRouteInfo {
fn monomorphized_function<'_b>(
__req: &'_b rocket::request::Request<'_>,
__data: rocket::data::Data,
) -> rocket::handler::HandlerFuture<'_b> {
::std::boxed::Box::pin(async move {
let ___responder = world();
rocket::handler::Outcome::from(__req, ___responder)
})
}
rocket::StaticRouteInfo {
name: "world",
method: ::rocket::http::Method::Get,
path: "/world",
handler: monomorphized_function,
format: ::std::option::Option::None,
rank: ::std::option::Option::None,
}
}
}
```

View File

@ -53,7 +53,7 @@ selected profile doesn't contain a requested values, while values in the
[`Provider`]: @figment/trait.Provider.html
[`Profile`]: @figment/struct.Profile.html
[`Config`]: @api/rocket/struct.Config.html
[`Config::figment()`]: @api/struct.Config.html#method.figment
[`Config::figment()`]: @api/rocket/struct.Config.html#method.figment
[`Toml`]: @figment/providers/struct.Toml.html
[`Json`]: @figment/providers/struct.Json.html
[`Figment`]: @api/rocket/struct.Figment.html