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

Replace methods with more flexible endpoints

This commit is contained in:
msrd0 2021-01-18 00:05:30 +00:00
parent 0ac0f0f504
commit b807ae2796
87 changed files with 1497 additions and 1512 deletions

View file

@ -0,0 +1,12 @@
#[macro_use]
extern crate gotham_restful;
use gotham_restful::State;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all]
async fn read_all(state: &State) {}
fn main() {}

View file

@ -0,0 +1,5 @@
error: Endpoint handler functions that are async must not take `&State` as an argument, consider taking `&mut State`
--> $DIR/async_state.rs:10:19
|
10 | async fn read_all(state: &State) {}
| ^^^^^

View file

@ -1,14 +1,11 @@
#[macro_use] extern crate gotham_restful;
#[macro_use]
extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all(FooResource)]
fn read_all(self)
{
}
fn read_all() {}
fn main()
{
}
fn main() {}

View file

@ -0,0 +1,11 @@
error: Invalid attribute syntax
--> $DIR/invalid_attribute.rs:8:12
|
8 | #[read_all(FooResource)]
| ^^^^^^^^^^^
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
--> $DIR/invalid_attribute.rs:5:12
|
5 | #[resource(read_all)]
| ^^^^^^^^ not found in this scope

View file

@ -1,14 +1,11 @@
#[macro_use] extern crate gotham_restful;
#[macro_use]
extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all]
fn read_all()
{
}
fn read_all(self) {}
fn main()
{
}
fn main() {}

View file

@ -0,0 +1,19 @@
error: Didn't expect self parameter
--> $DIR/self.rs:9:13
|
9 | fn read_all(self) {}
| ^^^^
error: `self` parameter is only allowed in associated functions
--> $DIR/self.rs:9:13
|
9 | fn read_all(self) {}
| ^^^^ not semantically valid as function parameter
|
= note: associated functions are those in `impl` or `trait` definitions
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
--> $DIR/self.rs:5:12
|
5 | #[resource(read_all)]
| ^^^^^^^^ not found in this scope

View file

@ -0,0 +1,11 @@
#[macro_use]
extern crate gotham_restful;
#[derive(Resource)]
#[resource(read)]
struct FooResource;
#[read]
fn read() {}
fn main() {}

View file

@ -0,0 +1,11 @@
error: Too few arguments
--> $DIR/too_few_args.rs:9:4
|
9 | fn read() {}
| ^^^^
error[E0412]: cannot find type `read___gotham_restful_endpoint` in this scope
--> $DIR/too_few_args.rs:5:12
|
5 | #[resource(read)]
| ^^^^ not found in this scope

View file

@ -0,0 +1,11 @@
#[macro_use]
extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all]
fn read_all(_id: u64) {}
fn main() {}

View file

@ -0,0 +1,11 @@
error: Too many arguments
--> $DIR/too_many_args.rs:9:4
|
9 | fn read_all(_id: u64) {}
| ^^^^^^^^
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
--> $DIR/too_many_args.rs:5:12
|
5 | #[resource(read_all)]
| ^^^^^^^^ not found in this scope

View file

@ -0,0 +1,11 @@
#[macro_use]
extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all(pineapple = "on pizza")]
fn read_all() {}
fn main() {}

View file

@ -0,0 +1,11 @@
error: Unknown attribute
--> $DIR/unknown_attribute.rs:8:12
|
8 | #[read_all(pineapple = "on pizza")]
| ^^^^^^^^^
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
--> $DIR/unknown_attribute.rs:5:12
|
5 | #[resource(read_all)]
| ^^^^^^^^ not found in this scope

View file

@ -0,0 +1,11 @@
#[macro_use]
extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all]
unsafe fn read_all() {}
fn main() {}

View file

@ -0,0 +1,11 @@
error: Endpoint handler methods must not be unsafe
--> $DIR/unsafe.rs:9:1
|
9 | unsafe fn read_all() {}
| ^^^^^^
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
--> $DIR/unsafe.rs:5:12
|
5 | #[resource(read_all)]
| ^^^^^^^^ not found in this scope

View file

