I'm trying use a String Cell in my project but I am having trouble with the get method. Also I don't know enough about Cell's. Should the functions use String or &str's?
Using the Rust Playground this example says the following trait bounds were not satisfied: String: Copy
In general: The most useful thing you can do on a Cell with a non-Copy type is to swap the value. E.g. use the take method to replace the string in the cell with an empty one temporarily, access the taken-out string, and use set to put back the (potentially modified) String.
Your concrete method can this be re-written as
pub fn title(&self) -> String {
let title = self.cell.take();
let title_cloned = title.clone();
self.cell.set(title); // put back title
title_cloned // return the clone
}
Obviously, this clones the string, which might be somewhat expensive. RefCell is more powerful than Cell (but has a small overhead, and can result in panics if you use it wrong). With RefCell you couldn't make your API as it is "more efficient" either, but it would probably be more ergonomic to use than the whole take+put dance.