@@ -32,96 +32,126 @@ extern mod rustrt {
3232pub enum SeekStyle { SeekSet , SeekEnd , SeekCur , }
3333
3434
35- // The raw underlying reader trait. All readers must implement this.
35+ /// The raw underlying reader trait. All readers must implement this.
3636pub trait Reader {
3737 // FIXME (#2004): Seekable really should be orthogonal.
3838
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.
3941 // FIXME (#2982): This should probably return an error.
4042 fn read ( bytes : & [ mut u8] , len : uint ) -> uint ;
43+
44+ /// Read a single byte, returning a negative value for EOF or read error.
4145 fn read_byte ( ) -> int ;
46+
47+ /// Behaves like the libc function ungetc.
4248 fn unread_byte ( int ) ;
49+
50+ /// Return whether the stream is currently at EOF position.
4351 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.
4558 fn tell ( ) -> uint ;
4659}
4760
48- // Generic utility functions defined on readers
61+ /// Generic utility functions defined on readers.
4962pub trait ReaderUtil {
63+
64+ /// Read len bytes into a new vec.
5065 fn read_bytes ( len : uint ) -> ~[ u8 ] ;
66+
67+ /// Read up until the first '\n' char (which is not returned), or EOF.
5168 fn read_line ( ) -> ~str ;
5269
70+ /// Read n utf-8 encoded chars.
5371 fn read_chars ( n : uint ) -> ~[ char ] ;
72+
73+ /// Read a single utf-8 encoded char.
5474 fn read_char ( ) -> char ;
75+
76+ /// Read up until the first null byte (which is not returned), or EOF.
5577 fn read_c_str ( ) -> ~str ;
78+
79+ /// Read all the data remaining in the stream in one go.
5680 fn read_whole_stream ( ) -> ~[ u8 ] ;
81+
82+ /// Iterate over every byte until the iterator breaks or EOF.
5783 fn each_byte ( it : fn ( int ) -> bool ) ;
84+
85+ /// Iterate over every char until the iterator breaks or EOF.
5886 fn each_char ( it : fn ( char ) -> bool ) ;
59- fn each_line ( it : fn ( ( & str ) ) -> bool ) ;
6087
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.
6292 fn read_le_uint_n ( nbytes : uint ) -> u64 ;
6393
64- /// read n (between 1 and 8) little-endian signed integer bytes
94+ /// Read n (between 1 and 8) little-endian signed integer bytes.
6595 fn read_le_int_n ( nbytes : uint ) -> i64 ;
6696
67- /// read n (between 1 and 8) big-endian unsigned integer bytes
97+ /// Read n (between 1 and 8) big-endian unsigned integer bytes.
6898 fn read_be_uint_n ( nbytes : uint ) -> u64 ;
6999
70- /// read n (between 1 and 8) big-endian signed integer bytes
100+ /// Read n (between 1 and 8) big-endian signed integer bytes.
71101 fn read_be_int_n ( nbytes : uint ) -> i64 ;
72102
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).
74104 fn read_le_uint ( ) -> uint ;
75105
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).
77107 fn read_le_int ( ) -> int ;
78108
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).
80110 fn read_be_uint ( ) -> uint ;
81111
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).
83113 fn read_be_int ( ) -> int ;
84114
85- /// read a big-endian u64 (8 bytes)
115+ /// Read a big-endian u64 (8 bytes).
86116 fn read_be_u64 ( ) -> u64 ;
87117
88- /// read a big-endian u32 (4 bytes)
118+ /// Read a big-endian u32 (4 bytes).
89119 fn read_be_u32 ( ) -> u32 ;
90120
91- /// read a big-endian u16 (2 bytes)
121+ /// Read a big-endian u16 (2 bytes).
92122 fn read_be_u16 ( ) -> u16 ;
93123
94- /// read a big-endian i64 (8 bytes)
124+ /// Read a big-endian i64 (8 bytes).
95125 fn read_be_i64 ( ) -> i64 ;
96126
97- /// read a big-endian i32 (4 bytes)
127+ /// Read a big-endian i32 (4 bytes).
98128 fn read_be_i32 ( ) -> i32 ;
99129
100- /// read a big-endian i16 (2 bytes)
130+ /// Read a big-endian i16 (2 bytes).
101131 fn read_be_i16 ( ) -> i16 ;
102132
103- /// read a little-endian u64 (8 bytes)
133+ /// Read a little-endian u64 (8 bytes).
104134 fn read_le_u64 ( ) -> u64 ;
105135
106- /// read a little-endian u32 (4 bytes)
136+ /// Read a little-endian u32 (4 bytes).
107137 fn read_le_u32 ( ) -> u32 ;
108138
109- /// read a little-endian u16 (2 bytes)
139+ /// Read a little-endian u16 (2 bytes).
110140 fn read_le_u16 ( ) -> u16 ;
111141
112- /// read a litle-endian i64 (8 bytes)
142+ /// Read a litle-endian i64 (8 bytes).
113143 fn read_le_i64 ( ) -> i64 ;
114144
115- /// read a litle-endian i32 (4 bytes)
145+ /// Read a litle-endian i32 (4 bytes).
116146 fn read_le_i32 ( ) -> i32 ;
117147
118- /// read a litle-endian i16 (2 bytes)
148+ /// Read a litle-endian i16 (2 bytes).
119149 fn read_le_i16 ( ) -> i16 ;
120150
121- /// read a u8 (1 byte)
151+ /// Read a u8 (1 byte).
122152 fn read_u8 ( ) -> u8 ;
123153
124- /// read a i8 (1 byte)
154+ /// Read a i8 (1 byte).
125155 fn read_i8 ( ) -> i8 ;
126156}
127157
@@ -504,11 +534,23 @@ pub impl WriterType : Eq {
504534
505535// FIXME (#2004): Seekable really should be orthogonal.
506536// FIXME (#2004): eventually u64
537+ /// The raw underlying writer trait. All writers must implement this.
507538pub trait Writer {
539+
540+ /// Write all of the given bytes.
508541 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.
509545 fn seek ( int , SeekStyle ) ;
546+
547+ /// Return the current position within the stream.
510548 fn tell ( ) -> uint ;
549+
550+ /// Flush the output buffer for this stream (if there is one).
511551 fn flush ( ) -> int ;
552+
553+ /// Determine if this Writer is writing to a file or not.
512554 fn get_type ( ) -> WriterType ;
513555}
514556
@@ -712,29 +754,76 @@ pub fn u64_from_be_bytes(data: &[const u8],
712754
713755// FIXME: #3048 combine trait+impl (or just move these to
714756// default methods on writer)
757+ /// Generic utility functions defined on writers.
715758pub trait WriterUtil {
759+
760+ /// Write a single utf-8 encoded char.
716761 fn write_char ( ch : char ) ;
762+
763+ /// Write every char in the given str, encoded as utf-8.
717764 fn write_str ( s : & str ) ;
765+
766+ /// Write the given str, as utf-8, followed by '\n'.
718767 fn write_line ( s : & str ) ;
768+
769+ /// Write the result of passing n through `int::to_str_bytes`.
719770 fn write_int ( n : int ) ;
771+
772+ /// Write the result of passing n through `uint::to_str_bytes`.
720773 fn write_uint ( n : uint ) ;
774+
775+ /// Write a little-endian uint (number of bytes depends on system).
721776 fn write_le_uint ( n : uint ) ;
777+
778+ /// Write a little-endian int (number of bytes depends on system).
722779 fn write_le_int ( n : int ) ;
780+
781+ /// Write a big-endian uint (number of bytes depends on system).
723782 fn write_be_uint ( n : uint ) ;
783+
784+ /// Write a big-endian int (number of bytes depends on system).
724785 fn write_be_int ( n : int ) ;
786+
787+ /// Write a big-endian u64 (8 bytes).
725788 fn write_be_u64 ( n : u64 ) ;
789+
790+ /// Write a big-endian u32 (4 bytes).
726791 fn write_be_u32 ( n : u32 ) ;
792+
793+ /// Write a big-endian u16 (2 bytes).
727794 fn write_be_u16 ( n : u16 ) ;
795+
796+ /// Write a big-endian i64 (8 bytes).
728797 fn write_be_i64 ( n : i64 ) ;
798+
799+ /// Write a big-endian i32 (4 bytes).
729800 fn write_be_i32 ( n : i32 ) ;
801+
802+ /// Write a big-endian i16 (2 bytes).
730803 fn write_be_i16 ( n : i16 ) ;
804+
805+ /// Write a little-endian u64 (8 bytes).
731806 fn write_le_u64 ( n : u64 ) ;
807+
808+ /// Write a little-endian u32 (4 bytes).
732809 fn write_le_u32 ( n : u32 ) ;
810+
811+ /// Write a little-endian u16 (2 bytes).
733812 fn write_le_u16 ( n : u16 ) ;
813+
814+ /// Write a little-endian i64 (8 bytes).
734815 fn write_le_i64 ( n : i64 ) ;
816+
817+ /// Write a little-endian i32 (4 bytes).
735818 fn write_le_i32 ( n : i32 ) ;
819+
820+ /// Write a little-endian i16 (2 bytes).
736821 fn write_le_i16 ( n : i16 ) ;
822+
823+ /// Write a u8 (1 byte).
737824 fn write_u8 ( n : u8 ) ;
825+
826+ /// Write a i8 (1 byte).
738827 fn write_i8 ( n : i8 ) ;
739828}
740829
0 commit comments