#[stable(feature = "rust1", since = "1.0.0")]
impl FromIterator<bool> for BitVec {
fn from_iter<I: IntoIterator<Item=bool>>(iter: I) -> BitVec {
- let mut ret = Bitv::new();
+ let mut ret = BitVec::new();
ret.extend(iter);
ret
}
#[stable(feature = "rust1", since = "1.0.0")]
impl FromIterator<usize> for BitSet {
fn from_iter<I: IntoIterator<Item=usize>>(iter: I) -> BitSet {
- let mut ret = BitvSet::new();
+ let mut ret = BitSet::new();
ret.extend(iter);
ret
}
///
/// let a = [1, 4, 2, 3, 8, 9, 6];
/// let sum = a.iter()
- /// .cloned()
- /// .inspect(|&x| println!("filtering {}", x))
- /// .filter(|&x| x % 2 == 0)
- /// .inspect(|&x| println!("{} made it through", x))
- /// .sum();
+ /// .map(|x| *x)
+ /// .inspect(|&x| println!("filtering {}", x))
+ /// .filter(|&x| x % 2 == 0)
+ /// .inspect(|&x| println!("{} made it through", x))
+ /// .sum();
/// println!("{}", sum);
/// ```
#[inline]
}
impl Hasher for MyHasher {
- type Output = u64;
fn write(&mut self, buf: &[u8]) {
for byte in buf {
self.hash += *byte as u64;
struct CustomHasher { output: u64 }
impl Hasher for CustomHasher {
- type Output = u64;
fn finish(&self) -> u64 { self.output }
fn write(&mut self, data: &[u8]) { panic!() }
fn write_u64(&mut self, data: u64) { self.output = data; }
Br(bcx, loop_bcx.llbb, DebugLoc::None);
let loop_counter = Phi(loop_bcx, bcx.ccx().int_type(),
- &[C_uint(bcx.ccx(), 0)], &[bcx.llbb]);
+ &[C_uint(bcx.ccx(), 0 as usize)], &[bcx.llbb]);
let bcx = loop_bcx;
impl Lock {
pub fn new(p: &Path) -> Lock {
- let buf = CString::from_slice(p.as_vec()).unwrap();
+ let buf = CString::new(p.as_vec()).unwrap();
let fd = unsafe {
libc::open(buf.as_ptr(), libc::O_RDWR | libc::O_CREAT,
libc::S_IRWXU)
s.push_str(&highlight::highlight(&text,
None,
Some("rust-example-rendered")));
- let output = CString::from_vec(s.into_bytes()).unwrap();
+ let output = CString::new(s).unwrap();
hoedown_buffer_puts(ob, output.as_ptr());
})
}
format!("{} ", sec)
});
- let text = CString::from_vec(text.into_bytes()).unwrap();
+ let text = CString::new(text).unwrap();
unsafe { hoedown_buffer_puts(ob, text.as_ptr()) }
}
S: HashState<Hasher=H> + Default,
H: hash::Hasher<Output=u64>
{
- fn from_iter<T: Iterator<Item=(K, V)>>(iter: T) -> HashMap<K, V, S> {
+ fn from_iter<T: IntoIterator<Item=(K, V)>>(iter: T) -> HashMap<K, V, S> {
+ let iter = iter.into_iter();
let lower = iter.size_hint().0;
let mut map = HashMap::with_capacity_and_hash_state(lower,
Default::default());
S: HashState<Hasher=H>,
H: hash::Hasher<Output=u64>
{
- fn extend<T: Iterator<Item=(K, V)>>(&mut self, iter: T) {
+ fn extend<T: IntoIterator<Item=(K, V)>>(&mut self, iter: T) {
for (k, v) in iter {
self.insert(k, v);
}
S: HashState<Hasher=H> + Default,
H: hash::Hasher<Output=u64>
{
- fn from_iter<I: Iterator<Item=T>>(iter: I) -> HashSet<T, S> {
+ fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> HashSet<T, S> {
+ let iter = iter.into_iter();
let lower = iter.size_hint().0;
let mut set = HashSet::with_capacity_and_hash_state(lower, Default::default());
set.extend(iter);
S: HashState<Hasher=H>,
H: hash::Hasher<Output=u64>
{
- fn extend<I: Iterator<Item=T>>(&mut self, iter: I) {
+ fn extend<I: IntoIterator<Item=T>>(&mut self, iter: I) {
for k in iter {
self.insert(k);
}
/// }
///
/// fn main() {
-/// let s = CString::from_slice(b"data data data data").unwrap();
+/// let s = CString::new("data data data data").unwrap();
/// work(&s);
/// }
/// ```
/// extern { fn puts(s: *const libc::c_char); }
///
/// fn main() {
- /// let to_print = CString::from_slice(b"Hello!").unwrap();
+ /// let to_print = CString::new("Hello!").unwrap();
/// unsafe {
/// puts(to_print.as_ptr());
/// }
/// extern { fn puts(s: *const libc::c_char); }
///
/// fn main() {
- /// let to_print = CString::from_slice(b"Hello!").unwrap();
+ /// let to_print = CString::new("Hello!").unwrap();
/// unsafe {
/// puts(to_print.as_ptr());
/// }
#[test]
fn simple() {
- let s = CString::from_slice(b"1234").unwrap();
+ let s = CString::new(b"1234").unwrap();
assert_eq!(s.as_bytes(), b"1234");
assert_eq!(s.as_bytes_with_nul(), b"1234\0");
}
#[test]
fn build_with_zero1() {
- assert!(CString::from_slice(b"\0").is_err());
+ assert!(CString::new(b"\0").is_err());
}
#[test]
fn build_with_zero2() {
- assert!(CString::from_vec(vec![0]).is_err());
+ assert!(CString::new(vec![0]).is_err());
}
#[test]
#[test]
fn formatted() {
- let s = CString::from_slice(b"12").unwrap();
+ let s = CString::new(b"12").unwrap();
assert_eq!(format!("{:?}", s), "\"12\"");
}
#![feature(box_syntax)]
extern crate collections;
-use std::collections::Bitv;
+use std::collections::BitVec;
fn bitv_test() {
- let mut v1 = box Bitv::from_elem(31, false);
- let v2 = box Bitv::from_elem(31, true);
+ let mut v1 = box BitVec::from_elem(31, false);
+ let v2 = box BitVec::from_elem(31, true);
v1.union(&*v2);
}
}
fn atol(s: String) -> int {
- let c = CString::from_slice(s.as_bytes()).unwrap();
+ let c = CString::new(s).unwrap();
unsafe { mlibc::atol(c.as_ptr()) as int }
}
fn atoll(s: String) -> i64 {
- let c = CString::from_slice(s.as_bytes()).unwrap();
+ let c = CString::new(s).unwrap();
unsafe { mlibc::atoll(c.as_ptr()) as i64 }
}
#![feature(macro_rules)]
use std::borrow::{Cow, IntoCow};
-use std::collections::Bitv;
+use std::collections::BitVec;
use std::default::Default;
use std::iter::FromIterator;
use std::ops::Add;
Vec::<()>::new, fn() -> Vec<()>, ();
Vec::with_capacity, fn(uint) -> Vec<()>, (5);
Vec::<()>::with_capacity, fn(uint) -> Vec<()>, (5);
- Bitv::from_fn, fn(uint, fn(uint) -> bool) -> Bitv, (5, odd);
- Bitv::from_fn::<fn(uint) -> bool>, fn(uint, fn(uint) -> bool) -> Bitv, (5, odd);
+ BitVec::from_fn, fn(uint, fn(uint) -> bool) -> BitVec, (5, odd);
+ BitVec::from_fn::<fn(uint) -> bool>, fn(uint, fn(uint) -> bool) -> BitVec, (5, odd);
// Inherent non-static method.
Vec::map_in_place, fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>, (vec![b'f', b'o', b'o'], u8_as_i8);
fn strlen(str: String) -> uint {
// C string is terminated with a zero
- let s = CString::from_slice(str.as_bytes()).unwrap();
+ let s = CString::new(str).unwrap();
unsafe {
mlibc::my_strlen(s.as_ptr()) as uint
}
extern crate collections;
-use std::collections::Bitv;
+use std::collections::BitVec;
use std::num::Float;
fn main() {
// Generate sieve of Eratosthenes for n up to 1e6
let n = 1000000_usize;
- let mut sieve = Bitv::from_elem(n+1, true);
+ let mut sieve = BitVec::from_elem(n+1, true);
let limit: uint = (n as f32).sqrt() as uint;
for i in 2..limit+1 {
if sieve[i] {
// except according to those terms.
extern crate collections;
-use std::collections::RingBuf;
+use std::collections::VecDeque;
pub fn main() {
- let mut q = RingBuf::new();
+ let mut q = VecDeque::new();
q.push_front(10);
}
let test_file = &old_path.join("temp.txt");
/* Write the temp input file */
- let fromp = CString::from_slice(test_file.as_vec()).unwrap();
- let modebuf = CString::from_slice(b"w+b").unwrap();
+ let fromp = CString::new(test_file.as_vec()).unwrap();
+ let modebuf = CString::new(b"w+b").unwrap();
let ostream = libc::fopen(fromp.as_ptr(), modebuf.as_ptr());
assert!((ostream as uint != 0_usize));
let s = "hello".to_string();
- let buf = CString::from_slice(b"hello").unwrap();
+ let buf = CString::new(b"hello").unwrap();
let write_len = libc::fwrite(buf.as_ptr() as *mut _,
1_usize as libc::size_t,
(s.len() + 1_usize) as libc::size_t,
unsafe {
// Call with just the named parameter
- let c = CString::from_slice(b"Hello World\n").unwrap();
+ let c = CString::new(b"Hello World\n").unwrap();
check("Hello World\n", |s| sprintf(s, c.as_ptr()));
// Call with variable number of arguments
- let c = CString::from_slice(b"%d %f %c %s\n").unwrap();
+ let c = CString::new(b"%d %f %c %s\n").unwrap();
check("42 42.500000 a %d %f %c %s\n\n", |s| {
sprintf(s, c.as_ptr(), 42, 42.5f64, 'a' as c_int, c.as_ptr());
});
// A function that takes a function pointer
unsafe fn call(p: unsafe extern fn(*mut c_char, *const c_char, ...) -> c_int) {
// Call with just the named parameter
- let c = CString::from_slice(b"Hello World\n").unwrap();
+ let c = CString::new(b"Hello World\n").unwrap();
check("Hello World\n", |s| sprintf(s, c.as_ptr()));
// Call with variable number of arguments
- let c = CString::from_slice(b"%d %f %c %s\n").unwrap();
+ let c = CString::new(b"%d %f %c %s\n").unwrap();
check("42 42.500000 a %d %f %c %s\n\n", |s| {
sprintf(s, c.as_ptr(), 42, 42.5f64, 'a' as c_int, c.as_ptr());
});