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

feat: add get_{ref, mut} to arrow_ipc Reader and Writer #4122

Merged
merged 1 commit into from
Apr 25, 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
28 changes: 28 additions & 0 deletions arrow-ipc/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,20 @@ impl<R: Read + Seek> FileReader<R> {
))),
}
}

/// Gets a reference to the underlying reader.
///
/// It is inadvisable to directly read from the underlying reader.
Comment on lines +1043 to +1044
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///
/// It is inadvisable to directly read from the underlying reader.

Reading requires mutable access so this comment is possibly redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes reading doesn't require a mutable reference (e.g. &File implements Read), so I think the comment is worth having.

pub fn get_ref(&self) -> &R {
self.reader.get_ref()
}

/// Gets a mutable reference to the underlying reader.
///
/// It is inadvisable to directly read from the underlying reader.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pub fn get_mut(&mut self) -> &mut R {
self.reader.get_mut()
}
}

impl<R: Read + Seek> Iterator for FileReader<R> {
Expand Down Expand Up @@ -1243,6 +1257,20 @@ impl<R: Read> StreamReader<R> {
)),
}
}

/// Gets a reference to the underlying reader.
///
/// It is inadvisable to directly read from the underlying reader.
Comment on lines +1262 to +1263
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///
/// It is inadvisable to directly read from the underlying reader.

pub fn get_ref(&self) -> &R {
self.reader.get_ref()
}

/// Gets a mutable reference to the underlying reader.
///
/// It is inadvisable to directly read from the underlying reader.
pub fn get_mut(&mut self) -> &mut R {
self.reader.get_mut()
}
}

impl<R: Read> Iterator for StreamReader<R> {
Expand Down
24 changes: 24 additions & 0 deletions arrow-ipc/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,18 @@ impl<W: Write> FileWriter<W> {
Ok(())
}

/// Gets a reference to the underlying writer.
pub fn get_ref(&self) -> &W {
self.writer.get_ref()
}

/// Gets a mutable reference to the underlying writer.
///
/// It is inadvisable to directly write to the underlying writer.
pub fn get_mut(&mut self) -> &mut W {
self.writer.get_mut()
}

/// Unwraps the BufWriter housed in FileWriter.writer, returning the underlying
/// writer
///
Expand Down Expand Up @@ -920,6 +932,18 @@ impl<W: Write> StreamWriter<W> {
Ok(())
}

/// Gets a reference to the underlying writer.
pub fn get_ref(&self) -> &W {
self.writer.get_ref()
}

/// Gets a mutable reference to the underlying writer.
///
/// It is inadvisable to directly write to the underlying writer.
pub fn get_mut(&mut self) -> &mut W {
self.writer.get_mut()
}

/// Unwraps the BufWriter housed in StreamWriter.writer, returning the underlying
/// writer
///
Expand Down