On tricky problem impossible to do without unsafe blocks, is holding in a struct references to something owned by an other attribute of this struct.
However, with unsafe blocks it's quite easy, one can do something like:
struct Foo { bar: &'static str, foo: String } impl Foo { pub fn new(s: String) -> Foo { Foo { bar: unsafe { ::std::mem::transmute(&s[..]) }, foo: s } } } Here is the question: provided no method of the struct Foo previously defined gives &mut access to it (the struct will thus never be modified after creation), knowing that the data of String is heap-allocated, is this code actually safe (according to rust meaning of "safe")? If not, what are the situations where a problem may arise?