]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/ptr.rs
Rollup merge of #68141 - euclio:replace-bindings-with-winapi, r=alexcrichton
[rust.git] / src / libsyntax / ptr.rs
index e75cc8b1756d15cbac9260e0ee2066cedad00ebc..4597624ef88b08d21f55c6d55bac50f39709494b 100644 (file)
 //!   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 @@ pub fn into_inner(self) -> 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 @@ pub fn map<F>(mut self, f: F) -> P<T> where
     }
 
     /// 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 @@ fn into(self) -> Vec<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 @@ fn decode<D: Decoder>(d: &mut D) -> Result<P<[T]>, D::Error> {
 }
 
 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);