Skip to content

Commit d474649

Browse files
Remove outdated APIs
1 parent 83f1cb7 commit d474649

File tree

1 file changed

+1
-73
lines changed

1 file changed

+1
-73
lines changed

src/lib.rs

+1-73
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<const N: usize> TryFrom<&[u8]> for Bytes<N> {
5656
impl<const N: usize> Bytes<N> {
5757
/// Construct a new, empty `Bytes<N>`.
5858
pub fn new() -> Self {
59-
Self { bytes: Vec::new() }
59+
Bytes::from(Vec::new())
6060
}
6161

6262
pub fn as_ptr(&self) -> *const u8 {
@@ -282,78 +282,6 @@ impl<const N: usize> Bytes<N> {
282282
pub fn retain_mut(&mut self, f: impl FnMut(&mut u8) -> bool) {
283283
self.bytes.retain_mut(f)
284284
}
285-
}
286-
287-
impl<const N: usize> Bytes<N> {
288-
// /// Some APIs offer an interface of the form `f(&mut [u8]) -> Result<usize, E>`,
289-
// /// with the contract that the Ok-value signals how many bytes were written.
290-
// ///
291-
// /// This constructor allows wrapping such interfaces in a more ergonomic way,
292-
// /// returning a Bytes willed using `f`.
293-
// ///
294-
// /// It seems it's not possible to do this as an actual `TryFrom` implementation.
295-
// pub fn from_constructor<E>(
296-
// f: impl FnOnce(&mut [u8]) -> core::result::Result<usize, E>,
297-
// ) -> core::result::Result<Self, E> {
298-
// let mut data = Self::new();
299-
// data.resize_to_capacity();
300-
// let result = f(&mut data);
301-
302-
// result.map(|count| {
303-
// data.resize_default(count)
304-
// .expect("Contructor returned size larger than capacity");
305-
// data
306-
// })
307-
// }
308-
309-
// cf. https://internals.rust-lang.org/t/add-vec-insert-slice-at-to-insert-the-content-of-a-slice-at-an-arbitrary-index/11008/3
310-
pub fn insert_slice_at(&mut self, slice: &[u8], at: usize) -> core::result::Result<(), ()> {
311-
let l = slice.len();
312-
let before = self.len();
313-
314-
// make space
315-
self.bytes.resize_default(before + l)?;
316-
317-
// move back existing
318-
let raw: &mut [u8] = &mut self.bytes;
319-
raw.copy_within(at..before, at + l);
320-
321-
// insert slice
322-
raw[at..][..l].copy_from_slice(slice);
323-
324-
Ok(())
325-
}
326-
327-
// pub fn insert(&mut self, index: usize, item: u8) -> Result<(), u8> {
328-
// self.insert_slice_at(&[item], index).map_err(|_| item)
329-
// }
330-
331-
// pub fn remove(&mut self, index: usize) -> Result<u8, ()> {
332-
// if index < self.len() {
333-
// unsafe { Ok(self.remove_unchecked(index)) }
334-
// } else {
335-
// Err(())
336-
// }
337-
// }
338-
339-
// pub(crate) unsafe fn remove_unchecked(&mut self, index: usize) -> u8 {
340-
// // the place we are taking from.
341-
// let p = self.bytes.as_mut_ptr().add(index);
342-
343-
// // copy it out, unsafely having a copy of the value on
344-
// // the stack and in the vector at the same time.
345-
// let ret = ptr::read(p);
346-
347-
// // shift everything down to fill in that spot.
348-
// ptr::copy(p.offset(1), p, self.len() - index - 1);
349-
350-
// self.resize_default(self.len() - 1).unwrap();
351-
// ret
352-
// }
353-
354-
pub fn resize_default(&mut self, new_len: usize) -> core::result::Result<(), ()> {
355-
self.bytes.resize_default(new_len)
356-
}
357285

358286
pub fn resize_to_capacity(&mut self) {
359287
self.bytes.resize_default(self.bytes.capacity()).ok();

0 commit comments

Comments
 (0)