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: FlatBuffers are impossible to return from functions #8225

Open
Nickersoft opened this issue Jan 29, 2024 · 0 comments
Open

Rust: FlatBuffers are impossible to return from functions #8225

Nickersoft opened this issue Jan 29, 2024 · 0 comments

Comments

@Nickersoft
Copy link

Hey folks!

Full disclaimer: I'm a bit of a newbie at Rust, but am running up against an issue I've scoured the internet for and can't find a solution that applies to the FlatBuffers library. What I'm trying to do is very simple, which is read data from a file, load it into a FB, and return it in a Result:

fn read_from_path(path: &str) -> Result<DictionaryBuffer, Box<dyn Error>> {
    let contents = read_file(path)?;
    let buf = crate::schema_generated::root_as_dictionary_buffer(&contents)?;

    Ok(buf)
}

However, naturally I receive the error:

cannot return value referencing local variable `contents` returns a value referencing data owned by the current function. 

`contents` is borrowed here.

Makes sense, seeing I'm passing a ref to contents to the FB method. Yet, from what I can tell, the returned buffer should be owned, no? I'm not trying to return a reference to the buffer, which is the root cause of the majority of cases I've seen online.

Anyone have an idea how to work around this, or is it an issue with how FB is being implemented? I noticed all the examples instantiate buffers inside a main method, so I have no reference for how to approach this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant