]> git.lizzy.rs Git - rust.git/commitdiff
Make example function in comment more idiomatic
authorCorey Farwell <coreyf@rwell.org>
Sat, 4 Apr 2015 01:32:29 +0000 (18:32 -0700)
committerCorey Farwell <coreyf@rwell.org>
Sat, 4 Apr 2015 01:32:29 +0000 (18:32 -0700)
src/libcore/result.rs

index eff04dd5903936f997ff147a76d39b530349cb63..5be46a09a95d2004f3d4fb6375568a05c6f91c20 100644 (file)
 //! enum Version { Version1, Version2 }
 //!
 //! fn parse_version(header: &[u8]) -> Result<Version, &'static str> {
-//!     if header.len() < 1 {
-//!         return Err("invalid header length");
-//!     }
-//!     match header[0] {
-//!         1 => Ok(Version::Version1),
-//!         2 => Ok(Version::Version2),
-//!         _ => Err("invalid version")
+//!     match header.get(0) {
+//!         None => Err("invalid header length"),
+//!         Some(&1) => Ok(Version::Version1),
+//!         Some(&2) => Ok(Version::Version2),
+//!         Some(_) => Err("invalid version")
 //!     }
 //! }
 //!