Skip to main content

core/io/
impls.rs

1use crate::io::{self, Seek, SeekFrom, SizeHint};
2
3// =============================================================================
4// Forwarding implementations
5
6#[doc(hidden)]
7#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
8impl<T> SizeHint for &mut T {
9    #[inline]
10    fn lower_bound(&self) -> usize {
11        SizeHint::lower_bound(*self)
12    }
13
14    #[inline]
15    fn upper_bound(&self) -> Option<usize> {
16        SizeHint::upper_bound(*self)
17    }
18}
19
20#[stable(feature = "rust1", since = "1.0.0")]
21impl<S: Seek + ?Sized> Seek for &mut S {
22    #[inline]
23    fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
24        (**self).seek(pos)
25    }
26
27    #[inline]
28    fn rewind(&mut self) -> io::Result<()> {
29        (**self).rewind()
30    }
31
32    #[inline]
33    fn stream_len(&mut self) -> io::Result<u64> {
34        (**self).stream_len()
35    }
36
37    #[inline]
38    fn stream_position(&mut self) -> io::Result<u64> {
39        (**self).stream_position()
40    }
41
42    #[inline]
43    fn seek_relative(&mut self, offset: i64) -> io::Result<()> {
44        (**self).seek_relative(offset)
45    }
46}
47
48// =============================================================================
49// In-memory buffer implementations
50
51#[doc(hidden)]
52#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
53impl SizeHint for &[u8] {
54    #[inline]
55    fn lower_bound(&self) -> usize {
56        self.len()
57    }
58
59    #[inline]
60    fn upper_bound(&self) -> Option<usize> {
61        Some(self.len())
62    }
63}