usestd::{borrow::Borrow,ops::Deref};usecrate::lexer::Token;/// A buffer of [`Token`]s.
#[derive(Default)]pub(crate)structTokenBuffer{rest:Vec<Token>,
}implTokenBuffer{/// Push a [`Token`] into the buffer.
pub(crate)fnpush(&mutself, token: Token){self.rest.push(token)}}implDeref forTokenBuffer{typeTarget= TokenSlice;fnderef(&self)->&Self::Target{let ptr =self.rest.as_slice()as*const[Token]as*const TokenSlice;// SAFETY: This pointer is valid because `TokenSlice` and `Token` have the same layout.
unsafe{&*ptr }}}implBorrow<TokenSlice>forTokenBuffer{fnborrow(&self)->&TokenSlice{self}}/// A slice of [`Token`]s.
#[repr(transparent)]pub(crate)structTokenSlice{rest: [Token],
}implToOwned forTokenSlice{typeOwned= TokenBuffer;fnto_owned(&self)->Self::Owned{
TokenBuffer {
rest:self.rest.to_owned(),}}}