--- /dev/null
+ // Copyright 2014 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 module for working with borrowed data.
+
+ #![stable(feature = "rust1", since = "1.0.0")]
+
+ use core::clone::Clone;
+ use core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
+ use core::hash::{Hash, Hasher};
+ use core::marker::Sized;
+ use core::ops::Deref;
+ use core::option::Option;
+
+ use fmt;
+ use alloc::{rc, arc};
+
+ use self::Cow::*;
+
+ /// A trait for borrowing data.
+ ///
+ /// In general, there may be several ways to "borrow" a piece of data. The
+ /// typical ways of borrowing a type `T` are `&T` (a shared borrow) and `&mut T`
+ /// (a mutable borrow). But types like `Vec<T>` provide additional kinds of
+ /// borrows: the borrowed slices `&[T]` and `&mut [T]`.
+ ///
+ /// When writing generic code, it is often desirable to abstract over all ways
+ /// of borrowing data from a given type. That is the role of the `Borrow`
+ /// trait: if `T: Borrow<U>`, then `&U` can be borrowed from `&T`. A given
+ /// type can be borrowed as multiple different types. In particular, `Vec<T>:
+ /// Borrow<Vec<T>>` and `Vec<T>: Borrow<[T]>`.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ pub trait Borrow<Borrowed: ?Sized> {
+ /// Immutably borrow from an owned value.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn borrow(&self) -> &Borrowed;
+ }
+
+ /// A trait for mutably borrowing data.
+ ///
+ /// Similar to `Borrow`, but for mutable borrows.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ pub trait BorrowMut<Borrowed: ?Sized> : Borrow<Borrowed> {
+ /// Mutably borrow from an owned value.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn borrow_mut(&mut self) -> &mut Borrowed;
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<T: ?Sized> Borrow<T> for T {
+ fn borrow(&self) -> &T { self }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<T: ?Sized> BorrowMut<T> for T {
+ fn borrow_mut(&mut self) -> &mut T { self }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, T: ?Sized> Borrow<T> for &'a T {
+ fn borrow(&self) -> &T { &**self }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, T: ?Sized> Borrow<T> for &'a mut T {
+ fn borrow(&self) -> &T { &**self }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, T: ?Sized> BorrowMut<T> for &'a mut T {
+ fn borrow_mut(&mut self) -> &mut T { &mut **self }
+ }
+
+ impl<T> Borrow<T> for rc::Rc<T> {
+ fn borrow(&self) -> &T { &**self }
+ }
+
+ impl<T> Borrow<T> for arc::Arc<T> {
+ fn borrow(&self) -> &T { &**self }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B> where B: ToOwned, <B as ToOwned>::Owned: 'a {
+ fn borrow(&self) -> &B {
+ &**self
+ }
+ }
+
+ /// A generalization of Clone to borrowed data.
+ ///
+ /// Some types make it possible to go from borrowed to owned, usually by
+ /// implementing the `Clone` trait. But `Clone` works only for going from `&T`
+ /// to `T`. The `ToOwned` trait generalizes `Clone` to construct owned data
+ /// from any borrow of a given type.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ pub trait ToOwned {
+ #[stable(feature = "rust1", since = "1.0.0")]
+ type Owned: Borrow<Self>;
+
+ /// Create owned data from borrowed data, usually by copying.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn to_owned(&self) -> Self::Owned;
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<T> ToOwned for T where T: Clone {
+ type Owned = T;
+ fn to_owned(&self) -> T { self.clone() }
+ }
+
+ /// A clone-on-write smart pointer.
+ ///
+ /// The type `Cow` is a smart pointer providing clone-on-write functionality: it
+ /// can enclose and provide immutable access to borrowed data, and clone the
+ /// data lazily when mutation or ownership is required. The type is designed to
+ /// work with general borrowed data via the `Borrow` trait.
+ ///
+ /// `Cow` implements both `Deref`, which means that you can call
+ /// non-mutating methods directly on the data it encloses. If mutation
+ /// is desired, `to_mut` will obtain a mutable references to an owned
+ /// value, cloning if necessary.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// use std::borrow::Cow;
+ ///
+ /// fn abs_all(input: &mut Cow<[int]>) {
+ /// for i in 0..input.len() {
+ /// let v = input[i];
+ /// if v < 0 {
+ /// // clones into a vector the first time (if not already owned)
+ /// input.to_mut()[i] = -v;
+ /// }
+ /// }
+ /// }
+ /// ```
+ #[stable(feature = "rust1", since = "1.0.0")]
+ pub enum Cow<'a, B: ?Sized + 'a> where B: ToOwned {
+ /// Borrowed data.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ Borrowed(&'a B),
+
+ /// Owned data.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ Owned(<B as ToOwned>::Owned)
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> Clone for Cow<'a, B> where B: ToOwned {
+ fn clone(&self) -> Cow<'a, B> {
+ match *self {
+ Borrowed(b) => Borrowed(b),
+ Owned(ref o) => {
+ let b: &B = o.borrow();
+ Owned(b.to_owned())
+ },
+ }
+ }
+ }
+
+ impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
+ /// Acquire a mutable reference to the owned form of the data.
+ ///
+ /// Copies the data if it is not already owned.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ pub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned {
+ match *self {
+ Borrowed(borrowed) => {
+ *self = Owned(borrowed.to_owned());
+ self.to_mut()
+ }
+ Owned(ref mut owned) => owned
+ }
+ }
+
+ /// Extract the owned data.
+ ///
+ /// Copies the data if it is not already owned.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ pub fn into_owned(self) -> <B as ToOwned>::Owned {
+ match self {
+ Borrowed(borrowed) => borrowed.to_owned(),
+ Owned(owned) => owned
+ }
+ }
+
+ /// Returns true if this `Cow` wraps a borrowed value
+ #[deprecated(since = "1.0.0", reason = "match on the enum instead")]
+ #[unstable(feature = "std_misc")]
+ pub fn is_borrowed(&self) -> bool {
+ match *self {
+ Borrowed(_) => true,
+ _ => false,
+ }
+ }
+
+ /// Returns true if this `Cow` wraps an owned value
+ #[deprecated(since = "1.0.0", reason = "match on the enum instead")]
+ #[unstable(feature = "std_misc")]
+ pub fn is_owned(&self) -> bool {
+ match *self {
+ Owned(_) => true,
+ _ => false,
+ }
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> Deref for Cow<'a, B> where B: ToOwned {
+ type Target = B;
+
+ fn deref(&self) -> &B {
+ match *self {
+ Borrowed(borrowed) => borrowed,
+ Owned(ref owned) => owned.borrow()
+ }
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> Eq for Cow<'a, B> where B: Eq + ToOwned {}
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> Ord for Cow<'a, B> where B: Ord + ToOwned {
+ #[inline]
+ fn cmp(&self, other: &Cow<'a, B>) -> Ordering {
+ Ord::cmp(&**self, &**other)
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B> where
+ B: PartialEq<C> + ToOwned, C: ToOwned,
+ {
+ #[inline]
+ fn eq(&self, other: &Cow<'b, C>) -> bool {
+ PartialEq::eq(&**self, &**other)
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> PartialOrd for Cow<'a, B> where B: PartialOrd + ToOwned,
+ {
+ #[inline]
+ fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering> {
+ PartialOrd::partial_cmp(&**self, &**other)
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B> where
+ B: fmt::Debug + ToOwned,
+ <B as ToOwned>::Owned: fmt::Debug,
+ {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ Borrowed(ref b) => fmt::Debug::fmt(b, f),
+ Owned(ref o) => fmt::Debug::fmt(o, f),
+ }
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> fmt::Display for Cow<'a, B> where
+ B: fmt::Display + ToOwned,
+ <B as ToOwned>::Owned: fmt::Display,
+ {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ Borrowed(ref b) => fmt::Display::fmt(b, f),
+ Owned(ref o) => fmt::Display::fmt(o, f),
+ }
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
++#[cfg(stage0)]
+ impl<'a, B: ?Sized, S: Hasher> Hash<S> for Cow<'a, B> where B: Hash<S> + ToOwned
+ {
+ #[inline]
+ fn hash(&self, state: &mut S) {
+ Hash::hash(&**self, state)
+ }
+ }
++#[stable(feature = "rust1", since = "1.0.0")]
++#[cfg(not(stage0))]
++impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned
++{
++ #[inline]
++ fn hash<H: Hasher>(&self, state: &mut H) {
++ Hash::hash(&**self, state)
++ }
++}
+
+ /// Trait for moving into a `Cow`
+ #[stable(feature = "rust1", since = "1.0.0")]
+ pub trait IntoCow<'a, B: ?Sized> where B: ToOwned {
+ /// Moves `self` into `Cow`
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn into_cow(self) -> Cow<'a, B>;
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
+ fn into_cow(self) -> Cow<'a, B> {
+ self
+ }
+ }
use core::{iter, fmt, mem};
use Bound::{self, Included, Excluded, Unbounded};
-use ring_buf::RingBuf;
+ use borrow::Borrow;
+use vec_deque::VecDeque;
use self::Continuation::{Continue, Finished};
use self::StackOp::*;
pub mod vec;
pub mod vec_map;
+ #[cfg(stage0)]
+ #[path = "borrow_stage0.rs"]
+ pub mod borrow;
+
+ #[cfg(not(stage0))]
+ pub mod borrow;
+
#[unstable(feature = "collections",
reason = "RFC 509")]
-pub mod bitv {
- pub use bit::{Bitv, Iter};
+pub mod bit_vec {
+ pub use bit::{BitVec, Iter};
+
+ #[deprecated(since = "1.0.0", reason = "renamed to BitVec")]
+ #[unstable(feature = "collections")]
+ pub use bit::BitVec as Bitv;
}
#[unstable(feature = "collections",
use core::str as core_str;
use unicode::str::{UnicodeStr, Utf16Encoder};
-use ring_buf::RingBuf;
+use vec_deque::VecDeque;
+ use borrow::{Borrow, ToOwned};
use slice::SliceExt;
use string::String;
use unicode;
// Clone-on-write
////////////////////////////////////////////////////////////////////////////////
- #[unstable(feature = "collections",
- reason = "unclear how valuable this alias is")]
/// A clone-on-write vector
- pub type CowVec<'a, T> = Cow<'a, Vec<T>, [T]>;
+ #[deprecated(since = "1.0.0", reason = "use Cow<'a, [T]> instead")]
+ #[unstable(feature = "collections")]
+ pub type CowVec<'a, T> = Cow<'a, [T]>;
#[unstable(feature = "collections")]
- impl<'a, T> FromIterator<T> for CowVec<'a, T> where T: Clone {
- fn from_iter<I: IntoIterator<Item=T>>(it: I) -> CowVec<'a, T> {
+ impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
- fn from_iter<I: Iterator<Item=T>>(it: I) -> CowVec<'a, T> {
++ fn from_iter<I: IntoIterator<Item=T>>(it: I) -> Cow<'a, [T]> {
Cow::Owned(FromIterator::from_iter(it))
}
}
//! assert_eq!(hash::<_, SipHasher>(&person1), hash::<_, SipHasher>(&person2));
//! ```
-#![unstable(feature = "hash",
- reason = "module was recently redesigned")]
+#![stable(feature = "rust1", since = "1.0.0")]
+ use prelude::*;
+
use default::Default;
- use marker::Sized;
use mem;
-use num::Int;
pub use self::sip::SipHasher;
}
}
-impl<S: Writer + Hasher, T> Hash<S> for *mut T {
- #[inline]
- fn hash(&self, state: &mut S) {
- // NB: raw-pointer Hash does _not_ dereference
- // to the target; it just gives you the pointer-bytes.
- (*self as uint).hash(state);
+#[cfg(not(stage0))]
+mod impls {
+ use prelude::*;
+
+ use borrow::{Cow, ToOwned};
+ use slice;
+ use super::*;
+
+ macro_rules! impl_write {
+ ($(($ty:ident, $meth:ident),)*) => {$(
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl Hash for $ty {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ state.$meth(*self)
+ }
+
+ fn hash_slice<H: Hasher>(data: &[$ty], state: &mut H) {
+ let newlen = data.len() * ::$ty::BYTES;
+ let ptr = data.as_ptr() as *const u8;
+ state.write(unsafe { slice::from_raw_parts(ptr, newlen) })
+ }
+ }
+ )*}
}
-
- impl_write! {
- (u8, write_u8),
- (u16, write_u16),
- (u32, write_u32),
- (u64, write_u64),
- (usize, write_usize),
- (i8, write_i8),
- (i16, write_i16),
- (i32, write_i32),
- (i64, write_i64),
- (isize, write_isize),
- }
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl Hash for bool {
- fn hash<H: Hasher>(&self, state: &mut H) {
- state.write_u8(*self as u8)
- }
- }
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl Hash for char {
- fn hash<H: Hasher>(&self, state: &mut H) {
- state.write_u32(*self as u32)
- }
- }
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl Hash for str {
- fn hash<H: Hasher>(&self, state: &mut H) {
- state.write(self.as_bytes());
- state.write_u8(0xff)
- }
- }
-
- macro_rules! impl_hash_tuple {
- () => (
- #[stable(feature = "rust1", since = "1.0.0")]
- impl Hash for () {
- fn hash<H: Hasher>(&self, _state: &mut H) {}
- }
- );
-
- ( $($name:ident)+) => (
- #[stable(feature = "rust1", since = "1.0.0")]
- impl<$($name: Hash),*> Hash for ($($name,)*) {
- #[allow(non_snake_case)]
- fn hash<S: Hasher>(&self, state: &mut S) {
- let ($(ref $name,)*) = *self;
- $($name.hash(state);)*
- }
- }
- );
- }
-
- impl_hash_tuple! {}
- impl_hash_tuple! { A }
- impl_hash_tuple! { A B }
- impl_hash_tuple! { A B C }
- impl_hash_tuple! { A B C D }
- impl_hash_tuple! { A B C D E }
- impl_hash_tuple! { A B C D E F }
- impl_hash_tuple! { A B C D E F G }
- impl_hash_tuple! { A B C D E F G H }
- impl_hash_tuple! { A B C D E F G H I }
- impl_hash_tuple! { A B C D E F G H I J }
- impl_hash_tuple! { A B C D E F G H I J K }
- impl_hash_tuple! { A B C D E F G H I J K L }
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl<T: Hash> Hash for [T] {
- fn hash<H: Hasher>(&self, state: &mut H) {
- self.len().hash(state);
- Hash::hash_slice(self, state)
- }
- }
-
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl<'a, T: ?Sized + Hash> Hash for &'a T {
- fn hash<H: Hasher>(&self, state: &mut H) {
- (**self).hash(state);
- }
- }
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl<'a, T: ?Sized + Hash> Hash for &'a mut T {
- fn hash<H: Hasher>(&self, state: &mut H) {
- (**self).hash(state);
- }
- }
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl<T> Hash for *const T {
- fn hash<H: Hasher>(&self, state: &mut H) {
- state.write_usize(*self as usize)
- }
- }
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl<T> Hash for *mut T {
- fn hash<H: Hasher>(&self, state: &mut H) {
- state.write_usize(*self as usize)
- }
- }
-
- #[stable(feature = "rust1", since = "1.0.0")]
- impl<'a, T, B: ?Sized> Hash for Cow<'a, T, B>
- where B: Hash + ToOwned<T>
- {
- fn hash<H: Hasher>(&self, state: &mut H) {
- Hash::hash(&**self, state)
- }
- }
}
self.ty.sty.hash(s)
}
}
+#[cfg(not(stage0))]
+impl<'tcx> Hash for InternedTy<'tcx> {
+ fn hash<H: Hasher>(&self, s: &mut H) {
+ self.ty.sty.hash(s)
+ }
+}
- impl<'tcx> BorrowFrom<InternedTy<'tcx>> for sty<'tcx> {
- fn borrow_from<'a>(ty: &'a InternedTy<'tcx>) -> &'a sty<'tcx> {
- &ty.ty.sty
+ impl<'tcx> Borrow<sty<'tcx>> for InternedTy<'tcx> {
+ fn borrow<'a>(&'a self) -> &'a sty<'tcx> {
+ &self.ty.sty
}
}
/// If you already have the hash for the key lying around, use
/// search_hashed.
fn search<'a, Q: ?Sized>(&'a self, q: &Q) -> Option<FullBucketImm<'a, K, V>>
- where Q: BorrowFrom<K> + Eq + Hash
- where K: Borrow<Q>, Q: Eq + Hash<H>
++ where K: Borrow<Q>, Q: Eq + Hash
{
let hash = self.make_hash(q);
- search_hashed(&self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k)))
+ search_hashed(&self.table, hash, |k| q.eq(k.borrow()))
.into_option()
}
fn search_mut<'a, Q: ?Sized>(&'a mut self, q: &Q) -> Option<FullBucketMut<'a, K, V>>
- where Q: BorrowFrom<K> + Eq + Hash
- where K: Borrow<Q>, Q: Eq + Hash<H>
++ where K: Borrow<Q>, Q: Eq + Hash
{
let hash = self.make_hash(q);
- search_hashed(&mut self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k)))
+ search_hashed(&mut self.table, hash, |k| q.eq(k.borrow()))
.into_option()
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
- where Q: Hash + Eq + BorrowFrom<K>
- where K: Borrow<Q>, Q: Hash<H> + Eq
++ where K: Borrow<Q>, Q: Hash + Eq
{
self.search(k).map(|bucket| bucket.into_refs().1)
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
- where Q: Hash + Eq + BorrowFrom<K>
- where K: Borrow<Q>, Q: Hash<H> + Eq
++ where K: Borrow<Q>, Q: Hash + Eq
{
self.search(k).is_some()
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
- where Q: Hash + Eq + BorrowFrom<K>
- where K: Borrow<Q>, Q: Hash<H> + Eq
++ where K: Borrow<Q>, Q: Hash + Eq
{
self.search_mut(k).map(|bucket| bucket.into_mut_refs().1)
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
- where Q: Hash + Eq + BorrowFrom<K>
- where K: Borrow<Q>, Q: Hash<H> + Eq
++ where K: Borrow<Q>, Q: Hash + Eq
{
if self.table.size() == 0 {
return None
}
#[stable(feature = "rust1", since = "1.0.0")]
-impl<K, Q: ?Sized, V, S, H> Index<Q> for HashMap<K, V, S>
- where K: Eq + Hash<H> + Borrow<Q>,
- Q: Eq + Hash<H>,
- S: HashState<Hasher=H>,
- H: hash::Hasher<Output=u64>
+impl<K, Q: ?Sized, V, S> Index<Q> for HashMap<K, V, S>
- where K: Eq + Hash,
- Q: Eq + Hash + BorrowFrom<K>,
++ where K: Eq + Hash + Borrow<Q>,
++ Q: Eq + Hash,
+ S: HashState,
{
type Output = V;
}
#[stable(feature = "rust1", since = "1.0.0")]
-impl<K, V, S, H, Q: ?Sized> IndexMut<Q> for HashMap<K, V, S>
- where K: Eq + Hash<H> + Borrow<Q>,
- Q: Eq + Hash<H>,
- S: HashState<Hasher=H>,
- H: hash::Hasher<Output=u64>
+impl<K, V, S, Q: ?Sized> IndexMut<Q> for HashMap<K, V, S>
- where K: Eq + Hash,
- Q: Eq + Hash + BorrowFrom<K>,
++ where K: Eq + Hash + Borrow<Q>,
++ Q: Eq + Hash,
+ S: HashState,
{
#[inline]
fn index_mut<'a>(&'a mut self, index: &Q) -> &'a mut V {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
- where Q: BorrowFrom<T> + Hash + Eq
- where T: Borrow<Q>, Q: Hash<H> + Eq
++ where T: Borrow<Q>, Q: Hash + Eq
{
self.map.contains_key(value)
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
- where Q: BorrowFrom<T> + Hash + Eq
- where T: Borrow<Q>, Q: Hash<H> + Eq
++ where T: Borrow<Q>, Q: Hash + Eq
{
self.map.remove(value).is_some()
}
use core::prelude::*;
use ascii::*;
- use borrow::BorrowFrom;
+ use borrow::{Borrow, ToOwned, Cow};
use cmp;
-use iter;
+use iter::{self, IntoIterator};
use mem;
use ops::{self, Deref};
- use string::CowString;
use vec::Vec;
use fmt;
self.vect.borrow().len()
}
+ #[cfg(stage0)]
pub fn find<Q: ?Sized>(&self, val: &Q) -> Option<Name>
- where Q: BorrowFrom<RcStr> + Eq + Hash<Hasher> {
+ where RcStr: Borrow<Q>, Q: Eq + Hash<Hasher> {
match (*self.map.borrow()).get(val) {
Some(v) => Some(*v),
None => None,
use std::mem::size_of;
static uni: &'static str = "Les Miséééééééérables";
-static yy: usize = 25us;
+static yy: usize = 25;
- static bob: Option<std::vec::CowVec<'static, isize>> = None;
+ static bob: Option<std::borrow::Cow<'static, [isize]>> = None;
// buglink test - see issue #1337.