logo资料库

Hands-On Functional Programming in Rust 1st Edition [PDF].pdf

第1页 / 共407页
第2页 / 共407页
第3页 / 共407页
第4页 / 共407页
第5页 / 共407页
第6页 / 共407页
第7页 / 共407页
第8页 / 共407页
资料共407页,剩余部分请下载后查看
Title Page
Copyright and Credits
Hands-On Functional Programming in Rust
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Functional Programming – a Comparison
Technical requirements
Reducing code weight and complexity
Making generics more generic
Functions as values
Iterators
Compact legible expressions
Strict abstraction means safe abstraction
Scoped data binding
Algebraic datatypes
Mixing object-oriented programming and functional programming
Improving project architecture
File hierarchy, modules, and namespace design
Functional design patterns
Metaprogramming
Summary
Questions
Further reading
Functional Control Flow
Technical requirements
Designing the program
Gathering project requirements
Architecting a code map from requirements
Creating a Rust project
Writing stubs for each program requirement
Implementing program logic
Filling in the blanks
Parsing input and storing as building description and floor requests
Updating location, velocity, and acceleration
If the next floor request in the queue is satisfied, then remove it from the queue
Adjusting motor control to process the next floor request
Printing real-time statistics
Printing summary
Breaking down long segments into components
Searching for abstractions
Writing tests
Unit testing
Integration testing
Summary
Questions
Functional Data Structures
Technical requirements
Adjusting to changing the scope of the project
Gathering new project requirements
Architecting a change map from requirements
Translating expectations into requirements
Translating requirements into a change map
Mapping requirements directly to code
Writing the physics simulator
Writing the motor controller
Writing the executable to run a simulation
Writing the executable to analyze a simulation
Running simulations and analyzing data
Summary
Questions
Generics and Polymorphism
Technical requirements
Staying productive during downtime
Learning about generics
Investigating generics
Investigating parametric polymorphism
Investigating generalized algebraic datatypes
Investigating parametric lifetimes
Defining lifetimes on ground types
Defining lifetimes on generic types
Defining lifetimes on traits
Defining lifetime subtyping
Investigating parametric types
Applying parameterization concepts
Parameterizing data
Parameterizing functions and trait objects
Parametric traits and implementations
Summary
Questions
Code Organization and Application Architecture
Technical requirements
Shipping a product without sacrificing quality
Reorganizing the project
Planning content of files by type
Organizing the motor_controllers.rs module
Organizing the buildings.rs module
Planning content of files by purpose
Organizing the motion_controllers.rs module
Organizing the trip_planning.rs module
Organizing the elevator_drivers.rs module
Planning content of files by layer
Organizing the physics.rs module
Organizing the data_recorder.rs module
Planning the content of files by convenience
Organizing the simulate_trip.rs executable
Organizing the analyze_trip.rs executable
Organizing the operate_elevator.rs executable
Mapping code changes and additions
Developing code by type
Writing the motor_controllers.rs module
Writing the buildings.rs module
Developing code by purpose
Writing the motion_controllers.rs module
Writing the trip_planning.rs module
Writing the elevator_drivers.rs module
Developing code by layer
Writing the physics.rs module
Writing the data_recorders.rs module
Developing code by convenience
Writing the simulate_trip.rs executable
Writing the analyze_trip.rs executable
Writing the operate_elevator.rs executable
Reflecting on the project structure
Summary
Questions
Mutability, Ownership, and Pure Functions
Technical requirements
Recognizing anti-patterns of ownership
Inspecting the microcontroller drivers
Inspecting the type and trait definitions
Defining the OverrideCode enum
Defining the ErrorCode enum
Defining the AuthorizedSession struct and deconstructor
Authorizing sessions
Checking errors and resetting state
Privileged commands
Normal commands
Querying library and session state
Inspecting the foreign library tests
Issuing override codes
Accessing status information and sessions
Deactivating active sessions
Issuing normal commands
Issuing privileged commands
Denying unauthorized commands
Inspecting the Rust tests
Rust authorization with sessions
Rust sharing session reference
Privileged commands
Unprivileged commands
Denying access to privileged commands
Learning the rules of ownership
When the owner goes out of scope, the value will be dropped
Using immutable data
Fixing the hard-to-reproduce bug
Preventing hard-to-reproduce bugs
Using pure functions
Summary
Questions
Design Patterns
Technical requirements
Using the functor pattern
Using the monad pattern
Using the combinator pattern
Parser combinators
Using the lazy evaluation pattern
Summary
Questions
Implementing Concurrency
Technical requirements
Using subprocess concurrency
Understanding nix fork concurrency
Using thread concurrency
Understanding Send and Sync traits
Using functional design for concurrency
Summary
Questions
Performance, Debugging, and Metaprogramming
Technical requirements
Writing faster code
Compiling with release mode
Doing less work
Optimizing the code that needs it – profiling
For a code rarely executed, performance is not affected
Multiples of small numbers are also small numbers
Measuring first, to optimize it
Putting the fridge next to the computer
Capping the Big O
Constanting no growth
Logarithmic growth
Polynomial growth
Exponential growth
Referencing data is faster
Preventing bugs with defensive coding
Using Option and Result instead of panic!
Using typesafe interfaces instead of stringly typed interfaces
Using the heartbeat pattern for long running processes
Validating input and output
Finding and fixing bugs
Metaprogramming
Summary
Questions
Assessments
Functional Programming – a Comparison
Functional Control Flow
Functional Data Structures
Generics and Polymorphism
Code Organization and Application Architecture
Mutability, Ownership, and Pure Functions
Design Patterns
Implementing Concurrency
Performance, Debugging, and Metaprogramming
Other Books You May Enjoy
Leave a review - let other readers know what you think
Hands-On Functional Programming in Rust Build modular and reactive applications with functional programming techniques in Rust 2018 Andrew Johnson
BIRMINGHAM - MUMBAI
Hands-On Functional Programming in Rust Copyright © 2018 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Richa Tripathi Acquisition Editor: Karan Sadawana Content Development Editor: Tiksha Sarang Technical Editor: Adhithya Haridas Copy Editor: Safis Editing Project Coordinator: Prajakta Naik Proofreader: Safis Editing Indexer: Rekha Nair Graphics: Jisha Chirayil Production Coordinator: Shantanu Zagade First published: May 2018 Production reference: 1300518 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78883-935-8 www.packtpub.com
mapt.io Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Mapt is fully searchable Copy and paste, print, and bookmark content
PacktPub.com Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktP ub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
分享到:
收藏