Skip to main content

std/io/
impls.rs

1#[cfg(test)]
2mod tests;
3
4use crate::alloc::Allocator;
5use crate::collections::VecDeque;
6use crate::io::{self, BorrowedCursor, BufRead, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
7use crate::sync::Arc;
8use crate::{cmp, fmt, mem, str};
9
10// =============================================================================
11// Forwarding implementations
12
13#[stable(feature = "rust1", since = "1.0.0")]
14impl<R: Read + ?Sized> Read for &mut R {
15    #[inline]
16    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
17        (**self).read(buf)
18    }
19
20    #[inline]
21    fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
22        (**self).read_buf(cursor)
23    }
24
25    #[inline]
26    fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
27        (**self).read_vectored(bufs)
28    }
29
30    #[inline]
31    fn is_read_vectored(&self) -> bool {
32        (**self).is_read_vectored()
33    }
34
35    #[inline]
36    fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
37        (**self).read_to_end(buf)
38    }
39
40    #[inline]
41    fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
42        (**self).read_to_string(buf)
43    }
44
45    #[inline]
46    fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
47        (**self).read_exact(buf)
48    }
49
50    #[inline]
51    fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
52        (**self).read_buf_exact(cursor)
53    }
54}
55#[stable(feature = "rust1", since = "1.0.0")]
56impl<W: Write + ?Sized> Write for &mut W {
57    #[inline]
58    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
59        (**self).write(buf)
60    }
61
62    #[inline]
63    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
64        (**self).write_vectored(bufs)
65    }
66
67    #[inline]
68    fn is_write_vectored(&self) -> bool {
69        (**self).is_write_vectored()
70    }
71
72    #[inline]
73    fn flush(&mut self) -> io::Result<()> {
74        (**self).flush()
75    }
76
77    #[inline]
78    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
79        (**self).write_all(buf)
80    }
81
82    #[inline]
83    fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
84        (**self).write_all_vectored(bufs)
85    }
86
87    #[inline]
88    fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
89        (**self).write_fmt(fmt)
90    }
91}
92#[stable(feature = "rust1", since = "1.0.0")]
93impl<S: Seek + ?Sized> Seek for &mut S {
94    #[inline]
95    fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
96        (**self).seek(pos)
97    }
98
99    #[inline]
100    fn rewind(&mut self) -> io::Result<()> {
101        (**self).rewind()
102    }
103
104    #[inline]
105    fn stream_len(&mut self) -> io::Result<u64> {
106        (**self).stream_len()
107    }
108
109    #[inline]
110    fn stream_position(&mut self) -> io::Result<u64> {
111        (**self).stream_position()
112    }
113
114    #[inline]
115    fn seek_relative(&mut self, offset: i64) -> io::Result<()> {
116        (**self).seek_relative(offset)
117    }
118}
119#[stable(feature = "rust1", since = "1.0.0")]
120impl<B: BufRead + ?Sized> BufRead for &mut B {
121    #[inline]
122    fn fill_buf(&mut self) -> io::Result<&[u8]> {
123        (**self).fill_buf()
124    }
125
126    #[inline]
127    fn consume(&mut self, amt: usize) {
128        (**self).consume(amt)
129    }
130
131    #[inline]
132    fn has_data_left(&mut self) -> io::Result<bool> {
133        (**self).has_data_left()
134    }
135
136    #[inline]
137    fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<usize> {
138        (**self).read_until(byte, buf)
139    }
140
141    #[inline]
142    fn skip_until(&mut self, byte: u8) -> io::Result<usize> {
143        (**self).skip_until(byte)
144    }
145
146    #[inline]
147    fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
148        (**self).read_line(buf)
149    }
150}
151
152#[stable(feature = "rust1", since = "1.0.0")]
153impl<R: Read + ?Sized> Read for Box<R> {
154    #[inline]
155    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
156        (**self).read(buf)
157    }
158
159    #[inline]
160    fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
161        (**self).read_buf(cursor)
162    }
163
164    #[inline]
165    fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
166        (**self).read_vectored(bufs)
167    }
168
169    #[inline]
170    fn is_read_vectored(&self) -> bool {
171        (**self).is_read_vectored()
172    }
173
174    #[inline]
175    fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
176        (**self).read_to_end(buf)
177    }
178
179    #[inline]
180    fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
181        (**self).read_to_string(buf)
182    }
183
184    #[inline]
185    fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
186        (**self).read_exact(buf)
187    }
188
189    #[inline]
190    fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
191        (**self).read_buf_exact(cursor)
192    }
193}
194#[stable(feature = "rust1", since = "1.0.0")]
195impl<W: Write + ?Sized> Write for Box<W> {
196    #[inline]
197    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
198        (**self).write(buf)
199    }
200
201    #[inline]
202    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
203        (**self).write_vectored(bufs)
204    }
205
206    #[inline]
207    fn is_write_vectored(&self) -> bool {
208        (**self).is_write_vectored()
209    }
210
211    #[inline]
212    fn flush(&mut self) -> io::Result<()> {
213        (**self).flush()
214    }
215
216    #[inline]
217    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
218        (**self).write_all(buf)
219    }
220
221    #[inline]
222    fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
223        (**self).write_all_vectored(bufs)
224    }
225
226    #[inline]
227    fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
228        (**self).write_fmt(fmt)
229    }
230}
231#[stable(feature = "rust1", since = "1.0.0")]
232impl<S: Seek + ?Sized> Seek for Box<S> {
233    #[inline]
234    fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
235        (**self).seek(pos)
236    }
237
238    #[inline]
239    fn rewind(&mut self) -> io::Result<()> {
240        (**self).rewind()
241    }
242
243    #[inline]
244    fn stream_len(&mut self) -> io::Result<u64> {
245        (**self).stream_len()
246    }
247
248    #[inline]
249    fn stream_position(&mut self) -> io::Result<u64> {
250        (**self).stream_position()
251    }
252
253    #[inline]
254    fn seek_relative(&mut self, offset: i64) -> io::Result<()> {
255        (**self).seek_relative(offset)
256    }
257}
258#[stable(feature = "rust1", since = "1.0.0")]
259impl<B: BufRead + ?Sized> BufRead for Box<B> {
260    #[inline]
261    fn fill_buf(&mut self) -> io::Result<&[u8]> {
262        (**self).fill_buf()
263    }
264
265    #[inline]
266    fn consume(&mut self, amt: usize) {
267        (**self).consume(amt)
268    }
269
270    #[inline]
271    fn has_data_left(&mut self) -> io::Result<bool> {
272        (**self).has_data_left()
273    }
274
275    #[inline]
276    fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<usize> {
277        (**self).read_until(byte, buf)
278    }
279
280    #[inline]
281    fn skip_until(&mut self, byte: u8) -> io::Result<usize> {
282        (**self).skip_until(byte)
283    }
284
285    #[inline]
286    fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
287        (**self).read_line(buf)
288    }
289}
290
291// =============================================================================
292// In-memory buffer implementations
293
294/// Read is implemented for `&[u8]` by copying from the slice.
295///
296/// Note that reading updates the slice to point to the yet unread part.
297/// The slice will be empty when EOF is reached.
298#[stable(feature = "rust1", since = "1.0.0")]
299impl Read for &[u8] {
300    #[inline]
301    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
302        let amt = cmp::min(buf.len(), self.len());
303        let (a, b) = self.split_at(amt);
304
305        // First check if the amount of bytes we want to read is small:
306        // `copy_from_slice` will generally expand to a call to `memcpy`, and
307        // for a single byte the overhead is significant.
308        if amt == 1 {
309            buf[0] = a[0];
310        } else {
311            buf[..amt].copy_from_slice(a);
312        }
313
314        *self = b;
315        Ok(amt)
316    }
317
318    #[inline]
319    fn read_buf(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
320        let amt = cmp::min(cursor.capacity(), self.len());
321        let (a, b) = self.split_at(amt);
322
323        cursor.append(a);
324
325        *self = b;
326        Ok(())
327    }
328
329    #[inline]
330    fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
331        let mut nread = 0;
332        for buf in bufs {
333            nread += self.read(buf)?;
334            if self.is_empty() {
335                break;
336            }
337        }
338
339        Ok(nread)
340    }
341
342    #[inline]
343    fn is_read_vectored(&self) -> bool {
344        true
345    }
346
347    #[inline]
348    fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
349        if buf.len() > self.len() {
350            // `read_exact` makes no promise about the content of `buf` if it
351            // fails so don't bother about that.
352            *self = &self[self.len()..];
353            return Err(io::Error::READ_EXACT_EOF);
354        }
355        let (a, b) = self.split_at(buf.len());
356
357        // First check if the amount of bytes we want to read is small:
358        // `copy_from_slice` will generally expand to a call to `memcpy`, and
359        // for a single byte the overhead is significant.
360        if buf.len() == 1 {
361            buf[0] = a[0];
362        } else {
363            buf.copy_from_slice(a);
364        }
365
366        *self = b;
367        Ok(())
368    }
369
370    #[inline]
371    fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
372        if cursor.capacity() > self.len() {
373            // Append everything we can to the cursor.
374            cursor.append(*self);
375            *self = &self[self.len()..];
376            return Err(io::Error::READ_EXACT_EOF);
377        }
378        let (a, b) = self.split_at(cursor.capacity());
379
380        cursor.append(a);
381
382        *self = b;
383        Ok(())
384    }
385
386    #[inline]
387    fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
388        let len = self.len();
389        buf.try_reserve(len)?;
390        buf.extend_from_slice(*self);
391        *self = &self[len..];
392        Ok(len)
393    }
394
395    #[inline]
396    fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
397        let content = str::from_utf8(self).map_err(|_| io::Error::INVALID_UTF8)?;
398        let len = self.len();
399        buf.try_reserve(len)?;
400        buf.push_str(content);
401        *self = &self[len..];
402        Ok(len)
403    }
404}
405
406#[stable(feature = "rust1", since = "1.0.0")]
407impl BufRead for &[u8] {
408    #[inline]
409    fn fill_buf(&mut self) -> io::Result<&[u8]> {
410        Ok(*self)
411    }
412
413    #[inline]
414    fn consume(&mut self, amt: usize) {
415        *self = &self[amt..];
416    }
417}
418
419/// Write is implemented for `&mut [u8]` by copying into the slice, overwriting
420/// its data.
421///
422/// Note that writing updates the slice to point to the yet unwritten part.
423/// The slice will be empty when it has been completely overwritten.
424///
425/// If the number of bytes to be written exceeds the size of the slice, write operations will
426/// return short writes: ultimately, `Ok(0)`; in this situation, `write_all` returns an error of
427/// kind `ErrorKind::WriteZero`.
428#[stable(feature = "rust1", since = "1.0.0")]
429impl Write for &mut [u8] {
430    #[inline]
431    fn write(&mut self, data: &[u8]) -> io::Result<usize> {
432        let amt = cmp::min(data.len(), self.len());
433        let (a, b) = mem::take(self).split_at_mut(amt);
434        a.copy_from_slice(&data[..amt]);
435        *self = b;
436        Ok(amt)
437    }
438
439    #[inline]
440    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
441        let mut nwritten = 0;
442        for buf in bufs {
443            nwritten += self.write(buf)?;
444            if self.is_empty() {
445                break;
446            }
447        }
448
449        Ok(nwritten)
450    }
451
452    #[inline]
453    fn is_write_vectored(&self) -> bool {
454        true
455    }
456
457    #[inline]
458    fn write_all(&mut self, data: &[u8]) -> io::Result<()> {
459        if self.write(data)? < data.len() { Err(io::Error::WRITE_ALL_EOF) } else { Ok(()) }
460    }
461
462    #[inline]
463    fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
464        for buf in bufs {
465            if self.write(buf)? < buf.len() {
466                return Err(io::Error::WRITE_ALL_EOF);
467            }
468        }
469        Ok(())
470    }
471
472    #[inline]
473    fn flush(&mut self) -> io::Result<()> {
474        Ok(())
475    }
476}
477
478/// Write is implemented for `Vec<u8>` by appending to the vector.
479/// The vector will grow as needed.
480#[stable(feature = "rust1", since = "1.0.0")]
481impl<A: Allocator> Write for Vec<u8, A> {
482    #[inline]
483    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
484        self.extend_from_slice(buf);
485        Ok(buf.len())
486    }
487
488    #[inline]
489    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
490        let len = bufs.iter().map(|b| b.len()).sum();
491        self.reserve(len);
492        for buf in bufs {
493            self.extend_from_slice(buf);
494        }
495        Ok(len)
496    }
497
498    #[inline]
499    fn is_write_vectored(&self) -> bool {
500        true
501    }
502
503    #[inline]
504    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
505        self.extend_from_slice(buf);
506        Ok(())
507    }
508
509    #[inline]
510    fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
511        self.write_vectored(bufs)?;
512        Ok(())
513    }
514
515    #[inline]
516    fn flush(&mut self) -> io::Result<()> {
517        Ok(())
518    }
519}
520
521/// Read is implemented for `VecDeque<u8>` by consuming bytes from the front of the `VecDeque`.
522#[stable(feature = "vecdeque_read_write", since = "1.63.0")]
523impl<A: Allocator> Read for VecDeque<u8, A> {
524    /// Fill `buf` with the contents of the "front" slice as returned by
525    /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are
526    /// discontiguous, multiple calls to `read` will be needed to read the entire content.
527    #[inline]
528    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
529        let (ref mut front, _) = self.as_slices();
530        let n = Read::read(front, buf)?;
531        self.drain(..n);
532        Ok(n)
533    }
534
535    #[inline]
536    fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
537        let (front, back) = self.as_slices();
538
539        // Use only the front buffer if it is big enough to fill `buf`, else use
540        // the back buffer too.
541        match buf.split_at_mut_checked(front.len()) {
542            None => buf.copy_from_slice(&front[..buf.len()]),
543            Some((buf_front, buf_back)) => match back.split_at_checked(buf_back.len()) {
544                Some((back, _)) => {
545                    buf_front.copy_from_slice(front);
546                    buf_back.copy_from_slice(back);
547                }
548                None => {
549                    self.clear();
550                    return Err(io::Error::READ_EXACT_EOF);
551                }
552            },
553        }
554
555        self.drain(..buf.len());
556        Ok(())
557    }
558
559    #[inline]
560    fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
561        let (ref mut front, _) = self.as_slices();
562        let n = cmp::min(cursor.capacity(), front.len());
563        Read::read_buf(front, cursor)?;
564        self.drain(..n);
565        Ok(())
566    }
567
568    #[inline]
569    fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
570        let len = cursor.capacity();
571        let (front, back) = self.as_slices();
572
573        match front.split_at_checked(cursor.capacity()) {
574            Some((front, _)) => cursor.append(front),
575            None => {
576                cursor.append(front);
577                match back.split_at_checked(cursor.capacity()) {
578                    Some((back, _)) => cursor.append(back),
579                    None => {
580                        cursor.append(back);
581                        self.clear();
582                        return Err(io::Error::READ_EXACT_EOF);
583                    }
584                }
585            }
586        }
587
588        self.drain(..len);
589        Ok(())
590    }
591
592    #[inline]
593    fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
594        // The total len is known upfront so we can reserve it in a single call.
595        let len = self.len();
596        buf.try_reserve(len)?;
597
598        let (front, back) = self.as_slices();
599        buf.extend_from_slice(front);
600        buf.extend_from_slice(back);
601        self.clear();
602        Ok(len)
603    }
604
605    #[inline]
606    fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
607        // SAFETY: We only append to the buffer
608        unsafe { io::append_to_string(buf, |buf| self.read_to_end(buf)) }
609    }
610}
611
612/// BufRead is implemented for `VecDeque<u8>` by reading bytes from the front of the `VecDeque`.
613#[stable(feature = "vecdeque_buf_read", since = "1.75.0")]
614impl<A: Allocator> BufRead for VecDeque<u8, A> {
615    /// Returns the contents of the "front" slice as returned by
616    /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are
617    /// discontiguous, multiple calls to `fill_buf` will be needed to read the entire content.
618    #[inline]
619    fn fill_buf(&mut self) -> io::Result<&[u8]> {
620        let (front, _) = self.as_slices();
621        Ok(front)
622    }
623
624    #[inline]
625    fn consume(&mut self, amt: usize) {
626        self.drain(..amt);
627    }
628}
629
630/// Write is implemented for `VecDeque<u8>` by appending to the `VecDeque`, growing it as needed.
631#[stable(feature = "vecdeque_read_write", since = "1.63.0")]
632impl<A: Allocator> Write for VecDeque<u8, A> {
633    #[inline]
634    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
635        self.extend(buf);
636        Ok(buf.len())
637    }
638
639    #[inline]
640    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
641        let len = bufs.iter().map(|b| b.len()).sum();
642        self.reserve(len);
643        for buf in bufs {
644            self.extend(&**buf);
645        }
646        Ok(len)
647    }
648
649    #[inline]
650    fn is_write_vectored(&self) -> bool {
651        true
652    }
653
654    #[inline]
655    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
656        self.extend(buf);
657        Ok(())
658    }
659
660    #[inline]
661    fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
662        self.write_vectored(bufs)?;
663        Ok(())
664    }
665
666    #[inline]
667    fn flush(&mut self) -> io::Result<()> {
668        Ok(())
669    }
670}
671
672#[unstable(feature = "read_buf", issue = "78485")]
673impl<'a> io::Write for core::io::BorrowedCursor<'a> {
674    #[inline]
675    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
676        let amt = cmp::min(buf.len(), self.capacity());
677        self.append(&buf[..amt]);
678        Ok(amt)
679    }
680
681    #[inline]
682    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
683        let mut nwritten = 0;
684        for buf in bufs {
685            let n = self.write(buf)?;
686            nwritten += n;
687            if n < buf.len() {
688                break;
689            }
690        }
691        Ok(nwritten)
692    }
693
694    #[inline]
695    fn is_write_vectored(&self) -> bool {
696        true
697    }
698
699    #[inline]
700    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
701        if self.write(buf)? < buf.len() { Err(io::Error::WRITE_ALL_EOF) } else { Ok(()) }
702    }
703
704    #[inline]
705    fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
706        for buf in bufs {
707            if self.write(buf)? < buf.len() {
708                return Err(io::Error::WRITE_ALL_EOF);
709            }
710        }
711        Ok(())
712    }
713
714    #[inline]
715    fn flush(&mut self) -> io::Result<()> {
716        Ok(())
717    }
718}
719
720#[stable(feature = "io_traits_arc", since = "1.73.0")]
721impl<R: Read + ?Sized> Read for Arc<R>
722where
723    for<'a> &'a R: Read,
724    R: crate::io::IoHandle,
725{
726    #[inline]
727    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
728        (&**self).read(buf)
729    }
730
731    #[inline]
732    fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
733        (&**self).read_buf(cursor)
734    }
735
736    #[inline]
737    fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
738        (&**self).read_vectored(bufs)
739    }
740
741    #[inline]
742    fn is_read_vectored(&self) -> bool {
743        (&**self).is_read_vectored()
744    }
745
746    #[inline]
747    fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
748        (&**self).read_to_end(buf)
749    }
750
751    #[inline]
752    fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
753        (&**self).read_to_string(buf)
754    }
755
756    #[inline]
757    fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
758        (&**self).read_exact(buf)
759    }
760
761    #[inline]
762    fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
763        (&**self).read_buf_exact(cursor)
764    }
765}
766#[stable(feature = "io_traits_arc", since = "1.73.0")]
767impl<W: Write + ?Sized> Write for Arc<W>
768where
769    for<'a> &'a W: Write,
770    W: crate::io::IoHandle,
771{
772    #[inline]
773    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
774        (&**self).write(buf)
775    }
776
777    #[inline]
778    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
779        (&**self).write_vectored(bufs)
780    }
781
782    #[inline]
783    fn is_write_vectored(&self) -> bool {
784        (&**self).is_write_vectored()
785    }
786
787    #[inline]
788    fn flush(&mut self) -> io::Result<()> {
789        (&**self).flush()
790    }
791
792    #[inline]
793    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
794        (&**self).write_all(buf)
795    }
796
797    #[inline]
798    fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
799        (&**self).write_all_vectored(bufs)
800    }
801
802    #[inline]
803    fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
804        (&**self).write_fmt(fmt)
805    }
806}
807#[stable(feature = "io_traits_arc", since = "1.73.0")]
808impl<S: Seek + ?Sized> Seek for Arc<S>
809where
810    for<'a> &'a S: Seek,
811    S: crate::io::IoHandle,
812{
813    #[inline]
814    fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
815        (&**self).seek(pos)
816    }
817
818    #[inline]
819    fn rewind(&mut self) -> io::Result<()> {
820        (&**self).rewind()
821    }
822
823    #[inline]
824    fn stream_len(&mut self) -> io::Result<u64> {
825        (&**self).stream_len()
826    }
827
828    #[inline]
829    fn stream_position(&mut self) -> io::Result<u64> {
830        (&**self).stream_position()
831    }
832
833    #[inline]
834    fn seek_relative(&mut self, offset: i64) -> io::Result<()> {
835        (&**self).seek_relative(offset)
836    }
837}