1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00

docs: use [Type] syntax from rust 1.48

This commit is contained in:
Dominic 2020-11-22 23:55:52 +01:00
parent ed1bbbd1fb
commit 4ae860dd32
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
11 changed files with 71 additions and 70 deletions

View file

@ -20,18 +20,21 @@ impl<T: OpenapiType> ResourceType for T {}
/// A type that can be used inside a response body. Implemented for every type that is
/// serializable with serde. If the `openapi` feature is used, it must also be of type
/// `OpenapiType`.
/// [OpenapiType].
///
/// [OpenapiType]: trait.OpenapiType.html
pub trait ResponseBody: ResourceType + Serialize {}
impl<T: ResourceType + Serialize> ResponseBody for T {}
/**
This trait should be implemented for every type that can be built from an HTTP request body
plus its media type. For most use cases it is sufficient to derive this trait, you usually
don't need to manually implement this. Therefore, make sure that the first variable of
your struct can be built from [`Bytes`], and the second one can be build from [`Mime`].
If you have any additional variables, they need to be `Default`. This is an example of
such a struct:
plus its media type.
For most use cases it is sufficient to derive this trait, you usually don't need to manually
implement this. Therefore, make sure that the first variable of your struct can be built from
[Bytes], and the second one can be build from [Mime]. If you have any additional variables, they
need to be [Default]. This is an example of such a struct:
```rust
# #[macro_use] extern crate gotham_restful;
@ -43,14 +46,11 @@ struct RawImage {
content_type: Mime
}
```
[`Bytes`]: ../bytes/struct.Bytes.html
[`Mime`]: ../mime/struct.Mime.html
*/
pub trait FromBody: Sized {
/// The error type returned by the conversion if it was unsuccessfull. When using the derive
/// macro, there is no way to trigger an error, so `Infallible` is used here. However, this
/// might change in the future.
/// macro, there is no way to trigger an error, so [std::convert::Infallible] is used here.
/// However, this might change in the future.
type Err: Error;
/// Perform the conversion.
@ -67,11 +67,11 @@ impl<T: DeserializeOwned> FromBody for T {
/**
A type that can be used inside a request body. Implemented for every type that is deserializable
with serde. If the `openapi` feature is used, it must also be of type [`OpenapiType`].
with serde. If the `openapi` feature is used, it must also be of type [OpenapiType].
If you want a non-deserializable type to be used as a request body, e.g. because you'd like to
get the raw data, you can derive it for your own type. All you need is to have a type implementing
[`FromBody`] and optionally a list of supported media types:
[FromBody] and optionally a list of supported media types:
```rust
# #[macro_use] extern crate gotham_restful;
@ -84,8 +84,7 @@ struct RawImage {
}
```
[`FromBody`]: trait.FromBody.html
[`OpenapiType`]: trait.OpenapiType.html
[OpenapiType]: trait.OpenapiType.html
*/
pub trait RequestBody: ResourceType + FromBody {
/// Return all types that are supported as content types. Use `None` if all types are supported.
@ -102,7 +101,9 @@ impl<T: ResourceType + DeserializeOwned> RequestBody for T {
/// A type than can be used as a parameter to a resource method. Implemented for every type
/// that is deserialize and thread-safe. If the `openapi` feature is used, it must also be of
/// type `OpenapiType`.
/// type [OpenapiType].
///
/// [OpenapiType]: trait.OpenapiType.html
pub trait ResourceID: ResourceType + DeserializeOwned + Clone + RefUnwindSafe + Send + Sync {}
impl<T: ResourceType + DeserializeOwned + Clone + RefUnwindSafe + Send + Sync> ResourceID for T {}