Trait constriction::backends::SafeBuf
source · pub unsafe trait SafeBuf<Word>: AsRef<[Word]> { }
Expand description
Unsafe marker trait indicating sane implementation of AsRef
(and possibly AsMut
).
By implementing SafeBuf<Word>
for a type T
, you guarantee that
- calling
x.as_ref()
for somex: T
several times in a row (with no other method calls onx
in-between) never returns slices of decreasing length; and - if
T
implementsAsMut<[Word]>
then the above property must also hold for any sequence of calls ofx.as_ref()
andx.as_mut()
, and the lengths of slices returned by either of these calls must not decrease.
This is very likely the behaviour you would expect anyway for AsRef
and AsMut
. This
guarantee allows the implementation of ReadWords<Word, Stack>
for Cursor
to elide
an additional pedantic bounds check by maintaining an in-bounds invariant on its index
into the buffer.
Safety
If SafeBuf
is implemented for a type Buf
that violates the above contract then the
implementations of ReadWords<Word, Stack>::read
for Cursor<Word, Buf>
and of
WriteWords<Word>
for Reverse<Cursor<Word, Buf>>
may attempt to access the buffer out
of bounds without bounds checks.