about summary refs log tree commit diff
path: root/src/libstd/str.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-05-09 10:34:51 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-05-11 01:13:02 -0700
commitf94d671bfae5d8e9a4a4add310b1c40af0ab62a6 (patch)
tree97bea161eb7fff71a0e9a484aa9f190dbe037f58 /src/libstd/str.rs
parentadb8b0b230d5e5c79b4f873825b3d3cff8d1bc8f (diff)
downloadrust-f94d671bfae5d8e9a4a4add310b1c40af0ab62a6.tar.gz
rust-f94d671bfae5d8e9a4a4add310b1c40af0ab62a6.zip
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.

* transmute - This function was moved to `mem`, but it is now marked as
              #[unstable]. This is due to planned changes to the `transmute`
              function and how it can be invoked (see the #[unstable] comment).
              For more information, see RFC 5 and #12898

* transmute_copy - This function was moved to `mem`, with clarification that is
                   is not an error to invoke it with T/U that are different
                   sizes, but rather that it is strongly discouraged. This
                   function is now #[stable]

* forget - This function was moved to `mem` and marked #[stable]

* bump_box_refcount - This function was removed due to the deprecation of
                      managed boxes as well as its questionable utility.

* transmute_mut - This function was previously deprecated, and removed as part
                  of this commit.

* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
                         can be achieved with an `as` in safe code, so it was
                         removed.

* transmute_lifetime - This function was removed because it is likely a strong
                       indication that code is incorrect in the first place.

* transmute_mut_lifetime - This function was removed for the same reasons as
                           `transmute_lifetime`

* copy_lifetime - This function was moved to `mem`, but it is marked
                  `#[unstable]` now due to the likelihood of being removed in
                  the future if it is found to not be very useful.

* copy_mut_lifetime - This function was also moved to `mem`, but had the same
                      treatment as `copy_lifetime`.

* copy_lifetime_vec - This function was removed because it is not used today,
                      and its existence is not necessary with DST
                      (copy_lifetime will suffice).

In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.

    transmute - #[unstable]
    transmute_copy - #[stable]
    forget - #[stable]
    copy_lifetime - #[unstable]
    copy_mut_lifetime - #[unstable]

[breaking-change]
Diffstat (limited to 'src/libstd/str.rs')
-rw-r--r--src/libstd/str.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index fb3dcc97287..24cf9681ca8 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -74,23 +74,23 @@ The actual representation of strings have direct mappings to vectors:
 
 */
 
-use cast;
-use cast::transmute;
-use char;
 use char::Char;
+use char;
 use clone::Clone;
 use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering};
 use container::Container;
+use default::Default;
 use fmt;
+use from_str::FromStr;
 use io::Writer;
 use iter::{Iterator, range, AdditiveIterator};
+use mem::transmute;
+use mem;
 use option::{None, Option, Some};
-use from_str::FromStr;
-use slice::{ImmutableVector, MutableVector, CloneableVector};
 use slice::Vector;
-use vec::Vec;
-use default::Default;
+use slice::{ImmutableVector, MutableVector, CloneableVector};
 use strbuf::StrBuf;
+use vec::Vec;
 
 pub use core::str::{from_utf8, CharEq, Chars, CharOffsets, RevChars};
 pub use core::str::{RevCharOffsets, Bytes, RevBytes, CharSplits, RevCharSplits};
@@ -126,7 +126,7 @@ impl FromStr for ~str {
 /// Fails if invalid UTF-8
 pub fn from_byte(b: u8) -> ~str {
     assert!(b < 128u8);
-    unsafe { ::cast::transmute(box [b]) }
+    unsafe { ::mem::transmute(box [b]) }
 }
 
 /// Convert a char to a string
@@ -403,7 +403,7 @@ static TAG_CONT_U8: u8 = 128u8;
 /// ```
 pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
     if is_utf8(v) {
-        return Slice(unsafe { cast::transmute(v) })
+        return Slice(unsafe { mem::transmute(v) })
     }
 
     static REPLACEMENT: &'static [u8] = bytes!(0xEF, 0xBF, 0xBD); // U+FFFD in UTF-8
@@ -666,8 +666,8 @@ impl<'a> fmt::Show for MaybeOwned<'a> {
 
 /// Unsafe operations
 pub mod raw {
-    use cast;
     use libc;
+    use mem;
     use ptr::RawPtr;
     use raw::Slice;
     use slice::CloneableVector;
@@ -679,9 +679,9 @@ pub mod raw {
     /// Create a Rust string from a *u8 buffer of the given length
     pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str {
         let v = Slice { data: buf, len: len };
-        let bytes: &[u8] = ::cast::transmute(v);
+        let bytes: &[u8] = ::mem::transmute(v);
         assert!(is_utf8(bytes));
-        let s: &str = ::cast::transmute(bytes);
+        let s: &str = ::mem::transmute(bytes);
         s.to_owned()
     }
 
@@ -707,7 +707,7 @@ pub mod raw {
     /// that the utf-8-ness of the vector has already been validated
     #[inline]
     pub unsafe fn from_utf8_owned(v: ~[u8]) -> ~str {
-        cast::transmute(v)
+        mem::transmute(v)
     }
 
     /// Converts a byte to a string.
@@ -717,7 +717,7 @@ pub mod raw {
     /// The caller must preserve the valid UTF-8 property when modifying.
     #[inline]
     pub unsafe fn as_owned_vec<'a>(s: &'a mut ~str) -> &'a mut ~[u8] {
-        cast::transmute(s)
+        mem::transmute(s)
     }
 
     /// Sets the length of a string
@@ -823,7 +823,7 @@ pub trait StrAllocating: Str {
         use slice::Vector;
 
         unsafe {
-            ::cast::transmute(self.as_slice().as_bytes().to_owned())
+            ::mem::transmute(self.as_slice().as_bytes().to_owned())
         }
     }
 
@@ -933,7 +933,7 @@ pub trait OwnedStr {
 impl OwnedStr for ~str {
     #[inline]
     fn into_bytes(self) -> ~[u8] {
-        unsafe { cast::transmute(self) }
+        unsafe { mem::transmute(self) }
     }
 
     #[inline]