mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 04:52:28 +00:00
there is no need to force people to take &State arg
this highly improves async compatibility
This commit is contained in:
parent
cd7cf07318
commit
a36993f615
1 changed files with 10 additions and 10 deletions
|
@ -175,12 +175,20 @@ impl Spanned for MethodArgument
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interpret_arg_ty(index : usize, attrs : &[Attribute], name : &str, ty : Type) -> Result<MethodArgumentType, Error>
|
fn interpret_arg_ty(attrs : &[Attribute], name : &str, ty : Type) -> Result<MethodArgumentType, Error>
|
||||||
{
|
{
|
||||||
let attr = attrs.iter()
|
let attr = attrs.iter()
|
||||||
.find(|arg| arg.path.segments.iter().any(|path| &path.ident.to_string() == "rest_arg"))
|
.find(|arg| arg.path.segments.iter().any(|path| &path.ident.to_string() == "rest_arg"))
|
||||||
.map(|arg| arg.tokens.to_string());
|
.map(|arg| arg.tokens.to_string());
|
||||||
|
|
||||||
|
if attr.as_deref() == Some("state") || (attr.is_none() && name == "state")
|
||||||
|
{
|
||||||
|
return match ty {
|
||||||
|
Type::Reference(ty) => Ok(if ty.mutability.is_none() { MethodArgumentType::StateRef } else { MethodArgumentType::StateMutRef }),
|
||||||
|
_ => Err(Error::new(ty.span(), "The state parameter has to be a (mutable) reference to gotham_restful::State"))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if cfg!(feature = "auth") && (attr.as_deref() == Some("auth") || (attr.is_none() && name == "auth"))
|
if cfg!(feature = "auth") && (attr.as_deref() == Some("auth") || (attr.is_none() && name == "auth"))
|
||||||
{
|
{
|
||||||
return Ok(match ty {
|
return Ok(match ty {
|
||||||
|
@ -197,14 +205,6 @@ fn interpret_arg_ty(index : usize, attrs : &[Attribute], name : &str, ty : Type)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if index == 0
|
|
||||||
{
|
|
||||||
return match ty {
|
|
||||||
Type::Reference(ty) => Ok(if ty.mutability.is_none() { MethodArgumentType::StateRef } else { MethodArgumentType::StateMutRef }),
|
|
||||||
_ => Err(Error::new(ty.span(), "The first argument, unless some feature is used, has to be a (mutable) reference to gotham::state::State"))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(MethodArgumentType::MethodArg(ty))
|
Ok(MethodArgumentType::MethodArg(ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ fn interpret_arg(index : usize, arg : &PatType) -> Result<MethodArgument, Error>
|
||||||
let pat = &arg.pat;
|
let pat = &arg.pat;
|
||||||
let ident = format_ident!("arg{}", index);
|
let ident = format_ident!("arg{}", index);
|
||||||
let orig_name = quote!(#pat);
|
let orig_name = quote!(#pat);
|
||||||
let ty = interpret_arg_ty(index, &arg.attrs, &orig_name.to_string(), *arg.ty.clone())?;
|
let ty = interpret_arg_ty(&arg.attrs, &orig_name.to_string(), *arg.ty.clone())?;
|
||||||
|
|
||||||
Ok(MethodArgument { ident, ident_span: arg.pat.span(), ty })
|
Ok(MethodArgument { ident, ident_span: arg.pat.span(), ty })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue