diff options
Diffstat (limited to 'src/libsyntax/ptr.rs')
| -rw-r--r-- | src/libsyntax/ptr.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index e75cc8b1756..4597624ef88 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -21,31 +21,30 @@ //! implementation changes (using a special thread-local heap, for example). //! Moreover, a switch to, e.g., `P<'a, T>` would be easy and mostly automated. -use std::fmt::{self, Display, Debug}; +use std::fmt::{self, Debug, Display}; use std::iter::FromIterator; use std::ops::{Deref, DerefMut}; use std::{slice, vec}; -use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; -use rustc_data_structures::stable_hasher::{StableHasher, HashStable}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; /// An owned smart pointer. pub struct P<T: ?Sized> { - ptr: Box<T> + ptr: Box<T>, } /// Construct a `P<T>` from a `T` value. #[allow(non_snake_case)] pub fn P<T: 'static>(value: T) -> P<T> { - P { - ptr: box value - } + P { ptr: box value } } impl<T: 'static> P<T> { /// Move out of the pointer. /// Intended for chaining transformations not covered by `map`. - pub fn and_then<U, F>(self, f: F) -> U where + pub fn and_then<U, F>(self, f: F) -> U + where F: FnOnce(T) -> U, { f(*self.ptr) @@ -57,7 +56,8 @@ impl<T: 'static> P<T> { } /// Produce a new `P<T>` from `self` without reallocating. - pub fn map<F>(mut self, f: F) -> P<T> where + pub fn map<F>(mut self, f: F) -> P<T> + where F: FnOnce(T) -> T, { let x = f(*self.ptr); @@ -67,7 +67,8 @@ impl<T: 'static> P<T> { } /// Optionally produce a new `P<T>` from `self` without reallocating. - pub fn filter_map<F>(mut self, f: F) -> Option<P<T>> where + pub fn filter_map<F>(mut self, f: F) -> Option<P<T>> + where F: FnOnce(T) -> Option<T>, { *self.ptr = f(*self.ptr)?; @@ -174,7 +175,7 @@ impl<T> Into<Vec<T>> for P<[T]> { } impl<T> FromIterator<T> for P<[T]> { - fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> P<[T]> { + fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> P<[T]> { P::from_vec(iter.into_iter().collect()) } } @@ -209,7 +210,8 @@ impl<T: Decodable> Decodable for P<[T]> { } impl<CTX, T> HashStable<CTX> for P<T> - where T: ?Sized + HashStable<CTX> +where + T: ?Sized + HashStable<CTX>, { fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); |
