qubit_io/traits/seekable_output.rs
1// =============================================================================
2// Copyright (c) 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9use super::Output;
10use super::Seekable;
11
12/// Object-safe capability trait for outputs that can be written and
13/// repositioned in the same item space.
14///
15/// `SeekableOutput` exists to give the common [`Output`] + [`Seekable`]
16/// combination a stable, named trait with a single item type. It is useful for
17/// buffered outputs and other adapters that must coordinate pending items when
18/// seeking the wrapped output.
19///
20/// [`Output::Item`] is the shared type for both writing and seeking. It
21/// always matches [`Seekable::Unit`].
22///
23/// The trait adds no methods of its own. All operations come from the
24/// supertraits, and every type implementing both [`Output`] and [`Seekable`]
25/// with matching [`Output::Item`] and [`Seekable::Unit`] automatically
26/// implements `SeekableOutput`.
27///
28/// # Examples
29///
30/// ```
31/// use std::io::Cursor;
32/// use std::io::SeekFrom;
33///
34/// use qubit_io::SeekableOutput;
35///
36/// let output = Cursor::new(Vec::<u8>::new());
37/// let mut output: Box<dyn SeekableOutput<Item = u8, Unit = u8>> =
38/// Box::new(output);
39///
40/// assert_eq!(1, output.write(&[1_u8])?);
41/// assert_eq!(0, output.seek_to(SeekFrom::Start(0))?);
42/// # Ok::<(), std::io::Error>(())
43/// ```
44pub trait SeekableOutput: Output + Seekable<Unit = <Self as Output>::Item> {
45 // empty
46}
47
48impl<T> SeekableOutput for T
49where
50 T: Output + Seekable<Unit = <T as Output>::Item> + ?Sized,
51{
52 // empty
53}