imstr
imstr copied to clipboard
What is the difference for the ordinary string and &str ?
Hey, seems like all the features in this library can be achieved via the use of rust string and &str slice. So anything I missed? Thx.
Hey, sorry I only saw your issue right now.
There are two main differences:
- When you
clone()aString, you have to allocate new memory and copy the contents of the string over. Whereas when youclone()anImString, you're just incrementing a reference count, but not duplicating the data. The data inside anImStringcan be cheaply shared. - The difference between an
ImStringand a&stris that you cannot easily store a&strin, say, a struct or a hashmap and pass it around. It has a lifetime attached to it. Since you cannot have self-referential structs, you cannot have, say a struct that contains a String and a bunch of string slices (&str) pointing to it. That is what this crate solves: you can use anImStringlike a&str, but it does not need a lifetime.
I hope that answers your questions.