In the Rust API doc is a lot of the example code wrong?
5 25 Feb 2016 13:21 by u/box1663
I'm new to Rust and it's great but I keep finding situations where I can't get examples from their API docs to compile. It may be something I'm doing but I've banged against it long enough. Simple example from ([https://doc.rust-lang.org/std/io/](https://doc.rust-lang.org/std/io/)) : ~~~
fn main() { let mut f = try!(File::open("foo.txt")); let mut buffer = [0; 10];
// read up to 10 bytes try!(f.read(&mut buffer));
println!("The bytes: {:?}", buffer); } ~~~
The try macro on File::open causes a type ambiguity, error [E0308] which makes sense but are their examples supposed to be psuedo-code?
2 comments
0 u/MagicalCentaurBeans 26 Feb 2016 04:43
never used rust, but I run into this frequently with the android api docs. More than likely, the docs are outdated and haven't been reviewing/edited since implementing changes.
0 u/corvinusz 26 Feb 2016 04:55
There is a playground for rust-code from official docs. Rust has some small compatibility issues with compiler channels, i.e. stable compiler complains about unstable lib usage. I heard rust programmers use multirust tool that can easy change compiler channel in your system.