From 47fb4b85b83244af160749ffe3eb9c91cba23207 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Mon, 9 Sep 2024 11:09:18 -0500 Subject: [PATCH] Ensure BytesIter is an unsafe trait. Closes #104 Part of fixes to address #100 --- lexical-util/src/iterator.rs | 2 +- lexical-util/src/noskip.rs | 2 +- lexical-util/src/skip.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lexical-util/src/iterator.rs b/lexical-util/src/iterator.rs index 149ab92e..cb4b8adc 100644 --- a/lexical-util/src/iterator.rs +++ b/lexical-util/src/iterator.rs @@ -20,7 +20,7 @@ pub use crate::skip::{AsBytes, Bytes}; /// A default implementation is provided for slice iterators. /// This trait **should never** return `null` from `as_ptr`, or be /// implemented for non-contiguous data. -pub trait BytesIter<'a>: Iterator { +pub unsafe trait BytesIter<'a>: Iterator { /// Determine if each yielded value is adjacent in memory. const IS_CONTIGUOUS: bool; diff --git a/lexical-util/src/noskip.rs b/lexical-util/src/noskip.rs index 8abd9137..8c93557f 100644 --- a/lexical-util/src/noskip.rs +++ b/lexical-util/src/noskip.rs @@ -232,7 +232,7 @@ pub struct BytesIterator<'a: 'b, 'b, const __: u128> { byte: &'b mut Bytes<'a, __>, } -impl<'a: 'b, 'b, const __: u128> BytesIter<'a> for BytesIterator<'a, 'b, __> { +unsafe impl<'a: 'b, 'b, const __: u128> BytesIter<'a> for BytesIterator<'a, 'b, __> { const IS_CONTIGUOUS: bool = Bytes::<'a, __>::IS_CONTIGUOUS; #[inline(always)] diff --git a/lexical-util/src/skip.rs b/lexical-util/src/skip.rs index 591d9ca7..9fb4bbb9 100644 --- a/lexical-util/src/skip.rs +++ b/lexical-util/src/skip.rs @@ -721,7 +721,7 @@ macro_rules! skip_iterator_byteiter_base { /// Create impl ByteIter block for skip iterator. macro_rules! skip_iterator_byteiter_impl { ($iterator:ident, $mask:ident, $i:ident, $l:ident, $t:ident, $c:ident) => { - impl<'a: 'b, 'b, const FORMAT: u128> BytesIter<'a> for $iterator<'a, 'b, FORMAT> { + unsafe impl<'a: 'b, 'b, const FORMAT: u128> BytesIter<'a> for $iterator<'a, 'b, FORMAT> { skip_iterator_byteiter_base!(FORMAT, $mask); /// Peek the next value of the iterator, without consuming it. @@ -821,7 +821,7 @@ impl<'a: 'b, 'b, const FORMAT: u128> SpecialBytesIterator<'a, 'b, FORMAT> { is_digit_separator!(FORMAT); } -impl<'a: 'b, 'b, const FORMAT: u128> BytesIter<'a> for SpecialBytesIterator<'a, 'b, FORMAT> { +unsafe impl<'a: 'b, 'b, const FORMAT: u128> BytesIter<'a> for SpecialBytesIterator<'a, 'b, FORMAT> { skip_iterator_byteiter_base!(FORMAT, SPECIAL_DIGIT_SEPARATOR); /// Peek the next value of the iterator, without consuming it.