at least that's what the docs say: http://doc.rust-lang.org/std/slice/fn.from_raw_parts.html
A few situations got prettier. In some situations the mutability of the resulting and source pointers differed (and was cast away by transmute), the mutability matches now.
#![feature(box_syntax)]
#![feature(collections)]
- #![feature(core)]
#![feature(int_uint)]
#![feature(libc)]
#![feature(link_args)]
#![feature(staged_api)]
-#![feature(path)]
#![cfg_attr(unix, feature(std_misc))]
extern crate libc;
use std::ffi::CString;
use std::cell::RefCell;
- use std::{raw, mem};
+ use std::{slice, mem};
use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
use libc::{c_longlong, c_ulonglong, c_void};
use debuginfo::{DIBuilderRef, DIDescriptor,
pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
ptr: *const c_char,
size: size_t) {
- let slice: &[u8] = mem::transmute(raw::Slice {
- data: ptr as *const u8,
- len: size as uint,
- });
+ let slice = slice::from_raw_parts(ptr as *const u8, size as uint);
let sr: RustStringRepr = mem::transmute(sr);
(*sr).borrow_mut().push_all(slice);
#![deny(unused_must_use)]
#![allow(deprecated)] // seriously this is all deprecated
#![allow(unused_imports)]
+#![deprecated(since = "1.0.0",
+ reasons = "APIs have been replaced with new I/O modules such as \
+ std::{io, fs, net, process}")]
pub use self::SeekStyle::*;
pub use self::FileMode::*;
// Private function here because we aren't sure if we want to expose this as
// API yet. If so, it should be a method on Vec.
unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: uint, end: uint) -> &'a mut [T] {
- use raw::Slice;
+ use slice;
use ptr::PtrExt;
assert!(start <= end);
assert!(end <= v.capacity());
- transmute(Slice {
- data: v.as_ptr().offset(start as int),
- len: end - start
- })
+ slice::from_raw_parts_mut(
+ v.as_mut_ptr().offset(start as int),
+ end - start
+ )
}
/// A `RefReader` is a struct implementing `Reader` which contains a reference
//! nor can it decode WTF-8 from arbitrary bytes.
//! WTF-8 strings can be obtained from UTF-8, UTF-16, or code points.
+// this module is imported from @SimonSapin's repo and has tons of dead code on
+// unix (it's mostly used on windows), so don't worry about dead code here.
+#![allow(dead_code)]
+
use core::prelude::*;
use core::char::{encode_utf8_raw, encode_utf16_raw};
use core::str::{char_range_at_raw, next_code_point};
- use core::raw::Slice as RawSlice;
use ascii::*;
use borrow::Cow;
unsafe {
// Attempt to not use an intermediate buffer by just pushing bytes
// directly onto this string.
- let slice = RawSlice {
- data: self.bytes.as_ptr().offset(cur_len as int),
- len: 4,
- };
+ let slice = slice::from_raw_parts_mut(
+ self.bytes.as_mut_ptr().offset(cur_len as int),
+ 4
+ );
let used = encode_utf8_raw(code_point.value, mem::transmute(slice))
.unwrap_or(0);
self.bytes.set_len(cur_len + used);
/// Copied from core::str::raw::slice_unchecked
#[inline]
pub unsafe fn slice_unchecked(s: &Wtf8, begin: uint, end: uint) -> &Wtf8 {
- mem::transmute(RawSlice {
- data: s.bytes.as_ptr().offset(begin as int),
- len: end - begin,
- })
+ // memory layout of an &[u8] and &Wtf8 are the same
+ mem::transmute(slice::from_raw_parts(
+ s.bytes.as_ptr().offset(begin as int),
+ end - begin
+ ))
}
/// Copied from core::str::raw::slice_error_fail