File: test_from_buf.rs

package info (click to toggle)
rust-bytes 0.4.10-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 372 kB
  • sloc: sh: 58; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 792 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
extern crate bytes;

use bytes::{Buf, Bytes, BytesMut};
use std::io::Cursor;

const LONG: &'static [u8] = b"mary had a little lamb, little lamb, little lamb";
const SHORT: &'static [u8] = b"hello world";

#[test]
fn collect_to_vec() {
    let buf: Vec<u8> = Cursor::new(SHORT).collect();
    assert_eq!(buf, SHORT);

    let buf: Vec<u8> = Cursor::new(LONG).collect();
    assert_eq!(buf, LONG);
}

#[test]
fn collect_to_bytes() {
    let buf: Bytes = Cursor::new(SHORT).collect();
    assert_eq!(buf, SHORT);

    let buf: Bytes = Cursor::new(LONG).collect();
    assert_eq!(buf, LONG);
}

#[test]
fn collect_to_bytes_mut() {
    let buf: BytesMut = Cursor::new(SHORT).collect();
    assert_eq!(buf, SHORT);

    let buf: BytesMut = Cursor::new(LONG).collect();
    assert_eq!(buf, LONG);
}