Implement the functionality of a LimitReader in Rust, which wraps around an existing Reader and restricts the number of bytes that can be read from it based on a specified limit. The implementation should abide by the following requirements to ensure that the existing tests pass:
Struct Definition: Define a struct LimitReader<R> with two fields:
limit: A uint that represents the maximum number of bytes that can be read.
inner: A generic type R that implements the Reader trait.
Constructor: Implement a constructor new(r: R, limit: uint) -> LimitReader<R> that initializes a LimitReader with the given reader and limit.
Method Implementations:
into_inner: Implement a method into_inner(self) -> R that consumes the LimitReader and returns the underlying reader.
limit: Implement a method limit(&self) -> uint that returns the current limit on bytes that can still be read.
read: Override the read method from the Reader trait:
If the limit is zero, return an EOF error.
Otherwise, read up to the minimum of the current limit and the buffer length, then update the limit accordingly.
Buffer Trait Implementation: Implement the Buffer trait for LimitReader<R>, which should include the following:
fill_buf: This method should return a slice of data to fill the buffer, limited by the current limit.
consume: Update the consume method to ensure it does not allow the limit to exceed the maximum value.
Testing: Ensure to pass all provided unit tests related to the LimitReader functionality, particularly around reading from a backing reader.
The complete implementation should be located in the /app/ directory.