MarkBiesheuvel / optimizely-rust-sdk

An unofficial Rust SDK for Optimizely Feature Experimentation
0 stars 1 forks source link

Add lifetime parameters throughout datafile module #8

Closed MarkBiesheuvel closed 1 year ago

MarkBiesheuvel commented 1 year ago

And reduce the number of .to_owned() calls

MarkBiesheuvel commented 1 year ago

First try failed.

At the moment the ClientBuilder is the owner of the content variable. If the ClientBuilder goes out of scope. So do all references.

Idea: implement a similar function signature to std::io::Read::read_to_string.

let mut buffer = String::new();
let client = ClientBuilder::new()
        .with_local_datafile(FILE_PATH, buffer)?
        .build()?;

Now, buffer will remain in scope, so client is allowed to have references to it.

MarkBiesheuvel commented 1 year ago

Second attempt failed.

The challenge is the keep the datafile::Json variable in scope, while also passing it (as mutable reference) to many different constructors.

MarkBiesheuvel commented 1 year ago

At the moment, there is no reason to optimize memory management of parsing the datafile. Using owned String values is fine for now.