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

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

Closed
asfimport opened this issue Feb 4, 2020 · 1 comment
Closed

Comments

@asfimport
Copy link

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

Attempting to create a cursor from a Vec...

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> 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 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

 

Reporter: David Kegley / @dbkegley

PRs and other links:

Note: This issue was originally created as ARROW-7768. Please see the migration documentation for further details.

@asfimport
Copy link
Author

Chao Sun / @sunchao:
Issue resolved by pull request 6376
#6376

@asfimport asfimport added this to the 0.16.0 milestone Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant