playdate_fs/seek.rs
1use core::ffi::c_int;
2
3
4#[derive(Debug, Clone, Copy)]
5/// Same as [`std::io::SeekFrom`].
6pub enum SeekFrom {
7 /// Sets the offset to the provided number of bytes.
8 ///
9 /// Same as [`std::io::SeekFrom::Start`].
10 #[doc(alias = "sys::ffi::SEEK_SET")]
11 Start(c_int),
12
13 /// Sets the offset to the current position plus the specified number of
14 /// bytes.
15 ///
16 /// It is possible to seek beyond the end of an object, but it's an error to
17 /// seek before byte 0.
18 ///
19 /// Same as [`std::io::SeekFrom::Current`].
20 #[doc(alias = "sys::ffi::SEEK_CUR")]
21 Current(c_int),
22
23 /// Sets the offset to the size of this object plus the specified number of
24 /// bytes.
25 ///
26 /// It is possible to seek beyond the end of an object, but it's an error to
27 /// seek before byte 0.
28 ///
29 /// Same as [`std::io::SeekFrom::End`].
30 #[doc(alias = "sys::ffi::SEEK_END")]
31 End(c_int),
32}
33
34impl SeekFrom {
35 /// Split into [`whence`](Whence) and position.
36 pub const fn into_parts(self) -> (Whence, c_int) {
37 match self {
38 SeekFrom::Start(pos) => (Whence::Start, pos),
39 SeekFrom::Current(pos) => (Whence::Current, pos),
40 SeekFrom::End(pos) => (Whence::End, pos),
41 }
42 }
43}
44
45
46#[repr(u32)]
47#[derive(Debug, Clone, Copy)]
48pub enum Whence {
49 /// Equal to [`sys::ffi::SEEK_SET`].
50 #[doc(alias = "sys::ffi::SEEK_SET")]
51 Start = sys::ffi::SEEK_SET as _,
52
53 /// Equal to [`sys::ffi::SEEK_CUR`].
54 #[doc(alias = "sys::ffi::SEEK_CUR")]
55 Current = sys::ffi::SEEK_CUR as _,
56
57 /// Equal to [`sys::ffi::SEEK_END`].
58 #[doc(alias = "sys::ffi::SEEK_END")]
59 End = sys::ffi::SEEK_END as _,
60}