@ -0,0 +1,10 @@
#[macro_use]
extern crate gotham_restful;
#[derive(FromBody)]
enum FromBodyEnum {
SomeVariant(Vec<u8>),
OtherVariant(String)
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: #[derive(FromBody)] only works for structs
--> $DIR/from_body_enum.rs:4:1
--> $DIR/enum.rs:5:1
|
4 | enum FromBodyEnum
5 | enum FromBodyEnum {
| ^^^^

View file

@ -1,12 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(FromBody)]
enum FromBodyEnum
{
SomeVariant(Vec<u8>),
OtherVariant(String)
}
fn main()
{
}

View file

@ -1,15 +0,0 @@
#[macro_use] extern crate gotham_restful;
use gotham_restful::State;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all(FooResource)]
async fn read_all(state : &State)
{
}
fn main()
{
}

View file

@ -1,5 +0,0 @@
error: async fn must not take &State as an argument as State is not Sync, consider taking &mut State
--> $DIR/method_async_state.rs:9:19
|
9 | async fn read_all(state : &State)
| ^^^^^

View file

@ -1,10 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[read_all(UnknownResource)]
fn read_all()
{
}
fn main()
{
}

View file

@ -1,5 +0,0 @@
error[E0412]: cannot find type `UnknownResource` in this scope
--> $DIR/method_for_unknown_resource.rs:3:12
|
3 | #[read_all(UnknownResource)]
| ^^^^^^^^^^^^^^^ not found in this scope

View file

@ -1,15 +0,0 @@
error: Missing Resource struct. Example: #[read_all(MyResource)]
--> $DIR/method_no_resource.rs:7:1
|
7 | #[read_all]
| ^^^^^^^^^^^
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find function `_gotham_restful_foo_resource_read_all_setup_impl` in this scope
--> $DIR/method_no_resource.rs:3:10
|
3 | #[derive(Resource)]
| ^^^^^^^^ not found in this scope
|
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -1,13 +0,0 @@
error: Didn't expect self parameter
--> $DIR/method_self.rs:8:13
|
8 | fn read_all(self)
| ^^^^
error: `self` parameter is only allowed in associated functions
--> $DIR/method_self.rs:8:13
|
8 | fn read_all(self)
| ^^^^ not semantically valid as function parameter
|
= note: associated functions are those in `impl` or `trait` definitions

View file

@ -1,14 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(Resource)]
#[resource(read)]
struct FooResource;
#[read(FooResource)]
fn read()
{
}
fn main()
{
}

View file

@ -1,5 +0,0 @@
error: Too few arguments
--> $DIR/method_too_few_args.rs:8:4
|
8 | fn read()
| ^^^^

View file

@ -1,14 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all(FooResource)]
fn read_all(_id : u64)
{
}
fn main()
{
}

View file

@ -1,5 +0,0 @@
error: Too many arguments
--> $DIR/method_too_many_args.rs:8:13
|
8 | fn read_all(_id : u64)
| ^^^

View file

@ -1,14 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_all)]
struct FooResource;
#[read_all(FooResource)]
unsafe fn read_all()
{
}
fn main()
{
}

View file

@ -1,5 +0,0 @@
error: Resource methods must not be unsafe
--> $DIR/method_unsafe.rs:8:1
|
8 | unsafe fn read_all()
| ^^^^^^

View file

@ -0,0 +1,12 @@
#[macro_use]
extern crate gotham_restful;
#[derive(OpenapiType)]
enum Food {
Pasta,
Pizza { pineapple: bool },
Rice,
Other(String)
}
fn main() {}

View file

@ -1,11 +1,11 @@
error: #[derive(OpenapiType)] does not support enum variants with fields
--> $DIR/openapi_type_enum_with_fields.rs:7:2
--> $DIR/enum_with_fields.rs:7:2
|
7 | Pizza { pineapple : bool },
7 | Pizza { pineapple: bool },
| ^^^^^
error: #[derive(OpenapiType)] does not support enum variants with fields
--> $DIR/openapi_type_enum_with_fields.rs:9:2
--> $DIR/enum_with_fields.rs:9:2
|
9 | Other(String)
| ^^^^^

View file

