@@ -32,96 +32,126 @@ extern mod rustrt {
32
32
pub enum SeekStyle { SeekSet , SeekEnd , SeekCur , }
33
33
34
34
35
- // The raw underlying reader trait. All readers must implement this.
35
+ /// The raw underlying reader trait. All readers must implement this.
36
36
pub trait Reader {
37
37
// FIXME (#2004): Seekable really should be orthogonal.
38
38
39
+ /// Read up to len bytes (or EOF) and put them into bytes (which
40
+ /// must be at least len bytes long). Return number of bytes read.
39
41
// FIXME (#2982): This should probably return an error.
40
42
fn read ( bytes : & [ mut u8] , len : uint ) -> uint ;
43
+
44
+ /// Read a single byte, returning a negative value for EOF or read error.
41
45
fn read_byte ( ) -> int ;
46
+
47
+ /// Behaves like the libc function ungetc.
42
48
fn unread_byte ( int ) ;
49
+
50
+ /// Return whether the stream is currently at EOF position.
43
51
fn eof ( ) -> bool ;
44
- fn seek ( int , SeekStyle ) ;
52
+
53
+ /// Move the current position within the stream. The second parameter
54
+ /// determines the position that the first parameter is relative to.
55
+ fn seek ( position : int , style : SeekStyle ) ;
56
+
57
+ /// Return the current position within the stream.
45
58
fn tell ( ) -> uint ;
46
59
}
47
60
48
- // Generic utility functions defined on readers
61
+ /// Generic utility functions defined on readers.
49
62
pub trait ReaderUtil {
63
+
64
+ /// Read len bytes into a new vec.
50
65
fn read_bytes ( len : uint ) -> ~[ u8 ] ;
66
+
67
+ /// Read up until the first '\n' char (which is not returned), or EOF.
51
68
fn read_line ( ) -> ~str ;
52
69
70
+ /// Read n utf-8 encoded chars.
53
71
fn read_chars ( n : uint ) -> ~[ char ] ;
72
+
73
+ /// Read a single utf-8 encoded char.
54
74
fn read_char ( ) -> char ;
75
+
76
+ /// Read up until the first null byte (which is not returned), or EOF.
55
77
fn read_c_str ( ) -> ~str ;
78
+
79
+ /// Read all the data remaining in the stream in one go.
56
80
fn read_whole_stream ( ) -> ~[ u8 ] ;
81
+
82
+ /// Iterate over every byte until the iterator breaks or EOF.
57
83
fn each_byte ( it : fn ( int ) -> bool ) ;
84
+
85
+ /// Iterate over every char until the iterator breaks or EOF.
58
86
fn each_char ( it : fn ( char ) -> bool ) ;
59
- fn each_line ( it : fn ( ( & str ) ) -> bool ) ;
60
87
61
- /// read n (between 1 and 8) little-endian unsigned integer bytes
88
+ /// Iterate over every line until the iterator breaks or EOF.
89
+ fn each_line ( it : fn ( & str ) -> bool ) ;
90
+
91
+ /// Read n (between 1 and 8) little-endian unsigned integer bytes.
62
92
fn read_le_uint_n ( nbytes : uint ) -> u64 ;
63
93
64
- /// read n (between 1 and 8) little-endian signed integer bytes
94
+ /// Read n (between 1 and 8) little-endian signed integer bytes.
65
95
fn read_le_int_n ( nbytes : uint ) -> i64 ;
66
96
67
- /// read n (between 1 and 8) big-endian unsigned integer bytes
97
+ /// Read n (between 1 and 8) big-endian unsigned integer bytes.
68
98
fn read_be_uint_n ( nbytes : uint ) -> u64 ;
69
99
70
- /// read n (between 1 and 8) big-endian signed integer bytes
100
+ /// Read n (between 1 and 8) big-endian signed integer bytes.
71
101
fn read_be_int_n ( nbytes : uint ) -> i64 ;
72
102
73
- /// read a little-endian uint (number of bytes read depends on system)
103
+ /// Read a little-endian uint (number of bytes depends on system).
74
104
fn read_le_uint ( ) -> uint ;
75
105
76
- /// read a little-endian int (number of bytes read depends on system)
106
+ /// Read a little-endian int (number of bytes depends on system).
77
107
fn read_le_int ( ) -> int ;
78
108
79
- /// read a big-endian uint (number of bytes read depends on system)
109
+ /// Read a big-endian uint (number of bytes depends on system).
80
110
fn read_be_uint ( ) -> uint ;
81
111
82
- /// read a big-endian int (number of bytes read depends on system)
112
+ /// Read a big-endian int (number of bytes depends on system).
83
113
fn read_be_int ( ) -> int ;
84
114
85
- /// read a big-endian u64 (8 bytes)
115
+ /// Read a big-endian u64 (8 bytes).
86
116
fn read_be_u64 ( ) -> u64 ;
87
117
88
- /// read a big-endian u32 (4 bytes)
118
+ /// Read a big-endian u32 (4 bytes).
89
119
fn read_be_u32 ( ) -> u32 ;
90
120
91
- /// read a big-endian u16 (2 bytes)
121
+ /// Read a big-endian u16 (2 bytes).
92
122
fn read_be_u16 ( ) -> u16 ;
93
123
94
- /// read a big-endian i64 (8 bytes)
124
+ /// Read a big-endian i64 (8 bytes).
95
125
fn read_be_i64 ( ) -> i64 ;
96
126
97
- /// read a big-endian i32 (4 bytes)
127
+ /// Read a big-endian i32 (4 bytes).
98
128
fn read_be_i32 ( ) -> i32 ;
99
129
100
- /// read a big-endian i16 (2 bytes)
130
+ /// Read a big-endian i16 (2 bytes).
101
131
fn read_be_i16 ( ) -> i16 ;
102
132
103
- /// read a little-endian u64 (8 bytes)
133
+ /// Read a little-endian u64 (8 bytes).
104
134
fn read_le_u64 ( ) -> u64 ;
105
135
106
- /// read a little-endian u32 (4 bytes)
136
+ /// Read a little-endian u32 (4 bytes).
107
137
fn read_le_u32 ( ) -> u32 ;
108
138
109
- /// read a little-endian u16 (2 bytes)
139
+ /// Read a little-endian u16 (2 bytes).
110
140
fn read_le_u16 ( ) -> u16 ;
111
141
112
- /// read a litle-endian i64 (8 bytes)
142
+ /// Read a litle-endian i64 (8 bytes).
113
143
fn read_le_i64 ( ) -> i64 ;
114
144
115
- /// read a litle-endian i32 (4 bytes)
145
+ /// Read a litle-endian i32 (4 bytes).
116
146
fn read_le_i32 ( ) -> i32 ;
117
147
118
- /// read a litle-endian i16 (2 bytes)
148
+ /// Read a litle-endian i16 (2 bytes).
119
149
fn read_le_i16 ( ) -> i16 ;
120
150
121
- /// read a u8 (1 byte)
151
+ /// Read a u8 (1 byte).
122
152
fn read_u8 ( ) -> u8 ;
123
153
124
- /// read a i8 (1 byte)
154
+ /// Read a i8 (1 byte).
125
155
fn read_i8 ( ) -> i8 ;
126
156
}
127
157
@@ -504,11 +534,23 @@ pub impl WriterType : Eq {
504
534
505
535
// FIXME (#2004): Seekable really should be orthogonal.
506
536
// FIXME (#2004): eventually u64
537
+ /// The raw underlying writer trait. All writers must implement this.
507
538
pub trait Writer {
539
+
540
+ /// Write all of the given bytes.
508
541
fn write ( v : & [ const u8 ] ) ;
542
+
543
+ /// Move the current position within the stream. The second parameter
544
+ /// determines the position that the first parameter is relative to.
509
545
fn seek ( int , SeekStyle ) ;
546
+
547
+ /// Return the current position within the stream.
510
548
fn tell ( ) -> uint ;
549
+
550
+ /// Flush the output buffer for this stream (if there is one).
511
551
fn flush ( ) -> int ;
552
+
553
+ /// Determine if this Writer is writing to a file or not.
512
554
fn get_type ( ) -> WriterType ;
513
555
}
514
556
@@ -712,29 +754,76 @@ pub fn u64_from_be_bytes(data: &[const u8],
712
754
713
755
// FIXME: #3048 combine trait+impl (or just move these to
714
756
// default methods on writer)
757
+ /// Generic utility functions defined on writers.
715
758
pub trait WriterUtil {
759
+
760
+ /// Write a single utf-8 encoded char.
716
761
fn write_char ( ch : char ) ;
762
+
763
+ /// Write every char in the given str, encoded as utf-8.
717
764
fn write_str ( s : & str ) ;
765
+
766
+ /// Write the given str, as utf-8, followed by '\n'.
718
767
fn write_line ( s : & str ) ;
768
+
769
+ /// Write the result of passing n through `int::to_str_bytes`.
719
770
fn write_int ( n : int ) ;
771
+
772
+ /// Write the result of passing n through `uint::to_str_bytes`.
720
773
fn write_uint ( n : uint ) ;
774
+
775
+ /// Write a little-endian uint (number of bytes depends on system).
721
776
fn write_le_uint ( n : uint ) ;
777
+
778
+ /// Write a little-endian int (number of bytes depends on system).
722
779
fn write_le_int ( n : int ) ;
780
+
781
+ /// Write a big-endian uint (number of bytes depends on system).
723
782
fn write_be_uint ( n : uint ) ;
783
+
784
+ /// Write a big-endian int (number of bytes depends on system).
724
785
fn write_be_int ( n : int ) ;
786
+
787
+ /// Write a big-endian u64 (8 bytes).
725
788
fn write_be_u64 ( n : u64 ) ;
789
+
790
+ /// Write a big-endian u32 (4 bytes).
726
791
fn write_be_u32 ( n : u32 ) ;
792
+
793
+ /// Write a big-endian u16 (2 bytes).
727
794
fn write_be_u16 ( n : u16 ) ;
795
+
796
+ /// Write a big-endian i64 (8 bytes).
728
797
fn write_be_i64 ( n : i64 ) ;
798
+
799
+ /// Write a big-endian i32 (4 bytes).
729
800
fn write_be_i32 ( n : i32 ) ;
801
+
802
+ /// Write a big-endian i16 (2 bytes).
730
803
fn write_be_i16 ( n : i16 ) ;
804
+
805
+ /// Write a little-endian u64 (8 bytes).
731
806
fn write_le_u64 ( n : u64 ) ;
807
+
808
+ /// Write a little-endian u32 (4 bytes).
732
809
fn write_le_u32 ( n : u32 ) ;
810
+
811
+ /// Write a little-endian u16 (2 bytes).
733
812
fn write_le_u16 ( n : u16 ) ;
813
+
814
+ /// Write a little-endian i64 (8 bytes).
734
815
fn write_le_i64 ( n : i64 ) ;
816
+
817
+ /// Write a little-endian i32 (4 bytes).
735
818
fn write_le_i32 ( n : i32 ) ;
819
+
820
+ /// Write a little-endian i16 (2 bytes).
736
821
fn write_le_i16 ( n : i16 ) ;
822
+
823
+ /// Write a u8 (1 byte).
737
824
fn write_u8 ( n : u8 ) ;
825
+
826
+ /// Write a i8 (1 byte).
738
827
fn write_i8 ( n : i8 ) ;
739
828
}
740
829
0 commit comments