I'm using GDAL package, which has a structure:
#[derive(Debug, Default)]
pub struct DatasetOptions<'a> {
pub open_flags: GdalOpenFlags,
pub allowed_drivers: Option<&'a [&'a str]>,
pub open_options: Option<&'a [&'a str]>,
pub sibling_files: Option<&'a [&'a str]>,
}
Trying to instantiate it, I can't create these Option<...str>
members:
allowed_drivers: Some("GPKG"))
error: src/main.rs:6: expected slice `[&str]`, found `str`
note: src/main.rs:6: expected reference `&[&str]`
Googling for two hours produced some SO questions and answers (1, 2, 3, none of which made this code compile.
&*"GPKG".to_owned(),
, &"GPKG"[..]
, and other ways all produce the same compilation error:
error: src/main.rs:6: expected slice `[&str]`, found `str`
note: src/main.rs:6: expected reference `&[&str]`
found reference `&str`
What's the way to work around this?
Example Cargo.toml
:
[package]
name = "sometest"
version = "0.1.0"
edition = "2018"
[dependencies]
gdal = "0.11"
Example main.rs
:
use gdal::{Dataset, DatasetOptions, GdalOpenFlags};
fn main() {
let dso = DatasetOptions {
open_flags: GdalOpenFlags::GDAL_OF_UPDATE,
allowed_drivers: Some(&"GPKG"[..]),
open_options: None,
sibling_files: None
};
}