Skip to main content

compio_driver/sys/op/general/
mod.rs

1//! Implementation of common op codes
2
3#[cfg(windows)]
4mod_use![iocp];
5
6#[cfg(io_uring)]
7mod_use![iour];
8
9#[cfg(polling)]
10mod_use![poll];
11
12#[cfg(stub)]
13mod_use![stub];
14
15use crate::sys::prelude::*;
16
17/// Read a file at specified position into specified buffer.
18#[derive(Debug)]
19pub struct ReadAt<T: IoBufMut, S> {
20    pub(crate) fd: S,
21    pub(crate) offset: u64,
22    pub(crate) buffer: T,
23}
24
25impl<T: IoBufMut, S> ReadAt<T, S> {
26    /// Create [`ReadAt`].
27    pub fn new(fd: S, offset: u64, buffer: T) -> Self {
28        Self { fd, offset, buffer }
29    }
30}
31
32impl<T: IoBufMut, S> IntoInner for ReadAt<T, S> {
33    type Inner = T;
34
35    fn into_inner(self) -> Self::Inner {
36        self.buffer
37    }
38}
39
40/// Write a file at specified position from specified buffer.
41#[derive(Debug)]
42pub struct WriteAt<T: IoBuf, S> {
43    pub(crate) fd: S,
44    pub(crate) offset: u64,
45    pub(crate) buffer: T,
46}
47
48impl<T: IoBuf, S> WriteAt<T, S> {
49    /// Create [`WriteAt`].
50    pub fn new(fd: S, offset: u64, buffer: T) -> Self {
51        Self { fd, offset, buffer }
52    }
53}
54
55impl<T: IoBuf, S> IntoInner for WriteAt<T, S> {
56    type Inner = T;
57
58    fn into_inner(self) -> Self::Inner {
59        self.buffer
60    }
61}
62
63/// Read a file.
64pub struct Read<T: IoBufMut, S> {
65    pub(crate) fd: S,
66    pub(crate) buffer: T,
67}
68
69impl<T: IoBufMut, S> Read<T, S> {
70    /// Create [`Read`].
71    pub fn new(fd: S, buffer: T) -> Self {
72        Self { fd, buffer }
73    }
74}
75
76impl<T: IoBufMut, S> IntoInner for Read<T, S> {
77    type Inner = T;
78
79    fn into_inner(self) -> Self::Inner {
80        self.buffer
81    }
82}
83
84/// Write a file.
85pub struct Write<T: IoBuf, S> {
86    pub(crate) fd: S,
87    pub(crate) buffer: T,
88}
89
90impl<T: IoBuf, S> Write<T, S> {
91    /// Create [`Write`].
92    pub fn new(fd: S, buffer: T) -> Self {
93        Self { fd, buffer }
94    }
95}
96
97impl<T: IoBuf, S> IntoInner for Write<T, S> {
98    type Inner = T;
99
100    fn into_inner(self) -> Self::Inner {
101        self.buffer
102    }
103}