mirror of https://github.com/rwf2/Rocket.git
Emit warning when 'String' is used as a parameter.
The warning is only emitted when Rocket is compiled in debug.
This commit is contained in:
parent
3a44b1b28e
commit
c13a6c6a79
|
@ -200,8 +200,15 @@ impl<'a> FromParam<'a> for &'a str {
|
|||
impl<'a> FromParam<'a> for String {
|
||||
type Error = Empty;
|
||||
|
||||
#[track_caller]
|
||||
#[inline(always)]
|
||||
fn from_param(param: &'a str) -> Result<String, Self::Error> {
|
||||
#[cfg(debug_assertions)] {
|
||||
let loc = std::panic::Location::caller();
|
||||
warn_!("Note: Using `String` as a parameter type is inefficient. Use `&str` instead.");
|
||||
info_!("`String` is used a parameter guard in {}:{}.", loc.file(), loc.line());
|
||||
}
|
||||
|
||||
if param.is_empty() {
|
||||
return Err(Empty);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue