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
a82508b403
commit
e66db09a6c
|
@ -195,9 +195,15 @@ impl<'a> FromParam<'a> for &'a str {
|
||||||
impl<'a> FromParam<'a> for String {
|
impl<'a> FromParam<'a> for String {
|
||||||
type Error = std::convert::Infallible;
|
type Error = std::convert::Infallible;
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from_param(param: &'a str) -> Result<String, Self::Error> {
|
fn from_param(param: &'a str) -> Result<String, Self::Error> {
|
||||||
// TODO: Tell the user they're being inefficient?
|
#[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());
|
||||||
|
}
|
||||||
|
|
||||||
Ok(param.to_string())
|
Ok(param.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue