Skip to content

Commit 953302f

Browse files
committed
rollup merge of rust-lang#18707 : japaric/moar-dst
2 parents 2a3f0bb + 5272e6c commit 953302f

File tree

7 files changed

+77
-18
lines changed

7 files changed

+77
-18
lines changed

src/liballoc/boxed.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ impl<T: Default> Default for Box<T> {
4848
fn default() -> Box<T> { box Default::default() }
4949
}
5050

51+
impl<T> Default for Box<[T]> {
52+
fn default() -> Box<[T]> { box [] }
53+
}
54+
5155
#[unstable]
5256
impl<T: Clone> Clone for Box<T> {
5357
/// Returns a copy of the owned box.

src/libserialize/base64.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ static URLSAFE_CHARS: &'static[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
5454
0123456789-_";
5555

5656
/// A trait for converting a value to base64 encoding.
57-
pub trait ToBase64 {
57+
pub trait ToBase64 for Sized? {
5858
/// Converts the value of `self` to a base64 value following the specified
5959
/// format configuration, returning the owned string.
6060
fn to_base64(&self, config: Config) -> String;
6161
}
6262

63-
impl<'a> ToBase64 for &'a [u8] {
63+
impl ToBase64 for [u8] {
6464
/**
6565
* Turn a vector of `u8` bytes into a base64 string.
6666
*
@@ -155,7 +155,7 @@ impl<'a> ToBase64 for &'a [u8] {
155155
}
156156

157157
/// A trait for converting from base64 encoded values.
158-
pub trait FromBase64 {
158+
pub trait FromBase64 for Sized? {
159159
/// Converts the value of `self`, interpreted as base64 encoded data, into
160160
/// an owned vector of bytes, returning the vector.
161161
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error>;
@@ -192,7 +192,7 @@ impl error::Error for FromBase64Error {
192192
}
193193
}
194194

195-
impl<'a> FromBase64 for &'a str {
195+
impl FromBase64 for str {
196196
/**
197197
* Convert any base64 encoded string (literal, `@`, `&`, or `~`)
198198
* to the byte values it encodes.
@@ -227,7 +227,7 @@ impl<'a> FromBase64 for &'a str {
227227
}
228228
}
229229

230-
impl<'a> FromBase64 for &'a [u8] {
230+
impl FromBase64 for [u8] {
231231
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error> {
232232
let mut r = Vec::new();
233233
let mut buf: u32 = 0;

src/libserialize/hex.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ use std::string;
1616
use std::error;
1717

1818
/// A trait for converting a value to hexadecimal encoding
19-
pub trait ToHex {
19+
pub trait ToHex for Sized? {
2020
/// Converts the value of `self` to a hex value, returning the owned
2121
/// string.
2222
fn to_hex(&self) -> String;
2323
}
2424

2525
static CHARS: &'static[u8] = b"0123456789abcdef";
2626

27-
impl<'a> ToHex for &'a [u8] {
27+
impl ToHex for [u8] {
2828
/**
2929
* Turn a vector of `u8` bytes into a hexadecimal string.
3030
*
@@ -54,7 +54,7 @@ impl<'a> ToHex for &'a [u8] {
5454
}
5555

5656
/// A trait for converting hexadecimal encoded values
57-
pub trait FromHex {
57+
pub trait FromHex for Sized? {
5858
/// Converts the value of `self`, interpreted as hexadecimal encoded data,
5959
/// into an owned vector of bytes, returning the vector.
6060
fn from_hex(&self) -> Result<Vec<u8>, FromHexError>;
@@ -92,7 +92,7 @@ impl error::Error for FromHexError {
9292
}
9393

9494

95-
impl<'a> FromHex for &'a str {
95+
impl FromHex for str {
9696
/**
9797
* Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
9898
* to the byte values it encodes.

src/libserialize/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ impl ::Decoder<DecoderError> for Decoder {
23032303
}
23042304

23052305
/// A trait for converting values to JSON
2306-
pub trait ToJson {
2306+
pub trait ToJson for Sized? {
23072307
/// Converts the value of `self` to an instance of JSON
23082308
fn to_json(&self) -> Json;
23092309
}
@@ -2389,7 +2389,7 @@ tuple_impl!{A, B, C, D, E, F, G, H, I, J}
23892389
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K}
23902390
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K, L}
23912391

2392-
impl<'a, A: ToJson> ToJson for &'a [A] {
2392+
impl<A: ToJson> ToJson for [A] {
23932393
fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
23942394
}
23952395

src/libserialize/serialize.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub trait Decoder<E> {
169169
fn error(&mut self, err: &str) -> E;
170170
}
171171

172-
pub trait Encodable<S:Encoder<E>, E> {
172+
pub trait Encodable<S:Encoder<E>, E> for Sized? {
173173
fn encode(&self, s: &mut S) -> Result<(), E>;
174174
}
175175

@@ -297,9 +297,9 @@ impl<E, D:Decoder<E>> Decodable<D, E> for i64 {
297297
}
298298
}
299299

300-
impl<'a, E, S:Encoder<E>> Encodable<S, E> for &'a str {
300+
impl<E, S:Encoder<E>> Encodable<S, E> for str {
301301
fn encode(&self, s: &mut S) -> Result<(), E> {
302-
s.emit_str(*self)
302+
s.emit_str(self)
303303
}
304304
}
305305

@@ -375,24 +375,31 @@ impl<E, D:Decoder<E>> Decodable<D, E> for () {
375375
}
376376
}
377377

378-
impl<'a, E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for &'a T {
378+
impl<'a, E, S: Encoder<E>, Sized? T: Encodable<S, E>> Encodable<S, E> for &'a T {
379379
fn encode(&self, s: &mut S) -> Result<(), E> {
380380
(**self).encode(s)
381381
}
382382
}
383383

384-
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for Box<T> {
384+
impl<E, S: Encoder<E>, Sized? T: Encodable<S, E>> Encodable<S, E> for Box<T> {
385385
fn encode(&self, s: &mut S) -> Result<(), E> {
386386
(**self).encode(s)
387387
}
388388
}
389389

390-
impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for Box<T> {
390+
impl<E, D:Decoder<E>, T: Decodable<D, E>> Decodable<D, E> for Box<T> {
391391
fn decode(d: &mut D) -> Result<Box<T>, E> {
392392
Ok(box try!(Decodable::decode(d)))
393393
}
394394
}
395395

396+
impl<E, D:Decoder<E>, T: Decodable<D, E>> Decodable<D, E> for Box<[T]> {
397+
fn decode(d: &mut D) -> Result<Box<[T]>, E> {
398+
let v: Vec<T> = try!(Decodable::decode(d));
399+
Ok(v.into_boxed_slice())
400+
}
401+
}
402+
396403
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for Rc<T> {
397404
#[inline]
398405
fn encode(&self, s: &mut S) -> Result<(), E> {
@@ -407,7 +414,7 @@ impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for Rc<T> {
407414
}
408415
}
409416

410-
impl<'a, E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for &'a [T] {
417+
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for [T] {
411418
fn encode(&self, s: &mut S) -> Result<(), E> {
412419
s.emit_seq(self.len(), |s| {
413420
for (i, e) in self.iter().enumerate() {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::default::Default;
12+
13+
#[deriving(Default)]
14+
struct A {
15+
foo: Box<[bool]>,
16+
}
17+
18+
pub fn main() {
19+
let a: A = Default::default();
20+
let b: Box<[_]> = box [];
21+
assert_eq!(a.foo, b);
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern crate serialize;
12+
13+
use serialize::{Encodable, Decodable};
14+
use serialize::json;
15+
16+
#[deriving(Encodable, Decodable)]
17+
struct A {
18+
foo: Box<[bool]>,
19+
}
20+
21+
fn main() {
22+
let obj = A { foo: box [true, false] };
23+
let s = json::encode(&obj);
24+
let obj2: A = json::decode(s.as_slice()).unwrap();
25+
assert!(obj.foo == obj2.foo);
26+
}

0 commit comments

Comments
 (0)