nanobot248 ,
@nanobot248@mtd.sysblog.at avatar

@became_fish in Rust, a Vec<char> is not a string, so you can't create a string_view aka &str from it. you could create a &[char] slice (via as_slice()) from it. char is more or less equivalent to u32, so Vec<char> is like Vec<u32>.

an std::String is like a utf-8 encoded Vec<u8>. so from that you can create a &[u8] with as_slice() or a &str with as_str().

if you have Vec<char> and want &str, a conversion step (e.g. copy to String) is necessary, as the whole encoding/mem-layout is different.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • test
  • worldmews
  • mews
  • All magazines