title: Expanding a VecDeque to limit size
body: <p>I want to implement a VecDeque with a maximum size limit. I have two strategies but I can't complete either.</p>
  <p>First approach: Inheritance by composition.</p>
  <p>I Created a new struct:</p>
  <pre><code>pub struct LimVecDeque&lt;T&gt; {                                                                                                    
       deque: VecDeque&lt;T&gt;,                                                 
       limit: usize,                                                       
  }
  
  </code></pre>
  <p>And create a new push function:</p>
  <pre><code>impl&lt;T&gt; LimVecDeque&lt;T&gt; {
    ...
  
    pub fn push (&amp;self, elem: T) {
      self.deque.push_back(elem);
      if self.limit &lt; self.deque.len() {
        self.deque.pop_front();
      }
    }
  
    ...
  }
  </code></pre>
  <p>This works but, as my program grow up, I require to add functionality to my LimVecDeque Struct. Most of them is a copy from the original VecDeque:</p>
  <pre><code>pub fn len(&amp;self) -&gt; usize {
    self.deque.len()
  }
  </code></pre>
  <p>I have more problems to export VecDeque::iter(). I had problems with types and iterators (I'm not very good with iterators yet).
  This approach forces me to clone/export each function in VecDeque into LimVecDeque. Lot of work!</p>
  <p>Second Approach: Create a new trait and implement for VecDeque:</p>
  <pre><code>trait Limited {
    type Elem;
  
    pub fn push_bounded(&amp;self, limit: usize, elem: Elem);
  }
  </code></pre>
  <p>and later impl the trait with VecDeque.</p>
  <p>But I have to pass <code>limit</code> value in each insertion. How can pass limit value once?</p>
  <p>In general, What is an easy way to add functionality to an struct from std (without loosing/hiding current ones)?</p>