Skip to content

Commit

Permalink
Add non-blocking RawTextReader & TextBuffer (#416)
Browse files Browse the repository at this point in the history
This echos the addition of the non-blocking binary reader and duplicates
(with modifications) the existing RawTextReader, and TextBuffer into a
non_blocking module with the intention of updating the existing blocking
version to lean on this non-blocking version.
  • Loading branch information
nirosys committed Sep 21, 2022
1 parent 4e5fd14 commit 16382f4
Show file tree
Hide file tree
Showing 6 changed files with 1,832 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub enum IonError {
#[error("ran out of input while reading {label} at offset {offset}")]
Incomplete { label: &'static str, offset: usize },

/// Indicates that the text input did not contain enough data to perform the requested read
/// operation. If the input source contains more data, the reader can append it to the buffer
/// and try again.
#[error("ran out of input while reading at line: {line} column: {column}")]
IncompleteText { line: usize, column: usize },

/// Indicates that the writer encountered a problem while serializing a given piece of data.
#[error("{description}")]
EncodingError { description: String },
Expand Down Expand Up @@ -63,6 +69,10 @@ impl Clone for IonError {
label,
offset: *offset,
},
IncompleteText { line, column } => IncompleteText {
line: *line,
column: *column,
},
EncodingError { description } => EncodingError {
description: description.clone(),
},
Expand Down Expand Up @@ -111,6 +121,14 @@ pub fn incomplete_data_error_raw(label: &'static str, offset: usize) -> IonError
IonError::Incomplete { label, offset }
}

pub fn incomplete_text_error<T>(line: usize, column: usize) -> IonResult<T> {
Err(incomplete_text_error_raw(line, column))
}

pub fn incomplete_text_error_raw(line: usize, column: usize) -> IonError {
IonError::IncompleteText { line, column }
}

/// A convenience method for creating an IonResult containing an IonError::DecodingError with the
/// provided description text.
pub fn decoding_error<T, S: AsRef<str>>(description: S) -> IonResult<T> {
Expand Down
1 change: 1 addition & 0 deletions src/text/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod non_blocking;
mod parent_container;
pub(crate) mod parse_result;
pub(in crate::text) mod parsers;
Expand Down
2 changes: 2 additions & 0 deletions src/text/non_blocking/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod raw_text_reader;
pub mod text_buffer;
Loading

0 comments on commit 16382f4

Please sign in to comment.