This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.


Rust: from zero to pretty-well-versed in 30 minutes


I found the article <a href="" author="Amos">A half-hour to learn Rust</a> to be extremely helpful in learning the syntax and mechanics of Rust. It starts out with the absolute basics: <bq><c>let</c> introduces a variable binding [...]</bq> then takes you through <ul> Modules Blocks Conditionals Matches <c>Options</c> <c>mut</c>ables Copy/clone semantics Traits Generic parameters Constraints Macros Enums Lifetimes and borrowing Generic lifetimes Statics vs. owned vs. referenced Slices and range literals (<c>Index</c> and <c>IndexMut</c>) <c>Results</c> Errors, <c>panic</c> and <c>unwrap</c>, <c>expect()</c> and <c>?</c> Closures (<c>Fn</c>, <c>FnMut</c>, and <c>FnOnce</c>) <c>move</c> <c>for ... in</c> </ul> and ends up with a function builder that tests strings: <code> fn make_tester<'a>(answer: &'a str) -> impl Fn(&str) -> bool + 'a { move |challenge| { challenge == answer } } fn main() { let test = make_tester("hunter2"); println!("{}", test("*******")); println!("{}", test("hunter2")); } // output: // false // true </code>