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

allow deriving enums

This commit is contained in:
Dominic 2019-10-03 00:04:33 +02:00
parent 0b11aaf1f9
commit 50ed2411c9
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
3 changed files with 73 additions and 12 deletions

View file

@ -26,8 +26,17 @@ rest_resource!{Users, route => {
}}
#[derive(Deserialize, OpenapiType, Serialize)]
struct User {
username : String
enum TestEnum
{
Foo,
Bar
}
#[derive(Deserialize, OpenapiType, Serialize)]
struct User
{
username : String,
test : Option<TestEnum>
}
impl ResourceReadAll<Success<Vec<Option<User>>>> for Users
@ -36,7 +45,7 @@ impl ResourceReadAll<Success<Vec<Option<User>>>> for Users
{
vec![Username().fake(), Username().fake()]
.into_iter()
.map(|username| Some(User { username }))
.map(|username| Some(User { username, test: None }))
.collect::<Vec<Option<User>>>()
.into()
}
@ -47,7 +56,7 @@ impl ResourceRead<u64, Success<User>> for Users
fn read(_state : &mut State, id : u64) -> Success<User>
{
let username : String = Username().fake();
User { username: format!("{}{}", username, id) }.into()
User { username: format!("{}{}", username, id), test: None }.into()
}
}