I want to return String from &Option<String> which is returned from config map from configparser::ini::Ini
use configparser::ini::Ini;
fn main() {
let filename : String = "p2pvpn.conf".to_owned();
let mut config = Ini::new();
let map = config.load(filename).unwrap();
let tunc = map.get("tun").unwrap(); //returns hashmap
/*
* 1st unwrap returns &Option<String>
* 2nd unwrap should return String
*/
let tunopt : String = tunc.get("ip").unwrap().unwrap(); //here is the problem
println!("{tunopt}");
}
But I am getting this error:
--> src/main.rs:9:28
|
9 | let tunopt : String = tunc.get("ip").unwrap().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `Option<String>`, which does not implement the `Copy` trait
|
help: consider borrowing the `Option`'s content
|
9 | let tunopt : String = tunc.get("ip").unwrap().unwrap().as_ref();
| +++++++++
I tried that option with as_ref, but it did not helped (expected struct String, found reference), and to_string did not helped too.
I know that first unwrap after get returns &Option<String> tunc.get("ip").unwrap().unwrap().
I tried this:
let tunopt : Option<String> = *(tunc.get("ip").unwrap()); //move this, deference using asterisk
I thought it will move ownership but still not working
13 | let tunopt : Option<String> = *(tunc.get("ip").unwrap()); //move this, deference using asterisk
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `Option<String>`, which does not implement the `Copy` trait
|
help: consider borrowing the `Option`'s content
My questions are:
- How to properly get value
Stringfrom option reference&Option<String>? - Why I can't deference
&Option<String>and move it's ownership to variable of typeOption<String>? - Why is it complaining about this:
not implement the 'Copy' trait', I am tring to move and not to copy.