RustInPractice
AProgrammersGuidetoBuildRustPrograms,TestApplicationsandCreate
CargoPackages
RustaceanTeam
Copyright©2023GitforGits
Allrightsreserved.
ISBN:978-8196228507
Contents
Preface
Chapter1:UnderstandingWhyRust!
WhytoLearnRustProgramming?
RustOverOtherProgrammingLanguages?
RustOverPython
RustOverC++andGo
BasicsofRustSyntax
Program‘Helloworld’
MyFirstProgram:CreatingaCalculator
Chapter2:GettingReadywithRustEnvironment
SettingUpRustonWindows
SettingUpRustonLinux
InstallingCratesandCargoonWindows
InstallingCratesandCargoonLinux
InstallingVisualStudioCodeonWindow
InstallingVisualStudioCodeonLinux
Chapter3:MostEssentialsofRust
Variables
Constants
ConstantsVsImmutableVariables
NecessityofConstantAgainstVariables
ShadowingVsMutability
Functions
TypesofFunctionsInRust
WritingaRustFunction
CodingaFunctionwithanIterator
PassingFunctionAsArguments
NestedFunction(FunctionWithinFunction)
Built-InFunctions
ControlFlow
IfStatements
LoopStatements
WhileStatements
ForStatements
MatchExpression
UnderstandingTraits
TypesofTraits
ImplementTraits
Do’sandDon'tsofUsingTrait
Unions
TypesofUnions
ImplementingUnions
Chapter4:Structs
UnderstandingStructs
TypesofStructs
WritingProgramUsingStruct
CustomStructs
WritingCustomStructProgram
WritingaNestedStructs
StructInheritanceInRust
Do’sandDon'tsofStruct
Chapter5:EnumsandPatternMatching
DefiningEnum
PatternMatching
AdvantageofEnumandPatternMatching
WritingaProgramForEnumFromScratch
AdvancedAspectsof‘match’Expression
UsingControlFlow
Do'sandDon'tsofEnum&PatternMatching
Chapter6:ExploringOwnershipandBorrowing
ConceptofOwnership
CharacteristicsofOwnership
CharacteristicsofBorrowing
Stack-allocatedVariablesandReferences
ApplicationsofOwnershipandBorrowing
LibrariesadoptingOwnershipandBorrowing
Chapter7:Cargo,CratesandPackages
UnderstandingCargo
UnderstandingCrates
UnderstandingPackages
CreatingMyFirstCrate
BuildMyFirstPackage
PublishThePackage
RoleofModulesandPathsInRust
AccessingCargoPackages
Chapter8:CargoCommands
GeneralandBuildCommands
ManifestCommands
PackageandPublishCommands
CustomCommands
Chapter9:UsingRustStandardLibrary
Overview
Std::Collections
Std::Error
Std::Net
Std::Sync
Std::Time
Std::Env
Std::Fmt
Std::Str
Std::Iter
Std::Ops
Std::Fs
PrimitiveTypes
Collections
Macros
WritingYourFirstMacro
Chapter10:MyFirstCommandLineApp(CLI)
FlowchartforCreatingCLIApplication
ProceduretoBuildCLIAplication
BuildingCLIApp:FileSortingProgram
Chapter11:CodeTestingofApplications
TypesofSoftwareTesting
RunCodeTestingonCLIApplication
Chapter12:SmartPointers&ReferenceCycles
UnderstandingSmartPointers
Box<T>
Rc<T>
Arc<T>
Weak<T>
UnderstandingReferenceCycles
TypesofReferenceCycles
CreatingaReferenceCycle:BetweenObjects
CreatingaReferenceCycle:BetweenObjects&Closure
PreventingReferenceCycles
Preface
RustInPracticeisanultimatefast-pacedguideforanyonelookingto
becomeapractitioneroftherustprogrammingfromday1.Thisbook
coverseverythingfromthebasicsofRustprogrammingtobuildingrobust
andefficientapplications.
Startingwiththefundamentals,thisbookguidesyouthroughthesyntaxand
semanticsoftheRustlanguage,includingitsuniqueownershipmodelandtype
system.You'lllearnaboutcommondatatypes,controlflow,errorhandling,and
more.
Asyouprogressthroughthebook,you'lldivedeeperintoadvancedtopicssuch
asbuildingprograms,rustlibrariesandcrates,usingthestandardlibrary,and
workingwithexternalcrates.You'llalsolearnhowtowriteconcurrentand
parallelcode,takeadvantageofRust'sbuilt-intestingfeatures,andusepopular
Rustframeworksandlibraries.
Thebookalsoprovideshands-onexamplesandexercisestohelpyoupractice
andapplytheconceptsyou'velearned.Bytheendofthisbook,you'llhavea
solidunderstandingofRustprogrammingandbewell-equippedtostartbuilding
yourownrobustandefficientapplications.Withclearexplanations,practical
examples,andexpertadvice,thisbookwillhelpyougetanedgeonRust
programmingandbecomeproficientinbuildingandtestingRustapplications,
rightfromdayone.
Inthisbookyouwilllearnhowto:
Getwellversedwithcargo,differentcargocommands
Understandingdatatypes,ownership,andborrowing
Writeflexible,efficientcodewithtraitsandgenerics
Makeuseofclosures,iterators,andasynchronousprogrammingtowritemultithreadedprograms
Utilizingcollections,strings,text,inputandoutput,macros,andavoidingunsafe
codes
Runcodetestingondifferenttypesofrustprogramsandapplications
50+examplescoveredtodemonstrateeveryfeatureandfunctionalityofrust
ThisbookiswrittenbyateamofRustprofessionalswithanintenttocontribute
andreturnbacktobothindustryandacademicresearchcommunities.
GitforGits
Prerequisites
Thisbookassumesyouareabsolutelynewtorustprogrammingandbelievesin
rusttomakesomeofthegreatperformingapplications.Ifyouknowanyother
programmingpriortothisbook,readingthisbookatspeedcanfinishtrulyina
day.
Rustisamodern,safeandefficientsystemsprogramminglanguagethatis
widelyusedinindustryandisagoodchoicefordeveloperswhowanttobuild
high-performance,concurrent,andsafesystems.
CodesUsage
Areyouinneedofsomehelpfulcodeexamplestoassistyouinyour
programminganddocumentation?Looknofurther!Ourbookoffersawealthof
supplementalmaterial,includingcodeexamplesandexercises.
Notonlyisthisbookheretoaidyouingettingyourjobdone,butyouhaveour
permissiontousetheexamplecodeinyourprogramsanddocumentation.
However,pleasenotethatifyouarereproducingasignificantportionofthe
code,wedorequireyoutocontactusforpermission.
Butdon'tworry,usingseveralchunksofcodefromthisbookinyourprogramor
answeringaquestionbycitingourbookandquotingexamplecodedoesnot
requirepermission.Butifyoudochoosetogivecredit,anattributiontypically
includesthetitle,author,publisher,andISBN.Forexample,"RustInPracticeby
theRustaceanTeam".
Ifyouareunsurewhetheryourintendeduseofthecodeexamplesfallsunderfair
useorthepermissionsoutlinedabove,pleasedonothesitatetoreachouttousat
Wearehappytoassistandclarifyanyconcerns.