use core::marker::Unsize;
use core::hash::{Hash, Hasher};
use core::{usize, isize};
+use core::convert::From;
use heap::deallocate;
const MAX_REFCOUNT: usize = (isize::MAX) as usize;
}
}
+#[stable(feature = "rust1", since = "1.6.0")]
+impl<T> From<T> for Arc<T> {
+ fn from(t: T) -> Self {
+ Arc::new(t)
+ }
+}
+
+#[stable(feature = "rust1", since = "1.6.0")]
+impl<T> From<Box<T>> for Arc<T> {
+ fn from(t: Box<T>) -> Self {
+ Arc::new(*t)
+ }
+}
+
#[cfg(test)]
mod tests {
+ use std::boxed::Box;
use std::clone::Clone;
use std::sync::mpsc::channel;
use std::mem::drop;
use std::vec::Vec;
use super::{Arc, Weak};
use std::sync::Mutex;
+ use std::convert::From;
struct Canary(*mut atomic::AtomicUsize);
drop(x);
assert!(y.upgrade().is_none());
}
+
+ #[test]
+ fn test_from_owned() {
+ let foo = 123;
+ let foo_arc = Arc::from(foo);
+ assert!(123 == *foo_arc);
+ }
+
+ #[test]
+ fn test_from_box() {
+ let foo_box = Box::new(123);
+ let foo_arc = Arc::from(foo_box);
+ assert!(123 == *foo_arc);
+ }
}
impl<T: ?Sized> borrow::Borrow<T> for Arc<T> {
use core::ops::{Placer, Boxed, Place, InPlace, BoxPlace};
use core::ptr::{self, Unique};
use core::raw::TraitObject;
+use core::convert::From;
/// A value that represents the heap. This is the default place that the `box`
/// keyword allocates into when no place is supplied.
}
}
+#[stable(feature = "rust1", since = "1.6.0")]
+impl<T> From<T> for Box<T> {
+ fn from(t: T) -> Self {
+ Box::new(t)
+ }
+}
+
impl Box<Any> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
use core::mem::{self, align_of_val, size_of_val, forget};
use core::ops::{CoerceUnsized, Deref};
use core::ptr::{self, Shared};
+use core::convert::From;
use heap::deallocate;
}
}
+#[stable(feature = "rust1", since = "1.6.0")]
+impl<T> From<T> for Rc<T> {
+ fn from(t: T) -> Self {
+ Rc::new(t)
+ }
+}
+
+#[stable(feature = "rust1", since = "1.6.0")]
+impl<T> From<Box<T>> for Rc<T> {
+ fn from(t: Box<T>) -> Self {
+ Rc::new(*t)
+ }
+}
+
/// A weak version of `Rc<T>`.
///
/// Weak references do not count when determining if the inner value should be
use std::result::Result::{Err, Ok};
use std::mem::drop;
use std::clone::Clone;
+ use std::convert::From;
#[test]
fn test_clone() {
let foo: Rc<[i32]> = Rc::new([1, 2, 3]);
assert_eq!(foo, foo.clone());
}
+
+ #[test]
+ fn test_from_owned() {
+ let foo = 123;
+ let foo_rc = Rc::from(foo);
+ assert!(123 == *foo_rc);
+ }
+
+ #[test]
+ fn test_from_box() {
+ let foo_box = Box::new(123);
+ let foo_rc = Rc::from(foo_box);
+ assert!(123 == *foo_rc);
+ }
}
impl<T: ?Sized> borrow::Borrow<T> for Rc<T> {