I should be able to create a str object without the std crate, right?

I think the "str" implementation is part of the "core" crate, thus I should be able to create a "str" object without using the "std" crate. However, I believe the only way to make a str object is with a static string, or std::str::from_utf8() that is from the std crate.

I am willing to even use unsafe code if that can do it. I mean I am creating a u8 slice myself that is 100% valid UTF-8, yet it is not a str slice; frustrating...

It's available in core: core::str::from_utf8

1 Like

The lib maintainers like to have everything available under std, so things in core are re-exported to std. If you find yourself on a page like this one, you can click src to see it takes you to something in core.

(Also core didn't always exist, sometimes things move from std to core, there's also alloc, etc. But AFAICT the "re-export to std" pattern is followed for all core-or-alloc-from-the-start items too.)

1 Like