brotli_decompressor/
brotli_alloc.rs

1#![cfg(feature="std")]
2use core;
3use core::ops;
4use std::boxed::Box;
5use std::vec::Vec;
6pub struct WrapBox<T> {
7   v : Vec<T>,
8}
9
10impl<T> core::default::Default for WrapBox<T> {
11    fn default() -> Self {
12       let v : Vec<T> = Vec::new();
13       return WrapBox::<T>{v : v};
14    }
15}
16
17impl<T> ops::Index<usize> for WrapBox<T>{
18    type Output = T;
19    fn index(&self, index : usize) -> &T {
20        return &self.v[index]
21    }
22}
23
24impl<T> ops::IndexMut<usize> for WrapBox<T>{
25    fn index_mut(&mut self, index : usize) -> &mut T {
26        return &mut self.v[index]
27    }
28}
29
30impl<T> super::SliceWrapper<T> for WrapBox<T> {
31    fn slice(&self) -> & [T] {
32       return &self.v[..]
33    }
34}
35
36impl<T> super::SliceWrapperMut<T> for WrapBox<T> {
37    fn slice_mut(&mut self) -> &mut [T] {
38       return &mut self.v[..]
39    }
40}
41
42pub struct BrotliAlloc<T : core::clone::Clone>{
43   pub default_value : T,
44}
45impl<T : core::clone::Clone+Default> BrotliAlloc<T> {
46   pub fn new() -> BrotliAlloc<T> {
47      return BrotliAlloc::<T>{default_value : T::default()};
48   }
49   pub fn take_ownership(&self, data: Vec<T>) -> WrapBox<T>{
50      WrapBox::<T>{v:data}
51   }
52}
53
54impl<T : core::clone::Clone> super::Allocator<T> for BrotliAlloc<T> {
55   type AllocatedMemory = WrapBox<T>;
56   fn alloc_cell(self : &mut BrotliAlloc<T>, len : usize) -> WrapBox<T> {
57
58       let v : Vec<T> = vec![self.default_value.clone();len];
59       return WrapBox::<T>{v : v};
60   }
61   fn free_cell(self : &mut BrotliAlloc<T>, _data : WrapBox<T>) {}
62}