Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unncessary SliceReader #149

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/binary/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{
lexer::{read_id, read_string, read_token},
LexError, LexemeId, LexerError, Token,
};
use crate::buffer::{BufferError, BufferWindow, BufferWindowBuilder, SliceReader};
use crate::buffer::{BufferError, BufferWindow, BufferWindowBuilder};
use std::{fmt, io::Read};

/// [Lexer](crate::binary::Lexer) that works over a [Read] implementation
Expand Down Expand Up @@ -49,9 +49,9 @@ pub struct TokenReader<R> {
impl TokenReader<()> {
/// Read from a byte slice without memcpy's
#[inline]
pub fn from_slice(data: &[u8]) -> TokenReader<SliceReader<'_>> {
pub fn from_slice(data: &[u8]) -> TokenReader<&'_ [u8]> {
TokenReader {
reader: SliceReader::new(data),
reader: data,
buf: BufferWindow::from_slice(data),
}
}
Expand Down
18 changes: 1 addition & 17 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Scalar;
use std::{io::Read, marker::PhantomData, ops::Range};
use std::{io::Read, ops::Range};

#[derive(Debug)]
pub struct BufferWindow {
Expand Down Expand Up @@ -160,19 +160,3 @@ impl BufferWindowBuilder {
}
}
}

/// An no-op read implementation used for TokenReaders
#[derive(Debug)]
pub struct SliceReader<'a>(PhantomData<&'a [u8]>);

impl<'a> SliceReader<'a> {
pub(crate) fn new(_data: &'a [u8]) -> Self {
SliceReader(PhantomData)
}
}

impl<'a> Read for SliceReader<'a> {
fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
Ok(0)
}
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ pub(crate) mod util;

#[doc(inline)]
pub use self::binary::{BinaryTape, BinaryToken};
pub use self::buffer::SliceReader;
pub use self::encoding::*;
pub use self::errors::*;
pub use self::scalar::{Scalar, ScalarError};
Expand Down
6 changes: 3 additions & 3 deletions src/text/reader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Operator;
use crate::{
buffer::{BufferError, BufferWindow, BufferWindowBuilder, SliceReader},
buffer::{BufferError, BufferWindow, BufferWindowBuilder},
data::is_boundary,
util::{contains_zero_byte, count_chunk, repeat_byte},
Scalar,
Expand Down Expand Up @@ -102,9 +102,9 @@ pub struct TokenReader<R> {
impl TokenReader<()> {
/// Read from a byte slice without memcpy's
#[inline]
pub fn from_slice(data: &[u8]) -> TokenReader<SliceReader<'_>> {
pub fn from_slice(data: &[u8]) -> TokenReader<&'_ [u8]> {
TokenReader {
reader: SliceReader::new(data),
reader: data,
buf: BufferWindow::from_slice(data),
utf8: Utf8Bom::Unknown,
}
Expand Down