Repository: pola-rs/polars
File: crates/polars-arrow/src/io/ipc/read/stream.rs (Rust)

Code before:
        .ok_or_else(|| polars_err!(oos = OutOfSpecKind::MissingMessageHeader))?;

    let block_length: usize = message
        .body_length()
        .map_err(|err| polars_err!(oos = OutOfSpecKind::InvalidFlatbufferBodyLength(err)))?
        .try_into()
        .map_err(|_| polars_err!(oos = OutOfSpecKind::UnexpectedNegativeInteger))?;

    match header {
        arrow_format::ipc::MessageHeaderRef::RecordBatch(batch) => {
            let cur_pos = reader.stream_position()?;

            let chunk = read_record_batch(
                batch,
                &metadata.schema,
                &metadata.ipc_schema,
                projection.as_ref().map(|x| x.columns.as_ref()),
                None,
                dictionaries,
                metadata.version,
                &mut reader.take(block_length as u64),
                0,
                scratch,
            );

            let new_pos = reader.stream_position()?;
            let read_size = new_pos - cur_pos;

            reader.seek(std::io::SeekFrom::Current(
                block_length as i64 - read_size as i64,
            ))?;

            if let Some(ProjectionInfo { map, .. }) = projection {
                // re-order according to projection
                chunk
                    .map(|chunk| apply_projection(chunk, map))
                    .map(|x| Some(StreamState::Some(x)))
            } else {
                chunk.map(|x| Some(StreamState::Some(x)))
            }
        },
        arrow_format::ipc::MessageHeaderRef::DictionaryBatch(batch) => {
            let cur_pos = reader.stream_position()?;

            read_dictionary(
                batch,
                &metadata.schema,
                &metadata.ipc_schema,
                dictionaries,
                &mut reader.take(block_length as u64),
                0,

Review comment (suggestion):
Can you make the reborrow of reader explicit here? That is, pass `&mut (&mut *reader).take(block_length as u64)` instead? Right now this only works because `reader.take` automatically gets transformed to `(&mut *reader).take`. I was really confused how this compiled since `take` takes `self` and should consume the `&mut R`.

Code after:
        .ok_or_else(|| polars_err!(oos = OutOfSpecKind::MissingMessageHeader))?;

    let block_length: usize = message
        .body_length()
        .map_err(|err| polars_err!(oos = OutOfSpecKind::InvalidFlatbufferBodyLength(err)))?
        .try_into()
        .map_err(|_| polars_err!(oos = OutOfSpecKind::UnexpectedNegativeInteger))?;

    match header {
        arrow_format::ipc::MessageHeaderRef::RecordBatch(batch) => {
            let cur_pos = reader.stream_position()?;

            let chunk = read_record_batch(
                batch,
                &metadata.schema,
                &metadata.ipc_schema,
                projection.as_ref().map(|x| x.columns.as_ref()),
                None,
                dictionaries,
                metadata.version,
                &mut (&mut *reader).take(block_length as u64),
                0,
                scratch,
            );

            let new_pos = reader.stream_position()?;
            let read_size = new_pos - cur_pos;

            reader.seek(std::io::SeekFrom::Current(
                block_length as i64 - read_size as i64,
            ))?;

            if let Some(ProjectionInfo { map, .. }) = projection {
                // re-order according to projection
                chunk
                    .map(|chunk| apply_projection(chunk, map))
                    .map(|x| Some(StreamState::Some(x)))
            } else {
                chunk.map(|x| Some(StreamState::Some(x)))
            }
        },
        arrow_format::ipc::MessageHeaderRef::DictionaryBatch(batch) => {
            let cur_pos = reader.stream_position()?;

            read_dictionary(
                batch,
                &metadata.schema,
                &metadata.ipc_schema,
                dictionaries,
                &mut (&mut *reader).take(block_length as u64),
                0,