use core::raw::Slice;
use core::ptr::RawPtr;
- use string::String;
+ use string::{mod, String};
use vec::Vec;
use MutableSeq;
buf
}
- /// Converts an owned vector of bytes to a new owned string. This assumes
- /// that the utf-8-ness of the vector has already been validated
- #[inline]
+ /// Deprecated. Replaced by `string::raw::from_utf8`
+ #[deprecated = "Use string::raw::from_utf8"]
pub unsafe fn from_utf8_owned(v: Vec<u8>) -> String {
- mem::transmute(v)
+ string::raw::from_utf8(v)
}
/// Converts a byte to a string.
}
}
+pub mod raw {
+ use super::String;
+ use vec::Vec;
+
+ /// 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_utf8(bytes: Vec<u8>) -> String {
+ String { vec: bytes }
+ }
+}
+
#[cfg(test)]
mod tests {
use std::prelude::*;
// ignore-lexer-test FIXME #15679
//! Base64 binary-to-text encoding
-use std::str;
use std::fmt;
+use std::string;
/// Available encoding character sets
pub enum CharacterSet {
}
unsafe {
- str::raw::from_utf8_owned(v)
+ string::raw::from_utf8(v)
}
}
}
// ignore-lexer-test FIXME #15679
//! Hex binary-to-text encoding
-use std::str;
use std::fmt;
+use std::string;
/// A trait for converting a value to hexadecimal encoding
pub trait ToHex {
}
unsafe {
- str::raw::from_utf8_owned(v)
+ string::raw::from_utf8(v)
}
}
}