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

Argument to ion_rs::value::Builder::new_blob, new_clob functions are &'static #465

Closed
dlurton opened this issue Jan 31, 2023 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@dlurton
Copy link

dlurton commented Jan 31, 2023

ion-rust/src/value/mod.rs

Lines 552 to 556 in 93da7e4

/// Builds a `clob` using Builder.
fn new_clob(bytes: &'static [u8]) -> Self::Element;
/// Builds a `blob` using Builder.
fn new_blob(bytes: &'static [u8]) -> Self::Element;

Which makes them pretty unusable in my case and I think most other cases as well. This is a big problem for my application because since we use a lot of blobs.

To demonstrate:

use ion_rs::value::Builder;
use ion_rs::value::owned::Element;

fn main() {
    let blob_elem = Element::new_blob("this compiles fine -- arg is already &'static ".as_bytes().into());
    println!("{:?}", blob_elem);

    let hello_world: Box<[u8]> = "hello, world!".as_bytes().into();
    let blob_elem = Element::new_blob(hello_world.as_ref());
    // |                              ^^^^^^^^^^^^^^^^^^^^
    // |                              |
    // |                              borrowed value does not live long enough
    // |                              argument requires that `hello_world` is borrowed for `'static`
    println!("{:?}", blob_elem);
}

Note that if you replace the argument with a string literal, i.e. Element::new_blob("hello, world!".into()), it works fine.

@dlurton dlurton added the bug Something isn't working label Jan 31, 2023
@dlurton
Copy link
Author

dlurton commented Jan 31, 2023

And while you're fixing this you might want to consider changing the bytes argument to be T: Into<Vec<u8>> as well.

@zslayton
Copy link
Contributor

This was fixed in #479 and will be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants