Deprecate unsafe functions in `str::raw` and remove `OwnedStr` trait

### Removed the `OwnedStr` trait

This trait was only implemented by `String`. It provided the methods `into_bytes` and `append`, both of which **are already implemented as normal methods** of `String` (they were duplicated). This change improves the consistency of strings.

Its removal shouldn't break any code, except if somebody has implemented `OwnedStr` for his own types.

### Deprecated some unsafe functions

* `from_c_str` in favor of `String::from_c_str`
* `from_utf8_owned` in favor of `String::from_bytes` (we could give it another name if you have a better one, for example `String::from_utf8_unchecked`)
* `from_byte` in favor of `String::from_bytes` (make a new vector with a single byte and call the function)

### Questions

I would like to deprecate `from_buf_len` as well. This way we would get rid of `str::raw` completely.

After thinking about it, it seems to me that `from_buf_len` addresses a problem that is not related to strings. What the user really wants is to build a `String` from a slice (or vector) of bytes. This can be done by calling `String::from_bytes` (without checking for UTF-8-ness) or `String::from_utf8` (checking). However, there is no easy way to convert a pointer to a slice, so the user will call `from_buf_len` with the raw pointer and its length as arguments. I think the real solution would be to add a new method to the `RawPtr` trait. Something like:

```
// I don't know if this would compile. It is just an example
unsafe fn as_slice<'a>(&'a self, len: uint) -> &'a [T] {
    mem::transmute(Slice {
        data: self, // Self is a *const T
        len: len,
    })
}
```

If we had this function, then we would be able to deprecate `from_buf_len` in favor of `String::from_bytes(buf.as_slice(len).to_vec())`, which seems much better to me. Otherwise we can just keep this function and move it to the `string` module.

Do you think this is a good idea? Should I submit a new PR for this or just add it here?

[breaking-change]
Good idea!
On Jul 19, 2014 8:37 PM, "Steven Sheldon" <notifications@github.com> wrote:

> In src/libcollections/string.rs:
>
> > @@ -386,6 +400,14 @@ impl String {
> >          }
> >      }
> >
> > +    /// Converts a vector of bytes to a new `String` without checking if
> > +    /// it contains valid UTF-8. This is unsafe because it assumes that
> > +    /// the utf-8-ness of the vector has already been validated.
> > +    #[inline]
> > +    pub unsafe fn from_bytes(bytes: Vec<u8>) -> String {
> > +        mem::transmute(bytes)
>
> Now that this is in the same module as String, the transmute could be
> removed to just be String { vec: bytes }, yeah?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/rust-lang/rust/pull/15807/files#r15145056>.
>