Skip to main content

qubit_io/std_io/impls/
seekable.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
9//! Standard [`Seek`](std::io::Seek) implementations of item seeking traits.
10
11use std::io::Result;
12use std::io::Seek;
13use std::io::SeekFrom;
14
15use crate::Seekable;
16
17/// Bridges byte-oriented standard seeking to item-oriented seeking.
18impl<S> Seekable for S
19where
20    S: Seek + ?Sized,
21{
22    /// Bytes used by the standard Seek implementation.
23    type Unit = u8;
24
25    /// Seeks using the standard byte offset semantics.
26    ///
27    /// # Parameters
28    ///
29    /// - `position`: Standard-library seek origin and byte offset.
30    ///
31    /// # Returns
32    ///
33    /// The resulting byte offset from the start of the stream.
34    ///
35    /// # Errors
36    ///
37    /// Returns the error reported by the standard seeker.
38    #[inline(always)]
39    fn seek_to(&mut self, position: SeekFrom) -> Result<u64> {
40        Seek::seek(self, position)
41    }
42}