rust-ini has a function:
pub fn section<'a, S>(&'a self, name: Option<S>) -> Option<&'a Properties>
where S: Into<String>
I want to read a file without sections, so I call it like this:
let ifo_cfg = match Ini::load_from_file("conf.ini") {
Result::Ok(cfg) => cfg,
Result::Err(err) => return Result::Err(err.msg),
};
let section = ifo_cfg.section(None).unwrap();
But it gives a compile error:
unable to infer enough type information about
_
; type annotations or generic parameter binding required [E0282]
I can fix it like this:
let none: Option<String> = None;
let section = ifo_cfg.section(none).unwrap();
How can fix this without the additional line with none
?
You could specify the type of the
T
in the typeOption<T>
for thisNone
with:Alternatively, you could specify the type
S
of the methodsection
:You can also look up E0282's explanation, although it might not really answer your question at this time :)
The syntax
::<T,U,V>
is sometimes called the turbofish. Some very generic methods likeString::parse()
andIterator::collect()
can return almost anything, and type inference does not have enough information to find the actual type. The::<T,U,V>
allow the human to tell the compiler what generic parameter should be substituted. Fromparse()
's reference: