//! 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)
}
/// 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);
}
/// 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)?;
}
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())
}
}
}
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);