diff options
| author | Aaron Turon <aturon@mozilla.com> | 2015-02-11 23:16:32 -0800 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2015-02-18 15:23:58 -0800 |
| commit | a99e698628cbd396c8100ef776d10ac61d911847 (patch) | |
| tree | 889679e9690bbb6303f75abfb9bdd0ec4beedfcc /src/libsyntax | |
| parent | 9bb3b3772d4be69b0f619bd9456255a9e3bc7d9e (diff) | |
| download | rust-a99e698628cbd396c8100ef776d10ac61d911847.tar.gz rust-a99e698628cbd396c8100ef776d10ac61d911847.zip | |
Stabilize std::borrow
This commit stabilizes `std::borrow`, making the following modifications to catch up the API with language changes: * It renames `BorrowFrom` to `Borrow`, as was originally intended (but blocked for technical reasons), and reorders the parameters accordingly. * It moves the type parameter of `ToOwned` to an associated type. This is somewhat less flexible, in that each borrowed type must have a unique owned type, but leads to a significant simplification for `Cow`. Flexibility can be regained by using newtyped slices, which is advisable for other reasons anyway. * It removes the owned type parameter from `Cow`, making the type much less verbose. * Deprecates the `is_owned` and `is_borrowed` predicates in favor of direct matching. The above API changes are relatively minor; the basic functionality remains the same, and essentially the whole module is now marked `#[stable]`. [breaking-change]
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/util/interner.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 51144267519..5236122f585 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -14,7 +14,7 @@ use ast::Name; -use std::borrow::BorrowFrom; +use std::borrow::Borrow; use std::cell::RefCell; use std::cmp::Ordering; use std::collections::HashMap; @@ -79,7 +79,7 @@ impl<T: Eq + Hash<Hasher> + Clone + 'static> Interner<T> { } pub fn find<Q: ?Sized>(&self, val: &Q) -> Option<Name> - where Q: BorrowFrom<T> + Eq + Hash<Hasher> { + where T: Borrow<Q>, Q: Eq + Hash<Hasher> { let map = self.map.borrow(); match (*map).get(val) { Some(v) => Some(*v), @@ -128,9 +128,9 @@ impl fmt::Display for RcStr { } } -impl BorrowFrom<RcStr> for str { - fn borrow_from(owned: &RcStr) -> &str { - &owned.string[] +impl Borrow<str> for RcStr { + fn borrow(&self) -> &str { + &self.string[] } } @@ -211,7 +211,7 @@ impl StrInterner { } 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, |
