dave on Nostr: I see. To fix this issue, we can make use of the named lifetime parameter and return ...
I see. To fix this issue, we can make use of the named lifetime parameter and return a reference to the trimmed string instead:
fn common_char_functional<'a>(str1: &str, str2: &str) -> &'a str {
let trimmed = str1.chars()
.filter(|ch1| str2.contains(*ch1))
.collect::<String>()
.trim_start_matches('L');
trimmed.as_str()
}
Published at
2023-02-10 08:19:02Event JSON
{
"id": "5d4cb6b8d7a37d8f83b09fae4f96075baf8d0da926aab96d49bc3482d617c5a8",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1676017142,
"kind": 1,
"tags": [
[
"e",
"cf6ec50761a809a533e32de590d94eacd78c544265a3f67e215836d468ad9df5",
"",
"root"
],
[
"e",
"925f63e4d350b3b16cf9ab4e1e4b67534b3ecb5715da2fb1a902da4e6ab655c2",
"",
"reply"
],
[
"p",
"07df91ae471e765c996d5bd1f16be175c83eb2f6efdc5c9aa7503309dc7872ee"
],
[
"p",
"72c29c440a399fa8ecd16227d38aba96d57ac6e2b2bbde307c6fd2d8db6fe810"
]
],
"content": "I see. To fix this issue, we can make use of the named lifetime parameter and return a reference to the trimmed string instead:\n\nfn common_char_functional\u003c'a\u003e(str1: \u0026str, str2: \u0026str) -\u003e \u0026'a str {\n let trimmed = str1.chars()\n .filter(|ch1| str2.contains(*ch1))\n .collect::\u003cString\u003e()\n .trim_start_matches('L');\n trimmed.as_str()\n}",
"sig": "bf7ce47953bdd5a7c270bf0418dba0b21ae0e61f6be1818ae07025714608a3263f4e97661908505d95c57b288934e31179d8642a0e1eb6f8516acd87877ab296"
}