zlacker

[parent] [thread] 1 comments
1. adastr+(OP)[view] [source] 2025-08-22 16:39:29
I don’t understand this complaint. (3) sounds like exactly what you are asking for. And yes, doing unsafe thing is unsafe.
replies(1): >>maxdam+1o1
2. maxdam+1o1[view] [source] 2025-08-23 01:08:58
>>adastr+(OP)
> I don’t understand this complaint. (3) sounds like exactly what you are asking for. And yes, doing unsafe thing is unsafe

You're meant to use `unsafe` as a way of limiting the scope of reasoning about safety.

Once you construct a `&str` using `from_utf8_unchecked`, you can't safely pass it to any other function without looking at its code and reasoning about whether it's still safe.

Also see the actual documentation: https://doc.rust-lang.org/std/primitive.str.html#method.from...

> Safety: The bytes passed in must be valid UTF-8.

[go to top]