Rust Essentials - Second Edition by Ivo Balbaert
Author:Ivo Balbaert
Language: eng
Format: epub, mobi, pdf
Tags: COM051070 - COMPUTERS / Programming Languages / C++, COM051220 - COMPUTERS / Programming / Parallel, COM051010 - COMPUTERS / Programming Languages / General
Publisher: Packt
Published: 2017-11-07T07:07:46+00:00
Methods on tuples and enums
In Rust, methods cannot only be defined on structs, they can also be defined on tuples and enums, and even on built-in types like integers.
Here is an example of an instance method mood defined on the variants of an Day enum. It matches the variant to print out the mood string of the day:
// see code in Chapter 6/code/method_enum.rs enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, } impl Day { fn mood(&self) { println!("{}", match *self { Day::Friday => "it's friday!", Day::Saturday | Day::Sunday => "weekend :-)", _ => "weekday...", }) } } fn main() { let today = Day::Tuesday; today.mood(); }
This prints out the following output:
weekday...
Download
Rust Essentials - Second Edition by Ivo Balbaert.mobi
Rust Essentials - Second Edition by Ivo Balbaert.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9928)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9803)
The Mikado Method by Ola Ellnestam Daniel Brolund(9787)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8310)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7791)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7772)
Grails in Action by Glen Smith Peter Ledbrook(7705)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7567)
Windows APT Warfare by Sheng-Hao Ma(6947)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6680)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6546)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6424)
Kotlin in Action by Dmitry Jemerov(5074)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4323)
Solidity Programming Essentials by Ritesh Modi(4062)
Functional Programming in JavaScript by Mantyla Dan(4044)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3855)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3796)
The Ultimate iOS Interview Playbook by Avi Tsadok(3773)
