1 | // SPDX-License-Identifier: Apache-2.0 OR MIT |
2 | |
3 | pub(crate) mod read { |
4 | use crate::derive::*; |
5 | |
6 | pub(crate) const NAME: &[&str] = &["Read" , "io::Read" ]; |
7 | |
8 | pub(crate) fn derive(_cx: &Context, data: &Data) -> Result<TokenStream> { |
9 | // TODO: Add is_read_vectored once stabilized https://github.com/rust-lang/rust/issues/69941 |
10 | // TODO: Add read_buf,read_buf_exact once stabilized https://github.com/rust-lang/rust/issues/78485 |
11 | Ok(derive_trait(data, &parse_quote!(::std::io::Read), None, parse_quote! { |
12 | trait Read { |
13 | #[inline] |
14 | fn read(&mut self, buf: &mut [u8]) -> ::std::io::Result<usize>; |
15 | #[inline] |
16 | fn read_vectored( |
17 | &mut self, |
18 | bufs: &mut [::std::io::IoSliceMut<'_>], |
19 | ) -> ::std::io::Result<usize>; |
20 | #[inline] |
21 | fn read_to_end( |
22 | &mut self, |
23 | buf: &mut ::std::vec::Vec<u8>, |
24 | ) -> ::std::io::Result<usize>; |
25 | #[inline] |
26 | fn read_to_string( |
27 | &mut self, |
28 | buf: &mut ::std::string::String, |
29 | ) -> ::std::io::Result<usize>; |
30 | #[inline] |
31 | fn read_exact(&mut self, buf: &mut [u8]) -> ::std::io::Result<()>; |
32 | } |
33 | })) |
34 | } |
35 | } |
36 | |
37 | pub(crate) mod write { |
38 | use crate::derive::*; |
39 | |
40 | pub(crate) const NAME: &[&str] = &["Write" , "io::Write" ]; |
41 | |
42 | pub(crate) fn derive(_cx: &Context, data: &Data) -> Result<TokenStream> { |
43 | // TODO: Add is_write_vectored once stabilized https://github.com/rust-lang/rust/issues/69941 |
44 | // TODO: Add write_all_vectored once stabilized https://github.com/rust-lang/rust/issues/70436 |
45 | Ok(derive_trait(data, &parse_quote!(::std::io::Write), None, parse_quote! { |
46 | trait Write { |
47 | #[inline] |
48 | fn write(&mut self, buf: &[u8]) -> ::std::io::Result<usize>; |
49 | #[inline] |
50 | fn write_vectored( |
51 | &mut self, |
52 | bufs: &[::std::io::IoSlice<'_>], |
53 | ) -> ::std::io::Result<usize>; |
54 | #[inline] |
55 | fn flush(&mut self) -> ::std::io::Result<()>; |
56 | #[inline] |
57 | fn write_all(&mut self, buf: &[u8]) -> ::std::io::Result<()>; |
58 | #[inline] |
59 | fn write_fmt( |
60 | &mut self, |
61 | fmt: ::std::fmt::Arguments<'_>, |
62 | ) -> ::std::io::Result<()>; |
63 | } |
64 | })) |
65 | } |
66 | } |
67 | |
68 | pub(crate) mod seek { |
69 | use crate::derive::*; |
70 | |
71 | pub(crate) const NAME: &[&str] = &["Seek" , "io::Seek" ]; |
72 | |
73 | pub(crate) fn derive(_cx: &Context, data: &Data) -> Result<TokenStream> { |
74 | Ok(derive_trait(data, &parse_quote!(::std::io::Seek), supertraits_types:None, trait_def:parse_quote! { |
75 | trait Seek { |
76 | #[inline] |
77 | fn seek(&mut self, pos: ::std::io::SeekFrom) -> ::std::io::Result<u64>; |
78 | } |
79 | })) |
80 | } |
81 | } |
82 | |
83 | pub(crate) mod buf_read { |
84 | use crate::derive::*; |
85 | |
86 | pub(crate) const NAME: &[&str] = &["BufRead" , "io::BufRead" ]; |
87 | |
88 | pub(crate) fn derive(_cx: &Context, data: &Data) -> Result<TokenStream> { |
89 | Ok(derive_trait(data, &parse_quote!(::std::io::BufRead), None, parse_quote! { |
90 | trait BufRead { |
91 | #[inline] |
92 | fn fill_buf(&mut self) -> ::std::io::Result<&[u8]>; |
93 | #[inline] |
94 | fn consume(&mut self, amt: usize); |
95 | #[inline] |
96 | fn read_until( |
97 | &mut self, |
98 | byte: u8, buf: &mut ::std::vec::Vec<u8>, |
99 | ) -> ::std::io::Result<usize>; |
100 | #[inline] |
101 | fn read_line( |
102 | &mut self, |
103 | buf: &mut ::std::string::String, |
104 | ) -> ::std::io::Result<usize>; |
105 | } |
106 | })) |
107 | } |
108 | } |
109 | |