qubit_io/read_write_seek.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10use std::io::{
11 Read,
12 Seek,
13 Write,
14};
15
16/// Object-safe capability trait for values that can be read, written, and
17/// repositioned.
18///
19/// `ReadWriteSeek` gives the common [`Read`] + [`Write`] + [`Seek`] combination
20/// a named trait for APIs that need full mutable random-access I/O through a
21/// trait object. Typical use cases include in-place file updates, editable
22/// binary containers, test buffers, and components that should accept either a
23/// file-like handle or an in-memory cursor.
24///
25/// The trait adds no methods of its own. All operations come from the
26/// standard-library supertraits, and every type implementing [`Read`],
27/// [`Write`], and [`Seek`] automatically implements `ReadWriteSeek`.
28///
29/// # Examples
30///
31/// ```rust
32/// use qubit_io::ReadWriteSeek;
33/// use std::io::SeekFrom;
34///
35/// fn rewrite_first_byte(io: &mut dyn ReadWriteSeek) -> std::io::Result<String> {
36/// io.write_all(b"abc")?;
37/// io.seek(SeekFrom::Start(0))?;
38/// io.write_all(b"z")?;
39/// io.seek(SeekFrom::Start(0))?;
40///
41/// let mut output = String::new();
42/// io.read_to_string(&mut output)?;
43/// Ok(output)
44/// }
45///
46/// let mut cursor = std::io::Cursor::new(Vec::new());
47/// assert_eq!(rewrite_first_byte(&mut cursor)?, "zbc");
48/// # Ok::<(), std::io::Error>(())
49/// ```
50pub trait ReadWriteSeek: Read + Write + Seek {}
51
52impl<T> ReadWriteSeek for T where T: Read + Write + Seek {}