mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-25 03:42:35 +00:00
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 {
|
||||
type Error = std::convert::Infallible;
|
||||
|
||||
#[track_caller]
|
||||
#[inline(always)]
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user