Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-7768

[Rust] Implement Length and TryClone traits for Cursor<Vec<u8>> in reader.rs

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 0.16.0
    • Rust

    Description

      Currently Length and TryClone are implemented for Cursor<&'a [u8]> in src/file/reader.rs

      Attempting to create a cursor from a Vec<u8>...

      fn test_cursor_and_file_has_the_same_behaviour() {
        let mut buf: Vec<u8> = Vec::new();        
        get_test_file("alltypes_plain.parquet")            
          .read_to_end(&mut buf)            
          .unwrap();        
        let cursor = Cursor::new(buf.as_slice());
      ...
      

       

      results in:

      `buf` does not live long enough
      
      borrowed value does not live long enough 
      rustc(E0597)
      reader.rs(681, 34): borrowed value does not live long enough
      reader.rs(681, 34): argument requires that `buf` is borrowed for `'static`
      reader.rs(691, 5): `buf` dropped here while still borrowed
      

       

      Implementing Length and TryClone for Cursor<Vec<u8>> would allow for:

      fn test_cursor_and_file_has_the_same_behaviour() {        
        let mut buf: Vec<u8> = Vec::new();        
        get_test_file("alltypes_plain.parquet")            
          .read_to_end(&mut buf)            
          .unwrap();        
        let cursor = Cursor::new(buf);
        let read_from_cursor = SerializedFileReader::new(cursor).unwrap();
      ...
      

      Otherwise, buf: Vec<u8> must be declared static in order to initialize a SerializedFileReader from a Cursor.

      I'm new to rust so perhaps this is the intended behavior, but if not I'm happy to submit a PR for this

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kegs David Kegley
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h