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