DSTify [T]/str extension traits

This PR changes the signature of several methods from `foo(self, ...)` to
`foo(&self, ...)`/`foo(&mut self, ...)`, but there is no breakage of the usage
of these methods due to the autoref nature of `method.call()`s. This PR also
removes the lifetime parameter from some traits (`Trait<'a>` -> `Trait`). These
changes break any use of the extension traits for generic programming, but
those traits are not meant to be used for generic programming in the first
place. In the whole rust distribution there was only one misuse of a extension
trait as a bound, which got corrected (the bound was unnecessary and got
removed) as part of this PR.

[breaking-change]
This commit is contained in:
Jorge Aparicio
2014-10-23 10:43:18 -05:00
parent bd7138dd69
commit 94ddb51c9c
8 changed files with 235 additions and 230 deletions

View File

@@ -19,6 +19,7 @@
//! Their definition should always match the ABI defined in `rustc::back::abi`.
use mem;
use kinds::Sized;
/// The representation of a Rust slice
#[repr(C)]
@@ -53,14 +54,14 @@ pub struct TraitObject {
/// This trait is meant to map equivalences between raw structs and their
/// corresponding rust values.
pub trait Repr<T> {
pub trait Repr<T> for Sized? {
/// This function "unwraps" a rust value (without consuming it) into its raw
/// struct representation. This can be used to read/write different values
/// for the struct. This is a safe method because by default it does not
/// enable write-access to the fields of the return value in safe code.
#[inline]
fn repr(&self) -> T { unsafe { mem::transmute_copy(self) } }
fn repr(&self) -> T { unsafe { mem::transmute_copy(&self) } }
}
impl<'a, T> Repr<Slice<T>> for &'a [T] {}
impl<'a> Repr<Slice<u8>> for &'a str {}
impl<T> Repr<Slice<T>> for [T] {}
impl Repr<Slice<u8>> for str {}