top | item 26933391

(no title)

phaylon | 4 years ago

You might want to look into using `Arc<str>`. It's an immutable string slice that can have many owners and will be dropped once the last one is done with it.

discuss

order

KingOfCoders|4 years ago

Thanks, I will try that - fearing my code is littered with Arc ;-) - but sarcasm aside, thanks.

phaylon|4 years ago

I usually just have a `type Text = std::sync::Arc<str>` at the root, specifically during prototyping :)

rmdashrfstar|4 years ago

How does this differ from just sharing &str?

phaylon|4 years ago

A `&str` is a borrow of the string slice data, and has borrowing semantics. An `std::sync::Arc<str>` on the other hand isn't borrowed but has shared ownership and is atomically reference counted.

Does that answer the question? Could you expand on what you mean by sharing `&str`?