pub trait DataSink {
Show 25 methods
// Required method
fn write_bytes(&mut self, buf: &[u8]) -> Result;
// Provided methods
fn write_utf8(&mut self, value: &str) -> Result { ... }
fn write_utf8_codepoint(&mut self, value: char) -> Result { ... }
fn write_u8(&mut self, value: u8) -> Result { ... }
fn write_i8(&mut self, value: i8) -> Result { ... }
fn write_u16(&mut self, value: u16) -> Result { ... }
fn write_i16(&mut self, value: i16) -> Result { ... }
fn write_u16_le(&mut self, value: u16) -> Result { ... }
fn write_i16_le(&mut self, value: i16) -> Result { ... }
fn write_u32(&mut self, value: u32) -> Result { ... }
fn write_i32(&mut self, value: i32) -> Result { ... }
fn write_u32_le(&mut self, value: u32) -> Result { ... }
fn write_i32_le(&mut self, value: i32) -> Result { ... }
fn write_u64(&mut self, value: u64) -> Result { ... }
fn write_i64(&mut self, value: i64) -> Result { ... }
fn write_u64_le(&mut self, value: u64) -> Result { ... }
fn write_i64_le(&mut self, value: i64) -> Result { ... }
fn write_u128(&mut self, value: u128) -> Result { ... }
fn write_i128(&mut self, value: i128) -> Result { ... }
fn write_u128_le(&mut self, value: u128) -> Result { ... }
fn write_i128_le(&mut self, value: i128) -> Result { ... }
fn write_usize(&mut self, value: usize) -> Result { ... }
fn write_isize(&mut self, value: isize) -> Result { ... }
fn write_usize_le(&mut self, value: usize) -> Result { ... }
fn write_isize_le(&mut self, value: isize) -> Result { ... }
}
Expand description
A sink stream of data.
Required Methods§
Sourcefn write_bytes(&mut self, buf: &[u8]) -> Result
fn write_bytes(&mut self, buf: &[u8]) -> Result
Writes all bytes from buf
. Equivalent to Write::write_all
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_bytes(b"Hello!")?;
assert_eq!(buf, b"Hello!");
Provided Methods§
Sourcefn write_utf8(&mut self, value: &str) -> Result
fn write_utf8(&mut self, value: &str) -> Result
Sourcefn write_utf8_codepoint(&mut self, value: char) -> Result
fn write_utf8_codepoint(&mut self, value: char) -> Result
Writes a single UTF-8 codepoint.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_utf8_codepoint('🍉')?;
assert_eq!(buf, "🍉".as_bytes());
Sourcefn write_u16_le(&mut self, value: u16) -> Result
fn write_u16_le(&mut self, value: u16) -> Result
Writes a little-endian u16
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_u16_le(0x1234)?;
assert_eq!(buf, [0x34, 0x12]);
Sourcefn write_i16_le(&mut self, value: i16) -> Result
fn write_i16_le(&mut self, value: i16) -> Result
Writes a little-endian i16
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_i16_le(0x1234)?;
assert_eq!(buf, [0x34, 0x12]);
Sourcefn write_u32(&mut self, value: u32) -> Result
fn write_u32(&mut self, value: u32) -> Result
Writes a big-endian u32
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_u32(0x12345678)?;
assert_eq!(buf, [0x12, 0x34, 0x56, 0x78]);
Sourcefn write_i32(&mut self, value: i32) -> Result
fn write_i32(&mut self, value: i32) -> Result
Writes a big-endian i32
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_i32(0x12345678)?;
assert_eq!(buf, [0x12, 0x34, 0x56, 0x78]);
Sourcefn write_u32_le(&mut self, value: u32) -> Result
fn write_u32_le(&mut self, value: u32) -> Result
Writes a little-endian u32
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_u32_le(0x12345678)?;
assert_eq!(buf, [0x78, 0x56, 0x34, 0x12]);
Sourcefn write_i32_le(&mut self, value: i32) -> Result
fn write_i32_le(&mut self, value: i32) -> Result
Writes a little-endian i32
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_i32_le(0x12345678)?;
assert_eq!(buf, [0x78, 0x56, 0x34, 0x12]);
Sourcefn write_u64(&mut self, value: u64) -> Result
fn write_u64(&mut self, value: u64) -> Result
Writes a big-endian u64
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_u64(0x1234_5678_9ABC_DEF0)?;
assert_eq!(buf, [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]);
Sourcefn write_i64(&mut self, value: i64) -> Result
fn write_i64(&mut self, value: i64) -> Result
Writes a big-endian i64
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_i64(0x1234_5678_9ABC_DEF0)?;
assert_eq!(buf, [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]);
Sourcefn write_u64_le(&mut self, value: u64) -> Result
fn write_u64_le(&mut self, value: u64) -> Result
Writes a little-endian u64
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_u64_le(0x1234_5678_9ABC_DEF0)?;
assert_eq!(buf, [0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]);
Sourcefn write_i64_le(&mut self, value: i64) -> Result
fn write_i64_le(&mut self, value: i64) -> Result
Writes a little-endian i64
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_i64_le(0x1234_5678_9ABC_DEF0)?;
assert_eq!(buf, [0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]);
Sourcefn write_u128(&mut self, value: u128) -> Result
fn write_u128(&mut self, value: u128) -> Result
Writes a big-endian u128
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_u128(0x1234_5678_9ABC_DEF0_0FED_CBA9_8765_4321)?;
assert_eq!(buf, [
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
0x0F, 0xED, 0xCB, 0xA9, 0x87, 0x65, 0x43, 0x21
]);
Sourcefn write_i128(&mut self, value: i128) -> Result
fn write_i128(&mut self, value: i128) -> Result
Writes a big-endian i128
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_i128(0x1234_5678_9ABC_DEF0_0FED_CBA9_8765_4321)?;
assert_eq!(buf, [
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
0x0F, 0xED, 0xCB, 0xA9, 0x87, 0x65, 0x43, 0x21
]);
Sourcefn write_u128_le(&mut self, value: u128) -> Result
fn write_u128_le(&mut self, value: u128) -> Result
Writes a little-endian u128
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_u128_le(0x1234_5678_9ABC_DEF0_0FED_CBA9_8765_4321)?;
assert_eq!(buf, [
0x21, 0x43, 0x65, 0x87, 0xA9, 0xCB, 0xED, 0x0F,
0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12
]);
Sourcefn write_i128_le(&mut self, value: i128) -> Result
fn write_i128_le(&mut self, value: i128) -> Result
Writes a little-endian i128
.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_i128_le(0x1234_5678_9ABC_DEF0_0FED_CBA9_8765_4321)?;
assert_eq!(buf, [
0x21, 0x43, 0x65, 0x87, 0xA9, 0xCB, 0xED, 0x0F,
0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12
]);
Sourcefn write_usize(&mut self, value: usize) -> Result
fn write_usize(&mut self, value: usize) -> Result
Writes a big-endian usize
. To make streams consistent across platforms,
usize
is fixed to the size of u64
regardless of the target platform.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_usize(0x1234_5678_9ABC_DEF0)?;
assert_eq!(buf, [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]);
Sourcefn write_isize(&mut self, value: isize) -> Result
fn write_isize(&mut self, value: isize) -> Result
Writes a big-endian isize
. To make streams consistent across platforms,
isize
is fixed to the size of i64
regardless of the target platform.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_isize(0x1234_5678_9ABC_DEF0)?;
assert_eq!(buf, [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]);
Sourcefn write_usize_le(&mut self, value: usize) -> Result
fn write_usize_le(&mut self, value: usize) -> Result
Writes a little-endian usize
. To make streams consistent across platforms,
usize
is fixed to the size of u64
regardless of the target platform.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_usize_le(0x1234_5678_9ABC_DEF0)?;
assert_eq!(buf, [0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]);
Sourcefn write_isize_le(&mut self, value: isize) -> Result
fn write_isize_le(&mut self, value: isize) -> Result
Writes a little-endian isize
. To make streams consistent across platforms,
isize
is fixed to the size of i64
regardless of the target platform.
§Errors
May return Overflow
if the sink would exceed some hard
storage limit. In the case, the stream is filled completely, excluding the
overflowing bytes.
§Example
use data_streams::DataSink;
let mut buf = Vec::new();
buf.write_isize_le(0x1234_5678_9ABC_DEF0)?;
assert_eq!(buf, [0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]);