RustSydney / talks

Talk requests and proposals for Rust Sydney
http://www.meetup.com/Rust-Sydney/
22 stars 2 forks source link

Overview of type conversion traits and techniques in Rust (beginner) #15

Open caspark opened 8 years ago

caspark commented 8 years ago

One of the things that new Rust developers struggle with is how to handle conversions between types. For example, "I have a str, how do I get a String?" has several answers (and it's not necessarily the same patterns as going from a String to a str - e.g. .to_string() is str-to-String specific), and it gets trickier if you want to return "str or String" (have to use Cow, plus there's also the Borrow and BorrowMut traits which have subtly different use cases to the AsRef and AsMut traits.

It'd be great if someone could give an overview of this in a newbie friendly way; all the information is available in decent format for consumption so it should just be a matter of learning it yourself and then presenting on it.

On a related note, at least one of the conversion traits (From) are also used for error handling with the try! macro (and I believe the upcoming ? syntax on Result too) to cut down on boilerplate, so it's probably worth touching on that too? (and/or error handling techniques could be a separate talk too.)

Useful sources for people putting talks together: