Trait basenc::EncodeBuf
[−]
[src]
pub trait EncodeBuf { type Output; unsafe fn alloc(&mut self, len: usize) -> *mut u8; unsafe fn commit(self, len: usize) -> Self::Output; }
String buffer receiving encoded input.
Implementors
&mut [u8]
: Stack buffers. Panics if the buffer is too small.String
: Convenience. Appends to the buffer.&mut String
,&mut Vec<u8>
: Efficient buffer reuse. Appends to the buffer.
Examples
Start by calculating the upper_bound
of memory needed for encoding and buffer.alloc(upper_bound)
it.
Write at most upper_bound
of valid utf-8 bytes to this memory and buffer.commit(len)
where len
is the actual number of utf-8 bytes written.
Associated Types
type Output
Required Methods
unsafe fn alloc(&mut self, len: usize) -> *mut u8
Returns uninitialized memory of the requested length.
Increases the underlying buffer's capacity and returns those extra bytes without touching the buffer length.
Safety
The returned memory is logically uninitialized.
unsafe fn commit(self, len: usize) -> Self::Output
Commits len
bytes previously alloc
ated.
Sets the buffer length effectively appending the written bytes to the output.
Returns the encoded string.
Safety
The commit
ted len
must be less than or equal to the earlier alloc
ated len
.
The bytes written must be valid utf-8.
The buffer must not be touched in between calling alloc
and commit
.