[−][src]Trait squash::Header
Description of the header encoding a length.
This is responsible to hold both a reference count (if applicable) and the length of the slice.
Note that it is not a trait consumers of this library would use directly and most common
implementations should be provided, so it is unlikely one would need to interact with it,
except for picking the right one as the type parameter of the OwnedSlice
or similar type.
Safety
The trait must correctly decode the same length as was encoded.
The reference counting must properly "pair" ‒ it must not ask for destruction while someone still holds a reference count.
Required methods
pub fn extra_needed(len: usize) -> Result<usize, TooLong>
[src]
How many extra bytes are needed for encoding this length.
Returns the amount of bytes needed, or signals that the length is too long for encoding.
pub unsafe fn encode_len(len: usize, extra: *mut u8) -> Self
[src]
Creates a new header and encodes the length.
Will be called with as many bytes as the extra_needed
designated,
passed as a pointer in the extra
parameter.
It shall encode a reference count of 1.
Safety
The extra
must point to at least as many bytes as asked for by
extra_needed
.
pub unsafe fn decode_len(&self, extra: *const u8) -> usize
[src]
Decodes the previously encoded length.
The extra bytes are provided back to it. Note that it is up to the header to know how many bytes there are.
Safety
The extra
must point to the bytes previously passed to
encode_len
.
pub fn inc(&self) -> bool
[src]
Increment the reference count.
Returns a success flag. If the reference count exceeds what the header can hold, a false is
returned to signal that it was not incremented. In that case, the
OwnedSlice
gets fully cloned instead.
pub fn dec(&self) -> bool
[src]
Decrements a reference count.
Returns if the reference count dropped to 0 and the slice should be destroyed.