alamb commented on a change in pull request #8726: URL: https://github.com/apache/arrow/pull/8726#discussion_r527978914
########## File path: rust/parquet/src/util/cursor.rs ########## @@ -129,6 +132,56 @@ impl Seek for SliceableCursor { } } +/// Use this type to write Parquet to memory rather than a file. +#[derive(Debug, Default, Clone)] +pub struct WriteableCursor { + buffer: Arc<Mutex<Cursor<Vec<u8>>>>, +} + +impl WriteableCursor { + /// Consume this instance and return the underlying buffer as long as there are no other + /// references to this instance. + pub fn into_inner(self) -> Option<Vec<u8>> { + Arc::try_unwrap(self.buffer) + .ok() + .and_then(|mutex| mutex.into_inner().ok()) + .map(|cursor| cursor.into_inner()) + } + + /// Returns a clone of the underlying buffer + pub fn data(&self) -> Vec<u8> { + let inner = self.buffer.lock().unwrap(); + inner.get_ref().to_vec() + } +} + +impl TryClone for WriteableCursor { + fn try_clone(&self) -> std::io::Result<Self> { + Ok(Self { + buffer: self.buffer.clone(), Review comment: THis is clever. 👍 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org