|  | 
| 4 | 4 | Core encoding and decoding interfaces. | 
| 5 | 5 | */ | 
| 6 | 6 | 
 | 
|  | 7 | +use std::alloc::Allocator; | 
| 7 | 8 | use std::borrow::Cow; | 
| 8 | 9 | use std::cell::{Cell, RefCell}; | 
| 9 | 10 | use std::marker::PhantomData; | 
| @@ -229,9 +230,9 @@ impl<D: Decoder, T> Decodable<D> for PhantomData<T> { | 
| 229 | 230 |     } | 
| 230 | 231 | } | 
| 231 | 232 | 
 | 
| 232 |  | -impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<[T]> { | 
| 233 |  | -    fn decode(d: &mut D) -> Box<[T]> { | 
| 234 |  | -        let v: Vec<T> = Decodable::decode(d); | 
|  | 233 | +impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<[T], A> { | 
|  | 234 | +    fn decode(d: &mut D) -> Box<[T], A> { | 
|  | 235 | +        let v: Vec<T, A> = Decodable::decode(d); | 
| 235 | 236 |         v.into_boxed_slice() | 
| 236 | 237 |     } | 
| 237 | 238 | } | 
| @@ -264,12 +265,13 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Vec<T> { | 
| 264 | 265 |     } | 
| 265 | 266 | } | 
| 266 | 267 | 
 | 
| 267 |  | -impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> { | 
| 268 |  | -    default fn decode(d: &mut D) -> Vec<T> { | 
|  | 268 | +impl<D: Decoder, T: Decodable<D>, A: Allocator + Default> Decodable<D> for Vec<T, A> { | 
|  | 269 | +    default fn decode(d: &mut D) -> Vec<T, A> { | 
| 269 | 270 |         let len = d.read_usize(); | 
|  | 271 | +        let allocator = A::default(); | 
| 270 | 272 |         // SAFETY: we set the capacity in advance, only write elements, and | 
| 271 | 273 |         // only set the length at the end once the writing has succeeded. | 
| 272 |  | -        let mut vec = Vec::with_capacity(len); | 
|  | 274 | +        let mut vec = Vec::with_capacity_in(len, allocator); | 
| 273 | 275 |         unsafe { | 
| 274 | 276 |             let ptr: *mut T = vec.as_mut_ptr(); | 
| 275 | 277 |             for i in 0..len { | 
| @@ -457,13 +459,15 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<T> { | 
| 457 | 459 |     } | 
| 458 | 460 | } | 
| 459 | 461 | 
 | 
| 460 |  | -impl<S: Encoder, T: ?Sized + Encodable<S>> Encodable<S> for Box<T> { | 
|  | 462 | +impl<S: Encoder, T: ?Sized + Encodable<S>, A: Allocator + Default> Encodable<S> for Box<T, A> { | 
| 461 | 463 |     fn encode(&self, s: &mut S) { | 
| 462 |  | -        (**self).encode(s); | 
|  | 464 | +        (**self).encode(s) | 
| 463 | 465 |     } | 
| 464 | 466 | } | 
| 465 |  | -impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<T> { | 
| 466 |  | -    fn decode(d: &mut D) -> Box<T> { | 
| 467 |  | -        Box::new(Decodable::decode(d)) | 
|  | 467 | + | 
|  | 468 | +impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<T, A> { | 
|  | 469 | +    fn decode(d: &mut D) -> Box<T, A> { | 
|  | 470 | +        let allocator = A::default(); | 
|  | 471 | +        Box::new_in(Decodable::decode(d), allocator) | 
| 468 | 472 |     } | 
| 469 | 473 | } | 
0 commit comments