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:
Sergio Benitez 2023-04-10 12:47:09 -07:00
parent 3a44b1b28e
commit c13a6c6a79
1 changed files with 7 additions and 0 deletions

View File

@ -200,8 +200,15 @@ impl<'a> FromParam<'a> for &'a str {
impl<'a> FromParam<'a> for String { impl<'a> FromParam<'a> for String {
type Error = Empty; type Error = Empty;
#[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> {
#[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() { if param.is_empty() {
return Err(Empty); return Err(Empty);
} }