I have a struct that contains a string.
struct Foo {
s: String
}
This string gets extended with bytes that I want to pass out of Foo and give to some other code.
I can achieve this with a copy
other.s = self.s.clone();
self.s.clear();
but it jars because its clearly a waste and s might be kilobytes.
I need Foo
to own the data, temporarily, passing pointer introduces lifetime issues I don't want to have to deal with. So I would like to pass ownership of the underlying bytes.
I can also do this with an s: Option<String>
and s.take()
, temporarily s
can be null but the syntax for manipulating data in an Option is nasty, and I never really want s
to be null.