@ -0,0 +1,10 @@
#[macro_use]
extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo {
#[openapi(nullable = "yes, please")]
bar: String
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: Expected bool
--> $DIR/openapi_type_nullable_non_bool.rs:6:23
--> $DIR/nullable_non_bool.rs:6:23
|
6 | #[openapi(nullable = "yes, please")]
| ^^^^^^^^^^^^^

View file

@ -0,0 +1,10 @@
#[macro_use]
extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo {
#[openapi(rename = 42)]
bar: String
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: Expected string literal
--> $DIR/openapi_type_rename_non_string.rs:6:21
--> $DIR/rename_non_string.rs:6:21
|
6 | #[openapi(rename = 42)]
| ^^

View file

@ -0,0 +1,7 @@
#[macro_use]
extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo(String);
fn main() {}

View file

@ -1,5 +1,5 @@
error: #[derive(OpenapiType)] does not support unnamed fields
--> $DIR/openapi_type_tuple_struct.rs:4:11
--> $DIR/tuple_struct.rs:5:11
|
4 | struct Foo(String);
5 | struct Foo(String);
| ^^^^^^^^

View file

@ -0,0 +1,10 @@
#[macro_use]
extern crate gotham_restful;
#[derive(OpenapiType)]
union IntOrPointer {
int: u64,
pointer: *mut String
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: #[derive(OpenapiType)] only works for structs and enums
--> $DIR/openapi_type_union.rs:4:1
--> $DIR/union.rs:5:1
|
4 | union IntOrPointer
5 | union IntOrPointer {
| ^^^^^

View file

@ -0,0 +1,10 @@
#[macro_use]
extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo {
#[openapi(like = "pizza")]
bar: String
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: Unknown key
--> $DIR/openapi_type_unknown_key.rs:6:12
--> $DIR/unknown_key.rs:6:12
|
6 | #[openapi(like = "pizza")]
| ^^^^

View file

@ -1,14 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
enum Food
{
Pasta,
Pizza { pineapple : bool },
Rice,
Other(String)
}
fn main()
{
}

View file

@ -1,12 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo
{
#[openapi(nullable = "yes, please")]
bar : String
}
fn main()
{
}

View file

@ -1,12 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo
{
#[openapi(rename = 42)]
bar : String
}
fn main()
{
}

View file

@ -1,8 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo(String);
fn main()
{
}

View file

@ -1,12 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
union IntOrPointer
{
int: u64,
pointer: *mut String
}
fn main()
{
}

View file

@ -1,12 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo
{
#[openapi(like = "pizza")]
bar : String
}
fn main()
{
}

View file

@ -0,0 +1,11 @@
#[macro_use]
extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_any)]
struct FooResource;
#[read_all]
fn read_all() {}
fn main() {}

View file

@ -0,0 +1,8 @@
error[E0412]: cannot find type `read_any___gotham_restful_endpoint` in this scope
--> $DIR/unknown_method.rs:5:12
|
5 | #[resource(read_any)]
| ^^^^^^^^ help: a struct with a similar name exists: `read_all___gotham_restful_endpoint`
...
8 | #[read_all]
| ----------- similarly named struct `read_all___gotham_restful_endpoint` defined here

View file

@ -1,14 +0,0 @@
#[macro_use] extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_any)]
struct FooResource;
#[read_all(FooResource)]
fn read_all()
{
}
fn main()
{
}

View file

@ -1,14 +0,0 @@
error: Unknown method: `read_any'
--> $DIR/resource_unknown_method.rs:4:12
|
4 | #[resource(read_any)]
| ^^^^^^^^
error[E0277]: the trait bound `FooResource: Resource` is not satisfied
--> $DIR/resource_unknown_method.rs:7:1
|
7 | #[read_all(FooResource)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Resource` is not implemented for `FooResource`
|
= help: see issue #48214
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

15
tests/ui/rustfmt.sh Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
set -euo pipefail
rustfmt=${RUSTFMT:-rustfmt}
version="$($rustfmt -V)"
if [[ $version != *nightly* ]]; then
rustfmt="$rustfmt +nightly"
fi
return=0
find "$(dirname "$0")" -name '*.rs' -type f | while read file; do
$rustfmt --config-path "$(dirname "$0")/../../rustfmt.toml" "$@" "$file" || return=1
done
exit $return