programming_rust.pdf

(10285 KB) Pobierz
Rust
FAST, SAFE SYSTEMS DEVELOPMENT
Programming
Jim Blandy & Jason Orendorff
Fast, Safe Systems Development
Programming Rust
Jim Blandy and Jason Orendorff
Beijing
Boston Farnham Sebastopol
Tokyo
Programming Rust
by Jim Blandy and Jason Orendorff
Copyright © 2018 Jim Blandy, Jason Orendorff. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editors:
Jeff Bleiel
Production Editor:
Colleen Cole
Copyeditor:
Jasmine Kwityn
Proofreader:
Sharon Wilkey
December 2017:
First Edition
Indexer:
WordCo Indexing Services, Inc.
Interior Designer:
David Futato
Cover Designer:
Karen Montgomery
Illustrator:
Rebecca Demarest
Revision History for the First Edition
2017-11-20:
First Release
See
http://oreilly.com/catalog/errata.csp?isbn=9781491927212
for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Programming Rust,
the cover image,
and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the authors have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
978-1-491-92728-1
[M]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
1.
Why Rust?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Type Safety
3
2.
A Tour of Rust. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Downloading and Installing Rust
A Simple Function
Writing and Running Unit Tests
Handling Command-Line Arguments
A Simple Web Server
Concurrency
What the Mandelbrot Set Actually Is
Parsing Pair Command-Line Arguments
Mapping from Pixels to Complex Numbers
Plotting the Set
Writing Image Files
A Concurrent Mandelbrot Program
Running the Mandelbrot Plotter
Safety Is Invisible
7
10
11
12
17
23
24
28
31
32
33
35
40
41
3.
Basic Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Machine Types
Integer Types
Floating-Point Types
The bool Type
Characters
Tuples
46
47
50
51
52
54
iii
Zgłoś jeśli naruszono regulamin