File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 11[package ]
2- name = " chapter2"
3- version = " 0.1.0"
42authors = [
" yytyd <[email protected] >" ]
53edition = " 2018"
4+ name = " chapter2"
5+ version = " 0.1.0"
66
77# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88
@@ -16,6 +16,10 @@ path = "src/2_4_1/main.rs"
1616name = " 2_4_2"
1717path = " src/2_4_2/main.rs"
1818
19+ [[bin ]]
20+ name = " 2_4_3"
21+ path = " src/2_4_3/main.rs"
22+
1923[[bin ]]
2024name = " client_2_4_4"
2125path = " src/2_4_4/client.rs"
Original file line number Diff line number Diff line change 1+ use std:: io:: Write ;
2+ use std:: str;
3+
4+ #[ derive( Debug ) ]
5+ enum BufferError {
6+ IOError ( std:: io:: Error ) ,
7+ StrError ( str:: Utf8Error ) ,
8+ }
9+
10+ impl From < std:: io:: Error > for BufferError {
11+ fn from ( error : std:: io:: Error ) -> Self {
12+ BufferError :: IOError ( error)
13+ }
14+ }
15+
16+ impl From < str:: Utf8Error > for BufferError {
17+ fn from ( error : str:: Utf8Error ) -> Self {
18+ BufferError :: StrError ( error)
19+ }
20+ }
21+
22+ fn main ( ) -> Result < ( ) , BufferError > {
23+ let mut buffer: Vec < u8 > = Vec :: new ( ) ;
24+ buffer. write ( b"bytes.Buffer example1\n " ) ?;
25+ println ! ( "{}" , str :: from_utf8( & buffer) ?) ;
26+ buffer. write ( b"bytes.Buffer example2\n " ) ?;
27+ println ! ( "{}" , str :: from_utf8( & buffer) ?) ;
28+ Ok ( ( ) )
29+ }
You can’t perform that action at this time.
0 commit comments