@@ -145,45 +145,61 @@ pub trait Bytes<A> {
145
145
/// Associated error codes
146
146
type E ;
147
147
148
- /// Writes a slice into the container at the specified address.
148
+ /// Writes a slice into the container at `addr`.
149
+ ///
149
150
/// Returns the number of bytes written. The number of bytes written can
150
151
/// be less than the length of the slice if there isn't enough room in the
151
152
/// container.
152
153
fn write ( & self , buf : & [ u8 ] , addr : A ) -> Result < usize , Self :: E > ;
153
154
154
- /// Reads to a slice from the container at the specified address.
155
+ /// Reads data from the container at `addr` into a slice.
156
+ ///
155
157
/// Returns the number of bytes read. The number of bytes read can be less than the length
156
- /// of the slice if there isn't enough room within the container.
158
+ /// of the slice if there isn't enough data within the container.
157
159
fn read ( & self , buf : & mut [ u8 ] , addr : A ) -> Result < usize , Self :: E > ;
158
160
159
- /// Writes the entire contents of a slice into the container at the specified address.
161
+ /// Writes the entire content of a slice into the container at `addr`.
162
+ ///
163
+ /// # Errors
160
164
///
161
- /// Returns an error if there isn't enough room within the container to complete the entire
162
- /// write. Part of the data may have been written nevertheless.
165
+ /// Returns an error if there isn't enough space within the container to write the entire slice.
166
+ /// Part of the data may have been copied nevertheless.
163
167
fn write_slice ( & self , buf : & [ u8 ] , addr : A ) -> Result < ( ) , Self :: E > ;
164
168
165
- /// Reads from the container at the specified address to fill the entire buffer .
169
+ /// Reads data from the container at `addr` to fill an entire slice .
166
170
///
167
- /// Returns an error if there isn't enough room within the container to fill the entire buffer.
168
- /// Part of the buffer may have been filled nevertheless.
171
+ /// # Errors
172
+ ///
173
+ /// Returns an error if there isn't enough data within the container to fill the entire slice.
174
+ /// Part of the data may have been copied nevertheless.
169
175
fn read_slice ( & self , buf : & mut [ u8 ] , addr : A ) -> Result < ( ) , Self :: E > ;
170
176
171
- /// Writes an object into the container at the specified address.
172
- /// Returns Ok(()) if the object fits, or Err if it extends past the end.
177
+ /// Writes an object into the container at `addr`.
178
+ ///
179
+ /// # Errors
180
+ ///
181
+ /// Returns an error if the object doesn't fit inside the container.
173
182
fn write_obj < T : ByteValued > ( & self , val : T , addr : A ) -> Result < ( ) , Self :: E > {
174
183
self . write_slice ( val. as_slice ( ) , addr)
175
184
}
176
185
177
- /// Reads an object from the container at the given address.
186
+ /// Reads an object from the container at `addr`.
187
+ ///
178
188
/// Reading from a volatile area isn't strictly safe as it could change mid-read.
179
189
/// However, as long as the type T is plain old data and can handle random initialization,
180
190
/// everything will be OK.
191
+ ///
192
+ /// # Errors
193
+ ///
194
+ /// Returns an error if there's not enough data inside the container.
181
195
fn read_obj < T : ByteValued > ( & self , addr : A ) -> Result < T , Self :: E > {
182
196
let mut result: T = Default :: default ( ) ;
183
197
self . read_slice ( result. as_mut_slice ( ) , addr) . map ( |_| result)
184
198
}
185
199
186
- /// Writes data from a readable object like a File and writes it into the container.
200
+ /// Reads up to `count` bytes from an object and writes them into the container at `addr`.
201
+ ///
202
+ /// Returns the number of bytes written into the container.
187
203
///
188
204
/// # Arguments
189
205
/// * `addr` - Begin writing at this address.
@@ -193,32 +209,44 @@ pub trait Bytes<A> {
193
209
where
194
210
F : Read ;
195
211
196
- /// Writes data from a readable object like a File and writes it into the container.
212
+ /// Reads exactly `count` bytes from an object and writes them into the container at `addr`.
213
+ ///
214
+ /// # Errors
215
+ ///
216
+ /// Returns an error if `count` bytes couldn't have been copied from `src` to the container.
217
+ /// Part of the data may have been copied nevertheless.
197
218
///
198
219
/// # Arguments
199
220
/// * `addr` - Begin writing at this address.
200
221
/// * `src` - Copy from `src` into the container.
201
- /// * `count` - Copy `count` bytes from `src` into the container.
222
+ /// * `count` - Copy exactly `count` bytes from `src` into the container.
202
223
fn read_exact_from < F > ( & self , addr : A , src : & mut F , count : usize ) -> Result < ( ) , Self :: E >
203
224
where
204
225
F : Read ;
205
226
206
- /// Reads data from the container to a writable object.
227
+ /// Reads up to `count` bytes from the container at `addr` and writes them it into an object.
228
+ ///
229
+ /// Returns the number of bytes written into the object.
207
230
///
208
231
/// # Arguments
209
- /// * `addr` - Begin reading from this addr .
232
+ /// * `addr` - Begin reading from this address .
210
233
/// * `dst` - Copy from the container to `dst`.
211
234
/// * `count` - Copy `count` bytes from the container to `dst`.
212
235
fn write_to < F > ( & self , addr : A , dst : & mut F , count : usize ) -> Result < usize , Self :: E >
213
236
where
214
237
F : Write ;
215
238
216
- /// Reads data from the container to a writable object.
239
+ /// Reads exactly `count` bytes from the container at `addr` and writes them into an object.
240
+ ///
241
+ /// # Errors
242
+ ///
243
+ /// Returns an error if `count` bytes couldn't have been copied from the container to `dst`.
244
+ /// Part of the data may have been copied nevertheless.
217
245
///
218
246
/// # Arguments
219
- /// * `addr` - Begin reading from this addr .
247
+ /// * `addr` - Begin reading from this address .
220
248
/// * `dst` - Copy from the container to `dst`.
221
- /// * `count` - Copy `count` bytes from the container to `dst`.
249
+ /// * `count` - Copy exactly `count` bytes from the container to `dst`.
222
250
fn write_all_to < F > ( & self , addr : A , dst : & mut F , count : usize ) -> Result < ( ) , Self :: E >
223
251
where
224
252
F : Write ;
0 commit comments