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 some x: T several times in a row (with no other method calls on x in-between) never returns slices of decreasing length; and
  • if T implements AsMut<[Word]> then the above property must also hold for any sequence of calls of x.as_ref() and x.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.

Implementations on Foreign Types§

source§

impl<'a, Word> SafeBuf<Word> for &'a [Word]

source§

impl<'a, Word> SafeBuf<Word> for &'a mut [Word]

source§

impl<Word> SafeBuf<Word> for Box<[Word]>

source§

impl<Word> SafeBuf<Word> for Vec<Word>

Implementors§