diff --git a/src/features/impl_alloc.rs b/src/features/impl_alloc.rs index 4a1889e1..4ed00f8e 100644 --- a/src/features/impl_alloc.rs +++ b/src/features/impl_alloc.rs @@ -25,10 +25,10 @@ pub(crate) struct VecWriter { impl VecWriter { /// Create a new vec writer with the given capacity - pub fn with_capacity(cap: usize) -> Self { - Self { - inner: Vec::with_capacity(cap), - } + pub fn with_capacity(cap: usize) -> Result { + let mut inner = Vec::new(); + inner.try_reserve(cap)?; + Ok(Self { inner }) } // May not be used in all feature combinations #[allow(dead_code)] @@ -57,7 +57,7 @@ pub fn encode_to_vec(val: E, config: C) -> Result::new(writer, config); val.encode(&mut encoder)?; Ok(encoder.into_writer().inner) @@ -453,6 +453,8 @@ where } } +// TODO +// Vec does not implement Into for Box<[T]> because it allocates again impl Decode for Box<[T]> where T: Decode + 'static, @@ -465,7 +467,6 @@ where // TODO // Vec does not implement Into for Box<[T]> because it allocates again -// we could do this manually with `Box::try_new_uninit` #[cfg(not(feature = "unstable-strict-oom-checks"))] impl<'de, T> BorrowDecode<'de> for Box<[T]> where