mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
default to Params::get() giving an owned value (which you want in a derived signal), but use reference in the macro
This commit is contained in:
parent
242d35cc37
commit
1766bfedb9
2 changed files with 11 additions and 3 deletions
|
@ -20,7 +20,7 @@ pub fn params_impl(ast: &syn::DeriveInput) -> proc_macro::TokenStream {
|
|||
|
||||
quote_spanned! {
|
||||
span=> #ident: <#ty as ::leptos_router::params::IntoParam>::into_param(
|
||||
map.get(#field_name_string),
|
||||
map.get_str(#field_name_string),
|
||||
#field_name_string
|
||||
)?
|
||||
}
|
||||
|
|
|
@ -27,9 +27,17 @@ impl ParamsMap {
|
|||
}
|
||||
*/
|
||||
|
||||
/// Gets a value from the map.
|
||||
/// Gets an owned value from the map.
|
||||
#[inline(always)]
|
||||
pub fn get(&self, key: &str) -> Option<&str> {
|
||||
pub fn get(&self, key: &str) -> Option<String> {
|
||||
self.0
|
||||
.iter()
|
||||
.find_map(|(k, v)| (k == key).then_some(v.to_owned()))
|
||||
}
|
||||
|
||||
/// Gets a referenc to a value from the map.
|
||||
#[inline(always)]
|
||||
pub fn get_str(&self, key: &str) -> Option<&str> {
|
||||
self.0
|
||||
.iter()
|
||||
.find_map(|(k, v)| (k == key).then_some(v.as_str()))
|
||||
|
|
Loading…
Reference in a new issue