--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! A unique pointer type
+
+use core::any::{Any, AnyRefExt};
+use core::clone::Clone;
+use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
+use core::default::Default;
+use core::fmt;
+use core::intrinsics;
+use core::mem;
+use core::option::Option;
+use core::raw::TraitObject;
+use core::result::{Ok, Err, Result};
+
+/// A value that represents the global exchange heap. This is the default
+/// place that the `box` keyword allocates into when no place is supplied.
+///
+/// The following two examples are equivalent:
+///
+/// use std::boxed::HEAP;
+///
+/// # struct Bar;
+/// # impl Bar { fn new(_a: int) { } }
+/// let foo = box(HEAP) Bar::new(2);
+/// let foo = box Bar::new(2);
+#[lang = "exchange_heap"]
+#[experimental = "may be renamed; uncertain about custom allocator design"]
+pub static HEAP: () = ();
+
+/// A type that represents a uniquely-owned value.
+#[lang = "owned_box"]
+#[unstable = "custom allocators will add an additional type parameter (with default)"]
+pub struct Box<T>(*mut T);
+
+impl<T: Default> Default for Box<T> {
+ fn default() -> Box<T> { box Default::default() }
+}
+
+#[unstable]
+impl<T: Clone> Clone for Box<T> {
+ /// Return a copy of the owned box.
+ #[inline]
+ fn clone(&self) -> Box<T> { box {(**self).clone()} }
+
+ /// Perform copy-assignment from `source` by reusing the existing allocation.
+ #[inline]
+ fn clone_from(&mut self, source: &Box<T>) {
+ (**self).clone_from(&(**source));
+ }
+}
+
+impl<T:PartialEq> PartialEq for Box<T> {
+ #[inline]
+ fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) }
+ #[inline]
+ fn ne(&self, other: &Box<T>) -> bool { *(*self) != *(*other) }
+}
+impl<T:PartialOrd> PartialOrd for Box<T> {
+ #[inline]
+ fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
+ (**self).partial_cmp(*other)
+ }
+ #[inline]
+ fn lt(&self, other: &Box<T>) -> bool { *(*self) < *(*other) }
+ #[inline]
+ fn le(&self, other: &Box<T>) -> bool { *(*self) <= *(*other) }
+ #[inline]
+ fn ge(&self, other: &Box<T>) -> bool { *(*self) >= *(*other) }
+ #[inline]
+ fn gt(&self, other: &Box<T>) -> bool { *(*self) > *(*other) }
+}
+impl<T: Ord> Ord for Box<T> {
+ #[inline]
+ fn cmp(&self, other: &Box<T>) -> Ordering { (**self).cmp(*other) }
+}
+impl<T: Eq> Eq for Box<T> {}
+
+/// Extension methods for an owning `Any` trait object
+#[unstable = "post-DST, the signature of `downcast` will change to take `Box<Self>`"]
+pub trait BoxAny {
+ /// Returns the boxed value if it is of type `T`, or
+ /// `Err(Self)` if it isn't.
+ fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
+
+ /// Deprecated; this method has been renamed to `downcast`.
+ #[deprecated = "use downcast instead"]
+ fn move<T: 'static>(self) -> Result<Box<T>, Self> {
+ self.downcast::<T>()
+ }
+}
+
+impl BoxAny for Box<Any> {
+ #[inline]
+ fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
+ if self.is::<T>() {
+ unsafe {
+ // Get the raw representation of the trait object
+ let to: TraitObject =
+ *mem::transmute::<&Box<Any>, &TraitObject>(&self);
+
+ // Prevent destructor on self being run
+ intrinsics::forget(self);
+
+ // Extract the data pointer
+ Ok(mem::transmute(to.data))
+ }
+ } else {
+ Err(self)
+ }
+ }
+}
+
+impl<T: fmt::Show> fmt::Show for Box<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ (**self).fmt(f)
+ }
+}
+
+impl fmt::Show for Box<Any> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.pad("Box<Any>")
+ }
+}
+
+#[cfg(test)]
+mod test {
+ #[test]
+ fn test_owned_clone() {
+ let a = box 5i;
+ let b: Box<int> = a.clone();
+ assert!(a == b);
+ }
+
+ #[test]
+ fn any_move() {
+ let a = box 8u as Box<Any>;
+ let b = box Test as Box<Any>;
+
+ match a.downcast::<uint>() {
+ Ok(a) => { assert!(a == box 8u); }
+ Err(..) => fail!()
+ }
+ match b.downcast::<Test>() {
+ Ok(a) => { assert!(a == box Test); }
+ Err(..) => fail!()
+ }
+
+ let a = box 8u as Box<Any>;
+ let b = box Test as Box<Any>;
+
+ assert!(a.downcast::<Box<Test>>().is_err());
+ assert!(b.downcast::<Box<uint>>().is_err());
+ }
+
+ #[test]
+ fn test_show() {
+ let a = box 8u as Box<Any>;
+ let b = box Test as Box<Any>;
+ let a_str = a.to_str();
+ let b_str = b.to_str();
+ assert_eq!(a_str.as_slice(), "Box<Any>");
+ assert_eq!(b_str.as_slice(), "Box<Any>");
+
+ let a = &8u as &Any;
+ let b = &Test as &Any;
+ let s = format!("{}", a);
+ assert_eq!(s.as_slice(), "&Any");
+ let s = format!("{}", b);
+ assert_eq!(s.as_slice(), "&Any");
+ }
+}
//!
//! Currently, there are four major definitions in this library.
//!
-//! ## Owned pointers
+//! ## Boxed values
//!
-//! The [`Box`](owned/index.html) type is the core owned pointer type in rust.
+//! The [`Box`](boxed/index.html) type is the core owned pointer type in rust.
//! There can only be one owner of a `Box`, and the owner can decide to mutate
-//! the contents.
+//! the contents, which live on the heap.
//!
//! This type can be sent among tasks efficiently as the size of a `Box` value
//! is just a pointer. Tree-like data structures are often built on owned
#[cfg(test)] #[phase(plugin, link)] extern crate std;
#[cfg(test)] #[phase(plugin, link)] extern crate log;
+// The deprecated name of the boxed module
+
+#[deprecated = "use boxed instead"]
+#[cfg(not(test))]
+pub use owned = boxed;
+
// Heaps provided for low-level allocation strategies
pub mod heap;
// Primitive types using the heaps above
#[cfg(not(test))]
-pub mod owned;
+pub mod boxed;
pub mod arc;
pub mod rc;
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! A unique pointer type
-
-use core::any::{Any, AnyRefExt};
-use core::clone::Clone;
-use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
-use core::default::Default;
-use core::fmt;
-use core::intrinsics;
-use core::kinds::Send;
-use core::mem;
-use core::option::Option;
-use core::raw::TraitObject;
-use core::result::{Ok, Err, Result};
-
-/// A value that represents the global exchange heap. This is the default
-/// place that the `box` keyword allocates into when no place is supplied.
-///
-/// The following two examples are equivalent:
-///
-/// use std::owned::HEAP;
-///
-/// # struct Bar;
-/// # impl Bar { fn new(_a: int) { } }
-/// let foo = box(HEAP) Bar::new(2);
-/// let foo = box Bar::new(2);
-#[lang="exchange_heap"]
-pub static HEAP: () = ();
-
-/// A type that represents a uniquely-owned value.
-#[lang="owned_box"]
-pub struct Box<T>(*mut T);
-
-impl<T: Default> Default for Box<T> {
- fn default() -> Box<T> { box Default::default() }
-}
-
-#[unstable]
-impl<T: Clone> Clone for Box<T> {
- /// Return a copy of the owned box.
- #[inline]
- fn clone(&self) -> Box<T> { box {(**self).clone()} }
-
- /// Perform copy-assignment from `source` by reusing the existing allocation.
- #[inline]
- fn clone_from(&mut self, source: &Box<T>) {
- (**self).clone_from(&(**source));
- }
-}
-
-// box pointers
-impl<T:PartialEq> PartialEq for Box<T> {
- #[inline]
- fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) }
- #[inline]
- fn ne(&self, other: &Box<T>) -> bool { *(*self) != *(*other) }
-}
-impl<T:PartialOrd> PartialOrd for Box<T> {
- #[inline]
- fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
- (**self).partial_cmp(*other)
- }
- #[inline]
- fn lt(&self, other: &Box<T>) -> bool { *(*self) < *(*other) }
- #[inline]
- fn le(&self, other: &Box<T>) -> bool { *(*self) <= *(*other) }
- #[inline]
- fn ge(&self, other: &Box<T>) -> bool { *(*self) >= *(*other) }
- #[inline]
- fn gt(&self, other: &Box<T>) -> bool { *(*self) > *(*other) }
-}
-impl<T: Ord> Ord for Box<T> {
- #[inline]
- fn cmp(&self, other: &Box<T>) -> Ordering { (**self).cmp(*other) }
-}
-impl<T: Eq> Eq for Box<T> {}
-
-/// Extension methods for an owning `Any` trait object
-pub trait AnyOwnExt {
- /// Returns the boxed value if it is of type `T`, or
- /// `Err(Self)` if it isn't.
- fn move<T: 'static>(self) -> Result<Box<T>, Self>;
-}
-
-impl AnyOwnExt for Box<Any> {
- #[inline]
- fn move<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
- if self.is::<T>() {
- unsafe {
- // Get the raw representation of the trait object
- let to: TraitObject =
- *mem::transmute::<&Box<Any>, &TraitObject>(&self);
-
- // Prevent destructor on self being run
- intrinsics::forget(self);
-
- // Extract the data pointer
- Ok(mem::transmute(to.data))
- }
- } else {
- Err(self)
- }
- }
-}
-
-/// Extension methods for an owning `Any+Send` trait object
-pub trait AnySendOwnExt {
- /// Returns the boxed value if it is of type `T`, or
- /// `Err(Self)` if it isn't.
- fn move_send<T: 'static>(self) -> Result<Box<T>, Self>;
-}
-
-impl AnySendOwnExt for Box<Any+Send> {
- #[inline]
- fn move_send<T: 'static>(self) -> Result<Box<T>, Box<Any+Send>> {
- if self.is::<T>() {
- unsafe {
- // Get the raw representation of the trait object
- let to: TraitObject =
- *mem::transmute::<&Box<Any+Send>, &TraitObject>(&self);
-
- // Prevent destructor on self being run
- intrinsics::forget(self);
-
- // Extract the data pointer
- Ok(mem::transmute(to.data))
- }
- } else {
- Err(self)
- }
- }
-}
-
-impl<T: fmt::Show> fmt::Show for Box<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- (**self).fmt(f)
- }
-}
-
-impl fmt::Show for Box<Any> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.pad("Box<Any>")
- }
-}
-
-#[cfg(test)]
-mod test {
- #[test]
- fn test_owned_clone() {
- let a = box 5i;
- let b: Box<int> = a.clone();
- assert!(a == b);
- }
-
- #[test]
- fn any_move() {
- let a = box 8u as Box<Any>;
- let b = box Test as Box<Any>;
-
- match a.move::<uint>() {
- Ok(a) => { assert!(a == box 8u); }
- Err(..) => fail!()
- }
- match b.move::<Test>() {
- Ok(a) => { assert!(a == box Test); }
- Err(..) => fail!()
- }
-
- let a = box 8u as Box<Any>;
- let b = box Test as Box<Any>;
-
- assert!(a.move::<Box<Test>>().is_err());
- assert!(b.move::<Box<uint>>().is_err());
- }
-
- #[test]
- fn test_show() {
- let a = box 8u as Box<Any>;
- let b = box Test as Box<Any>;
- let a_str = a.to_str();
- let b_str = b.to_str();
- assert_eq!(a_str.as_slice(), "Box<Any>");
- assert_eq!(b_str.as_slice(), "Box<Any>");
-
- let a = &8u as &Any;
- let b = &Test as &Any;
- let s = format!("{}", a);
- assert_eq!(s.as_slice(), "&Any");
- let s = format!("{}", b);
- assert_eq!(s.as_slice(), "&Any");
- }
-}
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::fmt;
use core::fmt::Show;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::default::Default;
use core::fmt;
use core::iter;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use alloc::rc::Rc;
use core::intrinsics::TypeId;
use core::mem;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::default::Default;
use core::fmt;
use core::fmt::Show;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::default::Default;
use core::mem::zeroed;
use core::mem;
use ty::Unsafe;
/// A mutable memory location that admits only `Copy` data.
+#[unstable = "likely to be renamed; otherwise stable"]
pub struct Cell<T> {
value: Unsafe<T>,
noshare: marker::NoShare,
}
+#[stable]
impl<T:Copy> Cell<T> {
/// Creates a new `Cell` containing the given value.
pub fn new(value: T) -> Cell<T> {
}
}
-#[unstable]
+#[unstable = "waiting for `Clone` trait to become stable"]
impl<T:Copy> Clone for Cell<T> {
fn clone(&self) -> Cell<T> {
Cell::new(self.get())
}
}
+#[unstable = "waiting for `PartialEq` trait to become stable"]
impl<T:PartialEq + Copy> PartialEq for Cell<T> {
fn eq(&self, other: &Cell<T>) -> bool {
self.get() == other.get()
}
/// A mutable memory location with dynamically checked borrow rules
+#[unstable = "likely to be renamed; otherwise stable"]
pub struct RefCell<T> {
value: Unsafe<T>,
borrow: Cell<BorrowFlag>,
impl<T> RefCell<T> {
/// Create a new `RefCell` containing `value`
+ #[stable]
pub fn new(value: T) -> RefCell<T> {
RefCell {
value: Unsafe::new(value),
}
/// Consumes the `RefCell`, returning the wrapped value.
+ #[unstable = "may be renamed, depending on global conventions"]
pub fn unwrap(self) -> T {
debug_assert!(self.borrow.get() == UNUSED);
unsafe{self.value.unwrap()}
/// immutable borrows can be taken out at the same time.
///
/// Returns `None` if the value is currently mutably borrowed.
+ #[unstable = "may be renamed, depending on global conventions"]
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
match self.borrow.get() {
WRITING => None,
/// # Failure
///
/// Fails if the value is currently mutably borrowed.
+ #[unstable]
pub fn borrow<'a>(&'a self) -> Ref<'a, T> {
match self.try_borrow() {
Some(ptr) => ptr,
/// cannot be borrowed while this borrow is active.
///
/// Returns `None` if the value is currently borrowed.
+ #[unstable = "may be renamed, depending on global conventions"]
pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> {
match self.borrow.get() {
UNUSED => {
/// # Failure
///
/// Fails if the value is currently borrowed.
+ #[unstable]
pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> {
match self.try_borrow_mut() {
Some(ptr) => ptr,
}
}
-#[unstable]
+#[unstable = "waiting for `Clone` to become stable"]
impl<T: Clone> Clone for RefCell<T> {
fn clone(&self) -> RefCell<T> {
RefCell::new(self.borrow().clone())
}
}
+#[unstable = "waiting for `PartialEq` to become stable"]
impl<T: PartialEq> PartialEq for RefCell<T> {
fn eq(&self, other: &RefCell<T>) -> bool {
*self.borrow() == *other.borrow()
}
/// Wraps a borrowed reference to a value in a `RefCell` box.
+#[unstable]
pub struct Ref<'b, T> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
}
#[unsafe_destructor]
+#[unstable]
impl<'b, T> Drop for Ref<'b, T> {
fn drop(&mut self) {
let borrow = self._parent.borrow.get();
}
}
+#[unstable = "waiting for `Deref` to become stable"]
impl<'b, T> Deref<T> for Ref<'b, T> {
#[inline]
fn deref<'a>(&'a self) -> &'a T {
///
/// A `Clone` implementation would interfere with the widespread
/// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
-#[experimental]
+#[experimental = "likely to be moved to a method, pending language changes"]
pub fn clone_ref<'b, T>(orig: &Ref<'b, T>) -> Ref<'b, T> {
// Since this Ref exists, we know the borrow flag
// is not set to WRITING.
}
/// Wraps a mutable borrowed reference to a value in a `RefCell` box.
+#[unstable]
pub struct RefMut<'b, T> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
}
#[unsafe_destructor]
+#[unstable]
impl<'b, T> Drop for RefMut<'b, T> {
fn drop(&mut self) {
let borrow = self._parent.borrow.get();
}
}
+#[unstable = "waiting for `Deref` to become stable"]
impl<'b, T> Deref<T> for RefMut<'b, T> {
#[inline]
fn deref<'a>(&'a self) -> &'a T {
}
}
+#[unstable = "waiting for `DerefMut` to become stable"]
impl<'b, T> DerefMut<T> for RefMut<'b, T> {
#[inline]
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
mod imp {
use core::prelude::*;
- use alloc::owned::Box;
+ use alloc::boxed::Box;
use collections::vec::Vec;
use core::mem;
use core::slice;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use collections::vec::Vec;
use core::atomics;
use core::mem;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::any::Any;
use task::{Task, BlockedTask, TaskOpts};
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use local_ptr;
use task::Task;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use collections::vec::Vec;
use core::kinds::marker;
use core::mem;
use core::prelude::*;
use core::mem;
-use alloc::owned::Box;
+use alloc::boxed::Box;
#[cfg(windows)] // mingw-w32 doesn't like thread_local things
#[cfg(target_os = "android")] // see #10686
pub mod compiled {
use core::prelude::*;
- use alloc::owned::Box;
+ use alloc::boxed::Box;
use core::mem;
#[cfg(test)]
pub mod native {
use core::prelude::*;
- use alloc::owned::Box;
+ use alloc::boxed::Box;
use core::mem;
use core::ptr;
use tls = thread_local_storage;
//! The EventLoop and internal synchronous I/O interface.
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use collections::string::String;
use collections::vec::Vec;
use core::fmt;
#[lang = "stack_exhausted"]
extern fn stack_exhausted() {
use core::prelude::*;
- use alloc::owned::Box;
+ use alloc::boxed::Box;
use local::Local;
use task::Task;
use core::intrinsics;
use core::prelude::*;
use alloc::arc::Arc;
-use alloc::owned::{AnyOwnExt, Box};
+use alloc::boxed::{BoxAny, Box};
use core::any::Any;
use core::atomics::{AtomicUint, SeqCst};
use core::iter::Take;
unsafe {
let imp = self.imp.take_unwrap();
let vtable = mem::transmute::<_, &raw::TraitObject>(&imp).vtable;
- match imp.wrap().move::<T>() {
+ match imp.wrap().downcast::<T>() {
Ok(t) => Some(t),
Err(t) => {
let data = mem::transmute::<_, raw::TraitObject>(t).data;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::mem;
use core::uint;
use libc;
mod imp {
use core::prelude::*;
- use alloc::owned::Box;
+ use alloc::boxed::Box;
use core::cmp;
use core::mem;
use core::ptr;
mod imp {
use core::prelude::*;
- use alloc::owned::Box;
+ use alloc::boxed::Box;
use core::cmp;
use core::mem;
use core::ptr;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use collections::string::String;
use collections::vec::Vec;
use core::any::Any;
use mem;
use ops::Drop;
use option::{Some, None, Option};
-use owned::Box;
+use boxed::Box;
use ptr;
use result::{Ok, Err};
#![experimental]
-use alloc::owned::Box;
+use alloc::boxed::Box;
use any::{Any, AnyRefExt};
use fmt;
use io::{Writer, IoResult};
use kinds::Send;
use libc;
use option::{Some, None, Option};
-use owned::Box;
+use boxed::Box;
use path::{Path, GenericPath};
use path;
use result::{Err, Ok};
use ops::{BitOr, BitAnd, Sub, Not};
use option::{Option, Some, None};
use os;
-use owned::Box;
+use boxed::Box;
use result::{Ok, Err, Result};
use rt::rtio;
use slice::{Vector, MutableVector, ImmutableVector};
use from_str::FromStr;
use kinds::Send;
use option::{None, Some, Option};
-use owned::Box;
+use boxed::Box;
use rt::rtio::{IoFactory, LocalIo, RtioSocket, RtioTcpListener};
use rt::rtio::{RtioTcpAcceptor, RtioTcpStream};
use rt::rtio;
use io::net::ip::{SocketAddr, IpAddr};
use io::{Reader, Writer, IoResult, IoError};
use kinds::Send;
-use owned::Box;
+use boxed::Box;
use option::Option;
use result::{Ok, Err};
use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, LocalIo};
use clone::Clone;
use io::{Listener, Acceptor, Reader, Writer, IoResult, IoError};
use kinds::Send;
-use owned::Box;
+use boxed::Box;
use rt::rtio::{IoFactory, LocalIo, RtioUnixListener};
use rt::rtio::{RtioUnixAcceptor, RtioPipe};
use io::{IoResult, IoError};
use libc;
use os;
-use owned::Box;
+use boxed::Box;
use rt::rtio::{RtioPipe, LocalIo};
/// A synchronous, in-memory pipe.
use io;
use libc;
use mem;
-use owned::Box;
+use boxed::Box;
use rt::rtio::{RtioProcess, ProcessConfig, IoFactory, LocalIo};
use rt::rtio;
use c_str::CString;
use kinds::Send;
use mem::drop;
use option::{Some, None};
-use owned::Box;
+use boxed::Box;
use result::{Ok, Err};
use rt::rtio::{IoFactory, LocalIo, RtioSignal, Callback};
use slice::ImmutableVector;
use kinds::Send;
use libc;
use option::{Option, Some, None};
-use owned::Box;
+use boxed::Box;
use result::{Ok, Err};
use rt;
use rt::local::Local;
use comm::{Receiver, Sender, channel};
use io::{IoResult, IoError};
use kinds::Send;
-use owned::Box;
+use boxed::Box;
use rt::rtio::{IoFactory, LocalIo, RtioTimer, Callback};
/// A synchronous timer object
use prelude::*;
use cmp;
use io;
-use owned::Box;
+use boxed::Box;
use slice::bytes::MutableByteVector;
/// Wraps a `Reader`, limiting the number of bytes that can be read from it.
mod test {
use io::{MemReader, MemWriter, BufReader};
use io;
- use owned::Box;
+ use boxed::Box;
use super::*;
use prelude::*;
#[cfg(test)] pub use realstd::ops;
#[cfg(test)] pub use realstd::cmp;
#[cfg(test)] pub use realstd::ty;
-#[cfg(test)] pub use realstd::owned;
+#[cfg(test)] pub use realstd::boxed;
#[cfg(test)] pub use realstd::gc;
pub use core::result;
pub use core::option;
-pub use alloc::owned;
+pub use alloc::boxed;
+#[deprecated = "use boxed instead"]
+pub use owned = boxed;
+
pub use alloc::rc;
pub use core_collections::slice;
#[doc(no_inline)] pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
#[doc(no_inline)] pub use num::{Signed, Unsigned, Primitive, Int, Float};
#[doc(no_inline)] pub use num::{FloatMath, ToPrimitive, FromPrimitive};
-#[doc(no_inline)] pub use owned::Box;
+#[doc(no_inline)] pub use boxed::Box;
#[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath};
#[doc(no_inline)] pub use ptr::RawPtr;
#[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek};
use io::{Writer, stdio};
use kinds::{Send, marker};
use option::{None, Some, Option};
-use owned::Box;
+use boxed::Box;
use result::Result;
use rt::local::Local;
use rt::task;
#[cfg(test)]
mod test {
use any::{Any, AnyRefExt};
- use owned::AnyOwnExt;
+ use boxed::BoxAny;
use result;
use result::{Ok, Err};
use str::StrAllocating;
Err(e) => {
type T = &'static str;
assert!(e.is::<T>());
- assert_eq!(*e.move::<T>().unwrap(), "static string");
+ assert_eq!(*e.downcast::<T>().unwrap(), "static string");
}
Ok(()) => fail!()
}
Err(e) => {
type T = String;
assert!(e.is::<T>());
- assert_eq!(*e.move::<T>().unwrap(), "owned string".to_string());
+ assert_eq!(*e.downcast::<T>().unwrap(), "owned string".to_string());
}
Ok(()) => fail!()
}
Err(e) => {
type T = Box<Any + Send>;
assert!(e.is::<T>());
- let any = e.move::<T>().unwrap();
+ let any = e.downcast::<T>().unwrap();
assert!(any.is::<u16>());
- assert_eq!(*any.move::<u16>().unwrap(), 413u16);
+ assert_eq!(*any.downcast::<u16>().unwrap(), 413u16);
}
Ok(()) => fail!()
}
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::mem;
pub use core::atomics::{AtomicBool, AtomicInt, AtomicUint, AtomicPtr};
use core::prelude::*;
use alloc::arc::Arc;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::cell::Cell;
use core::kinds::marker;
use core::mem;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::mem;
use rustrt::local::Local;
use rustrt::task::{Task, BlockedTask};
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::cell::Cell;
use core::kinds::marker;
use core::mem;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::cmp;
use core::int;
use rustrt::local::Local;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::cmp;
use core::int;
use rustrt::local::Local;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use collections::Vec;
use collections::Collection;
use core::mem;
use alloc::arc::Arc;
use alloc::heap::{allocate, deallocate};
-use alloc::owned::Box;
+use alloc::boxed::Box;
use collections::Vec;
use core::kinds::marker;
use core::mem::{forget, min_align_of, size_of, transmute};
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::mem;
use core::ty::Unsafe;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::atomics;
use core::kinds::marker;
use core::mem;
use core::prelude::*;
-use alloc::owned::Box;
+use alloc::boxed::Box;
use core::mem;
use core::ty::Unsafe;
// Tests that the new `box` syntax works with unique pointers and GC pointers.
use std::gc::{Gc, GC};
-use std::owned::{Box, HEAP};
+use std::boxed::{Box, HEAP};
pub fn main() {
let x: Gc<int> = box(HEAP) 2; //~ ERROR mismatched types
// Tests that the new `box` syntax works with unique pointers and GC pointers.
use std::gc::{Gc, GC};
-use std::owned::{Box, HEAP};
+use std::boxed::{Box, HEAP};
struct Structure {
x: int,
let c = box()(3i + 4);
let d = box(GC)(5i + 6);
}
-
// Make sure the destructor is run for unit-like structs.
-use std::owned::AnyOwnExt;
+use std::boxed::BoxAny;
use std::task;
struct Foo;
let _b = Foo;
});
- let s = x.unwrap_err().move::<&'static str>().unwrap();
+ let s = x.unwrap_err().downcast::<&'static str>().unwrap();
assert_eq!(s.as_slice(), "This failure should happen.");
}