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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
This trait abstracts common operations with actual buffer from implementation details
## Example usage
```no_run
use buf_ref_reader::Buffer;
use memchr::memchr;
use std::io::Read;
# fn foo<SomeBuffer: Buffer, R: Read>(mut input: R) -> Result<(), SomeBuffer::Error> {
// allocate 128 bytes of buffer or more
let mut buf = SomeBuffer::new(128)?;
// write data into free part of the buffer
let read = input.read(buf.appendable()).unwrap();
// append actually written bytes
buf.grow(read);
// read part of written data back
// this slice is only valid until another call to one of `buf`'s methods
let chunk = buf.consume(16);
let _ = chunk.len();
// we can also peek into filled part of the buffer
// as with `consume()`, this slice also has limited shelf life
let nl = memchr(b'\n', buf.filled());
if buf.appendable().len() == 0 {
// reserve some space before appending even more data
buf.enlarge()?;
}
let read = input.read(buf.appendable()).unwrap();
buf.grow(read);
// borrow checker will prevent `chunk` from being used at this point,
// and that makes sense as data might've been reallocated or destroyed
// during further manipulations with the buffer (e.g. `enlarge()`)
//let _ = chunk.len();
# Ok(())
# }
```
*/
pub use *;
pub use *;