Shane Celis on Nostr: So in #rust characters in strings can't be accessed via index because they're proper ...
So in #rust characters in strings can't be accessed via index because they're proper utf8 blah blah blah. So I have some code where I check the last character `string.chars().last() == ‘\n’` and I've been fretting, thinking it's O(n) and that I should stick that newline at the beginning of the next string in my sequence because `string.chars().next() == ‘\n’` is O(1). But it turns out chars().last() is O(1) too. Fancy that.
https://doc.rust-lang.org/std/str/struct.Chars.html Published at
2023-12-08 00:13:45Event JSON
{
"id": "e13720574d7b1da9d23bddb69f2d674c30f34558a65bb494df60ec6eaf57ef32",
"pubkey": "f93e59dd814c9044fb46ce81b53227818c9589e4797d801f439f84dac9619b7b",
"created_at": 1701994425,
"kind": 1,
"tags": [
[
"t",
"rust"
],
[
"proxy",
"https://mastodon.gamedev.place/users/shanecelis/statuses/111541906672550375",
"activitypub"
]
],
"content": "So in #rust characters in strings can't be accessed via index because they're proper utf8 blah blah blah. So I have some code where I check the last character `string.chars().last() == ‘\\n’` and I've been fretting, thinking it's O(n) and that I should stick that newline at the beginning of the next string in my sequence because `string.chars().next() == ‘\\n’` is O(1). But it turns out chars().last() is O(1) too. Fancy that.\n\nhttps://doc.rust-lang.org/std/str/struct.Chars.html\n\nhttps://cdn.masto.host/mastodongamedevplace/media_attachments/files/111/541/906/402/189/221/original/fa6cf280c2f2997d.png",
"sig": "0442bb7a103b19efa9b097e990f3fbcb39b1730594ff95bc738fe0a842bd6922a0dcf6bdc5532f6ed4a36231a7a21658b77cd10b31d85024de72eb67db34b153"
}