100% found this document useful (4 votes)
300 views

Instant ebooks textbook The Rust Programming Language Steve Klabnik download all chapters

Rust

Uploaded by

babikgodbyka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
300 views

Instant ebooks textbook The Rust Programming Language Steve Klabnik download all chapters

Rust

Uploaded by

babikgodbyka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Get ebook downloads in full at ebookmeta.

com

The Rust Programming Language Steve Klabnik

https://ebookmeta.com/product/the-rust-programming-language-
steve-klabnik/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

The Rust Programming Language 2nd Edition Steve Klabnik

https://ebookmeta.com/product/the-rust-programming-language-2nd-
edition-steve-klabnik/

ebookmeta.com

The Rust Programming Language, Second Edition Steve


Klabnik

https://ebookmeta.com/product/the-rust-programming-language-second-
edition-steve-klabnik/

ebookmeta.com

Black Hat Rust Applied offensive security with the Rust


programming language Sylvain Kerkour

https://ebookmeta.com/product/black-hat-rust-applied-offensive-
security-with-the-rust-programming-language-sylvain-kerkour-2/

ebookmeta.com

Learning Vocabulary in Another Language 3rd Edition I. S.


P. Nation

https://ebookmeta.com/product/learning-vocabulary-in-another-
language-3rd-edition-i-s-p-nation/

ebookmeta.com
Media Analytics: Understanding Media, Audiences, and
Consumers in the 21st Century 1st Edition C. Ann
Hollifield
https://ebookmeta.com/product/media-analytics-understanding-media-
audiences-and-consumers-in-the-21st-century-1st-edition-c-ann-
hollifield/
ebookmeta.com

Wraith King 3 1st Edition Jack Porter

https://ebookmeta.com/product/wraith-king-3-1st-edition-jack-porter/

ebookmeta.com

The Ultimate Scholarship Book 2023 15th Edition Gen &


Kelly Tanabe

https://ebookmeta.com/product/the-ultimate-scholarship-book-2023-15th-
edition-gen-kelly-tanabe/

ebookmeta.com

Myth Chaos and Certainty Notes on Cosmos Life and


Knowledge 1st Edition Rosolino Buccheri

https://ebookmeta.com/product/myth-chaos-and-certainty-notes-on-
cosmos-life-and-knowledge-1st-edition-rosolino-buccheri/

ebookmeta.com

The Distraction (Springbrook Hills #1) 1st Edition Morgan


Elizabeth

https://ebookmeta.com/product/the-distraction-springbrook-hills-1-1st-
edition-morgan-elizabeth/

ebookmeta.com
The Law of the Executive Branch Presidential Power Oxford
Commentaries on American Law 1st Edition Dr. Louis Fisher

https://ebookmeta.com/product/the-law-of-the-executive-branch-
presidential-power-oxford-commentaries-on-american-law-1st-edition-dr-
louis-fisher/
ebookmeta.com
CONTENTS IN DETAIL

TITLE PAGE

COPYRIGHT

ABOUT THE AUTHORS

FOREWORD

PREFACE

ACKNOWLEDGMENTS

INTRODUCTION
Who Rust Is For
Teams of Developers
Students
Companies
Open Source Developers
People Who Value Speed and Stability
Who This Book Is For
How to Use This Book
Resources and How to Contribute to This Book

CHAPTER 1: GETTING STARTED


Installation
Installing rustup on Linux or macOS
Installing rustup on Windows
Troubleshooting
Updating and Uninstalling
Local Documentation
Hello, World!
Creating a Project Directory
Writing and Running a Rust Program
Anatomy of a Rust Program
Compiling and Running Are Separate Steps
Hello, Cargo!
Creating a Project with Cargo
Building and Running a Cargo Project
Building for Release
Cargo as Convention
Summary

CHAPTER 2: PROGRAMMING A GUESSING GAME


Setting Up a New Project
Processing a Guess
Storing Values with Variables
Receiving User Input
Handling Potential Failure with Result
Printing Values with println! Placeholders
Testing the First Part
Generating a Secret Number
Using a Crate to Get More Functionality
Generating a Random Number
Comparing the Guess to the Secret Number
Allowing Multiple Guesses with Looping
Quitting After a Correct Guess
Handling Invalid Input
Summary

CHAPTER 3: COMMON PROGRAMMING CONCEPTS


Variables and Mutability
Constants
Shadowing
Data Types
Scalar Types
Compound Types
Functions
Parameters
Statements and Expressions
Functions with Return Values
Comments
Control Flow
if Expressions
Repetition with Loops
Summary

CHAPTER 4: UNDERSTANDING OWNERSHIP


What Is Ownership?
Ownership Rules
Variable Scope
The String Type
Memory and Allocation
Ownership and Functions
Return Values and Scope
References and Borrowing
Mutable References
Dangling References
The Rules of References
The Slice Type
String Slices
Other Slices
Summary

CHAPTER 5: USING STRUCTS TO STRUCTURE RELATED DAT


A
Defining and Instantiating Structs
Using the Field Init Shorthand
Creating Instances from Other Instances with Struct Update Syntax
Using Tuple Structs Without Named Fields to Create Different Types
Unit-Like Structs Without Any Fields
An Example Program Using Structs
Refactoring with Tuples
Refactoring with Structs: Adding More Meaning
Adding Useful Functionality with Derived Traits
Method Syntax
Defining Methods
Methods with More Parameters
Associated Functions
Multiple impl Blocks
Summary

CHAPTER 6: ENUMS AND PATTERN MATCHING


Defining an Enum
Enum Values
The Option Enum and Its Advantages Over Null Values
The match Control Flow Construct
Patterns That Bind to Values
Matching with Option<T>
Matches Are Exhaustive
Catch-All Patterns and the _ Placeholder
Concise Control Flow with if let
Summary

CHAPTER 7: MANAGING GROWING PROJECTS WITH PACKA


GES, CRATES, AND MODULES
Packages and Crates
Defining Modules to Control Scope and Privacy
Paths for Referring to an Item in the Module Tree
Exposing Paths with the pub Keyword
Starting Relative Paths with super
Making Structs and Enums Public
Bringing Paths into Scope with the use Keyword
Creating Idiomatic use Paths
Providing New Names with the as Keyword
Re-exporting Names with pub use
Using External Packages
Using Nested Paths to Clean Up Large use Lists
The Glob Operator
Separating Modules into Different Files
Summary

CHAPTER 8: COMMON COLLECTIONS


Storing Lists of Values with Vectors
Creating a New Vector
Updating a Vector
Reading Elements of Vectors
Iterating Over the Values in a Vector
Using an Enum to Store Multiple Types
Dropping a Vector Drops Its Elements
Storing UTF-8 Encoded Text with Strings
What Is a String?
Creating a New String
Updating a String
Indexing into Strings
Slicing Strings
Methods for Iterating Over Strings
Strings Are Not So Simple
Storing Keys with Associated Values in Hash Maps
Creating a New Hash Map
Accessing Values in a Hash Map
Hash Maps and Ownership
Updating a Hash Map
Hashing Functions
Summary
CHAPTER 9: ERROR HANDLING
Unrecoverable Errors with panic!
Recoverable Errors with Result
Matching on Different Errors
Propagating Errors
To panic! or Not to panic!
Examples, Prototype Code, and Tests
Cases in Which You Have More Information Than the Compiler
Guidelines for Error Handling
Creating Custom Types for Validation
Summary

CHAPTER 10: GENERIC TYPES, TRAITS, AND LIFETIMES


Removing Duplication by Extracting a Function
Generic Data Types
In Function Definitions
In Struct Definitions
In Enum Definitions
In Method Definitions
Performance of Code Using Generics
Traits: Defining Shared Behavior
Defining a Trait
Implementing a Trait on a Type
Default Implementations
Traits as Parameters
Returning Types That Implement Traits
Using Trait Bounds to Conditionally Implement Methods
Validating References with Lifetimes
Preventing Dangling References with Lifetimes
The Borrow Checker
Generic Lifetimes in Functions
Lifetime Annotation Syntax
Lifetime Annotations in Function Signatures
Thinking in Terms of Lifetimes
Lifetime Annotations in Struct Definitions
Lifetime Elision
Lifetime Annotations in Method Definitions
The Static Lifetime
Generic Type Parameters, Trait Bounds, and Lifetimes Together
Summary

CHAPTER 11: WRITING AUTOMATED TESTS


How to Write Tests
The Anatomy of a Test Function
Checking Results with the assert! Macro
Testing Equality with the assert_eq! and assert_ne! Macros
Adding Custom Failure Messages
Checking for Panics with should_panic
Using Result<T, E> in Tests
Controlling How Tests Are Run
Running Tests in Parallel or Consecutively
Showing Function Output
Running a Subset of Tests by Name
Ignoring Some Tests Unless Specifically Requested
Test Organization
Unit Tests
Integration Tests
Summary

CHAPTER 12: AN I/O PROJECT: BUILDING A COMMAND LIN


E PROGRAM
Accepting Command Line Arguments
Reading the Argument Values
Saving the Argument Values in Variables
Reading a File
Refactoring to Improve Modularity and Error Handling
Separation of Concerns for Binary Projects
Fixing the Error Handling
Extracting Logic from main
Splitting Code into a Library Crate
Developing the Library’s Functionality with Test-Driven Development
Writing a Failing Test
Writing Code to Pass the Test
Working with Environment Variables
Writing a Failing Test for the Case-Insensitive Search Function
Implementing the search_case_insensitive Function
Writing Error Messages to Standard Error Instead of Standard Outpu
t
Checking Where Errors Are Written
Printing Errors to Standard Error
Summary

CHAPTER 13: FUNCTIONAL LANGUAGE FEATURES: ITERATO


RS AND CLOSURES
Closures: Anonymous Functions That Capture Their Environment
Capturing the Environment with Closures
Closure Type Inference and Annotation
Capturing References or Moving Ownership
Moving Captured Values Out of Closures and the Fn Traits
Processing a Series of Items with Iterators
The Iterator Trait and the next Method
Methods That Consume the Iterator
Methods That Produce Other Iterators
Using Closures That Capture Their Environment
Improving Our I/O Project
Removing a clone Using an Iterator
Making Code Clearer with Iterator Adapters
Choosing Between Loops and Iterators
Comparing Performance: Loops vs. Iterators
Summary

CHAPTER 14: MORE ABOUT CARGO AND CRATES.IO


Customizing Builds with Release Profiles
Publishing a Crate to Crates.io
Making Useful Documentation Comments
Exporting a Convenient Public API with pub use
Setting Up a Crates.io Account
Adding Metadata to a New Crate
Publishing to Crates.io
Publishing a New Version of an Existing Crate
Deprecating Versions from Crates.io with cargo yank
Cargo Workspaces
Creating a Workspace
Creating the Second Package in the Workspace
Installing Binaries with cargo install
Extending Cargo with Custom Commands
Summary

CHAPTER 15: SMART POINTERS


Using Box<T> to Point to Data on the Heap
Using Box<T> to Store Data on the Heap
Enabling Recursive Types with Boxes
Treating Smart Pointers Like Regular References with Deref
Following the Pointer to the Value
Using Box<T> Like a Reference
Defining Our Own Smart Pointer
Implementing the Deref Trait
Implicit Deref Coercions with Functions and Methods
How Deref Coercion Interacts with Mutability
Running Code on Cleanup with the Drop Trait
Rc<T>, the Reference Counted Smart Pointer
Using Rc<T> to Share Data
Cloning an Rc<T> Increases the Reference Count
RefCell<T> and the Interior Mutability Pattern
Enforcing Borrowing Rules at Runtime with RefCell<T>
Interior Mutability: A Mutable Borrow to an Immutable Value
Allowing Multiple Owners of Mutable Data with Rc<T> and RefCell<
T>
Reference Cycles Can Leak Memory
Creating a Reference Cycle
Preventing Reference Cycles Using Weak<T>
Summary

CHAPTER 16: FEARLESS CONCURRENCY


Using Threads to Run Code Simultaneously
Creating a New Thread with spawn
Waiting for All Threads to Finish Using join Handles
Using move Closures with Threads
Using Message Passing to Transfer Data Between Threads
Channels and Ownership Transference
Sending Multiple Values and Seeing the Receiver Waiting
Creating Multiple Producers by Cloning the Transmitter
Shared-State Concurrency
Using Mutexes to Allow Access to Data from One Thread at a Time
Similarities Between RefCell<T>/Rc<T> and Mutex<T>/Arc<T>
Extensible Concurrency with the Send and Sync Traits
Allowing Transference of Ownership Between Threads with Send
Allowing Access from Multiple Threads with Sync
Implementing Send and Sync Manually Is Unsafe
Summary

CHAPTER 17: OBJECT-ORIENTED PROGRAMMING FEATURES


Characteristics of Object-Oriented Languages
Objects Contain Data and Behavior
Encapsulation That Hides Implementation Details
Inheritance as a Type System and as Code Sharing
Using Trait Objects That Allow for Values of Different Types
Defining a Trait for Common Behavior
Implementing the Trait
Trait Objects Perform Dynamic Dispatch
Implementing an Object-Oriented Design Pattern
Defining Post and Creating a New Instance in the Draft State
Storing the Text of the Post Content
Ensuring the Content of a Draft Post Is Empty
Requesting a Review Changes the Post’s State
Adding approve to Change the Behavior of content
Trade-offs of the State Pattern
Summary

CHAPTER 18: PATTERNS AND MATCHING


All the Places Patterns Can Be Used
match Arms
Conditional if let Expressions
while let Conditional Loops
for Loops
let Statements
Function Parameters
Refutability: Whether a Pattern Might Fail to Match
Pattern Syntax
Matching Literals
Matching Named Variables
Multiple Patterns
Matching Ranges of Values with ..=
Destructuring to Break Apart Values
Ignoring Values in a Pattern
Extra Conditionals with Match Guards
@ Bindings
Summary

CHAPTER 19: ADVANCED FEATURES


Unsafe Rust
Unsafe Superpowers
Dereferencing a Raw Pointer
Calling an Unsafe Function or Method
Accessing or Modifying a Mutable Static Variable
Implementing an Unsafe Trait
Accessing Fields of a Union
When to Use Unsafe Code
Advanced Traits
Associated Types
Default Generic Type Parameters and Operator Overloading
Disambiguating Between Methods with the Same Name
Using Supertraits
Using the Newtype Pattern to Implement External Traits
Advanced Types
Using the Newtype Pattern for Type Safety and Abstraction
Creating Type Synonyms with Type Aliases
The Never Type That Never Returns
Dynamically Sized Types and the Sized Trait
Advanced Functions and Closures
Function Pointers
Returning Closures
Macros
The Difference Between Macros and Functions
Other documents randomly have
different content
For my second instance. The next year, 1857, was Mutiny Year,
and closed upon an England raging mad over the story of Cawnpore.
Dickens and Wilkie Collins, on a tour together in the north of
England, had contrived a Christmas Number for Household Words,
announced and entitled The Perils of Certain English Prisoners, and
their Treasures in Women, Children, Silver and Jewels. The public
expected a red-hot account of the Nana Sahib, the treacherous
embarkation, the awful voyage down the Ganges. It was all there, to
the man’s hand, with illimitable applause for his mere inviting. But it
might inflame—and, inflaming, hurt—the nation’s temper, and
therefore he would have none of it: he, Dickens, the great literary
Commoner; lord over millions of English and to them, and to right
influence on them, bounden. Therefore the public got something
more profitable than it craved for: it got a romantic story empty of
racial or propagandist hatred; a simple narrative of peril and
adventure on a river in South America.

VI
But now let us see what a light this conscious popularity throws
upon two important events in Dickens’ career: his visit to the United
States in 1842, and his invention, the next year, of the “Christmas
Book.”
Dickens went over to America as a great personage: securely,
but neither immodestly nor overweeningly conscious of it. He went
over also as a great and genuine early-Victorian radical; something
better than any politician; an unbribed and unbribable writer,
immensely potent, with a pen already dedicated to war against social
abuses. He landed at Boston, fully expecting to see Liberty in
realisation under the star-spangled banner. He found Colonel Diver
and Mr. Jefferson Brick, Mr. La Fayette Kettle and the Honourable
Elijah Pogram. He found, of course, a fervent and generous
hospitality that sprang, in Forster’s words, “from feelings honourable
both to giver and receiver,” and was bestowed sincerely, if with a
touch of bravado and challenge—“We of the New World want to
show you, by extending the kind of homage that the Old World
reserves for kings and conquerors, to a young man with nothing to
distinguish him but his heart and his genius, what it is we think in
these parts worthier of honour than birth or wealth, a title or a
sword.” These are Forster’s words again, and they do well enough.
The hospitality included no doubt a good deal of the ridiculous: food
for innocent caricature of the kind provided in the great Pogram
levee where the two Literary Ladies are presented to the Honourable
Elijah by the Mother of the Modern Gracchi.

“To be presented to a Pogram,” said Miss Codger, “by a


Hominy, indeed a thrilling moment is it in its impressiveness on
what we call our feelings. But why we call them so, and why
impressed they are, or if impressed they are at all, or if at all we
are, or if there really is, oh gasping one! a Pogram or a Hominy,
or any active principle to which we give those titles is a topic,
Spirit searching, light-abandoned, much too vast to enter on, at
this unlooked-for Crisis.” “Mind and Matter,” said the lady in the
wig, “glide swift into the vortex of immensity. Howls the sublime,
and softly sleeps the calm Ideal, in the whispering chambers of
Imagination. To hear it, sweet it is. But then outlaughs the stern
philosopher, and saith to the Grotesque, ‘What ho! arrest for me
that agency! Go bring it here! And so the vision fadeth.’”

I will not take oath that I have not heard faint echoes of that sort of
talk at literary gatherings within a mile or so of this very spot. But if it
be not to some extent endemic in America even to-day, then all I can
say is that certain American authors (Mrs. Edith Wharton for one)
have misrepresented it far more cruelly than ever did Charles
Dickens, or certainly than I, with no knowledge at all, have any wish
to do.
But what brought Dickens up with a round turn was his discovery
(as he believed) that in this land of freedom no man was free to
speak his thought.
“I believe,” he wrote to Forster on Feb. 24th, “there is no
country on the face of the earth where there is less freedom of
opinion on any subject in reference to which there is a broad
difference of opinion than in this.... There!—I write the words with
reluctance, disappointment and sorrow: but I believe it from the
bottom of my soul.”

He did believe it, and it shocked him inexpressibly. “Very well,” it may
be answered; “but there were obligations. A man should not publicly
criticise a country in which he is an honoured guest.” Yes, but he had
gone out to the States with intent to discuss the question of
copyright, or rather of literary piracy, in which American law and
practice were so flagrantly immoral that he had never a doubt of
getting both rectified by a little heart-to-heart talk (as we call it now)
with some of their public men and lawgivers. Dickens was always a
good man of business. As the most widely-read of British authors,
and therefore the chief of sufferers, he could speak authoritatively on
behalf of his poorer brethren. He went, and received on a grand
scale that shock which on a far modester scale many of us have
experienced in our time, with the sort of embarrassment one feels
(let us say) in sitting down to Bridge with a very delightful person
whose code in the matter of revoking is rather notoriously “off
colour.” Let me illustrate this by the remark of a just man at
Washington in the debate preceding the latest copyright enactment.
A member of Congress had pleaded for the children of the
backwoods—these potential Abraham Lincolns devouring education
by the light of pine-knot fires—how desirable that these little Sons of
Liberty should be able to purchase their books (as he put it) “free of
authorial expenses!” “Hear, hear!” retorted my just man. “And the
negroes of the South too—so fond of chicken free of farmer-ial
expenses!”—A great saying!
And yet Dickens was wrong: in my opinion wrong as an English
Gentleman, being America’s Guest. On the balance I hold that he
should have thought what he thought and, thinking it, have
shortened his visit and come silently away.
Well, Dickens discussed the matter with Washington Irving,
Prescott, Hoffman, Bryant, Dana and others, and found that while
every writer in America was agreed upon the atrocious state of the
law, not a man of them dared to speak out. The suggestion that an
American could be found with temerity enough to hint that his
country was possibly wrong struck the boldest dumb. “Then,” said
Dickens, “I shall speak out”: and he did. “I wish you could have
seen,” he writes home, “the faces that I saw, down both sides of the
table at Hartford, when I began to talk about Scott.” [Remember,
please, this is my interjection, Gentlemen, that, on a small portion of
his dues, on a 10 per cent. (say) of his plundered sales, the great Sir
Walter Scott would have died in calm of mind and just prosperity.] “I
wish you could have heard how I gave it out. My blood so boiled as I
thought of the monstrous injustice that I felt as if I were twelve feet
high when I thrust it down their throats.”
The violence of the reaction upon Dickens you can of course
study in American Notes and Martin Chuzzlewit. But the real import
of these two books and the violence of resentment they raised, we
shall not understand without realising that Dickens went over, was
feasted: was disappointed, then outraged, and spoke his mind, from
first to last as a representative of the democracy of this country,
always conscious of a great, if undefined, responsibility and, under
disappointment, resolute to be brave, at whatever cost of favour.

VII
The same grand consciousness seems to me to have been the
true inspiration of his “Christmas Books.” For a private confession, I
dislike them: I find them—A Christmas Carol, The Chimes, The
Cricket on the Hearth, The Battle of Life, The Haunted Man—grossly
sentimental and as grossly overcharged with violent conversions to
the “Christmas Spirit.” For a further confession I greatly prefer
several of his later Christmas Stories in Household Words and All
the Year Round—The Wreck of the “Golden Mary” for instance, or
Dr. Marigold’s Prescriptions or The Holly-Tree Inn—to this classic
five which are still separated in the collected editions under the title
of “Christmas Books.” He himself confessed, in a general preface of
less than a dozen lines, his inability to work out character in the limits
he assigned himself—a hundred pages or so. “My chief purpose,” he
says of A Christmas Carol, “was, in a whimsical kind of masque
which the good humour of the season justified, to awaken some
loving and forbearing thoughts, never out of season in a Christian
land.” But he took it as a mission, and quite seriously. Christmas to
England had always meant, and should mean, a festival of
neighbourly goodwill and robust hospitality. Listen to the old Carols:

Now thrice welcome, Christmas,


Which brings us good cheer,
Minced pies and plum porridge,
Good ale and strong beer;
With pig, goose and capon,
The best that may be,
So well doth the weather
And our stomachs agree.

Or

Now that the time is come wherein


Our Saviour Christ was born,
The larders full of beef and pork,
The garners fill’d with corn....

Or

Bring us in good ale, and bring us in good ale;


For our blessed Lady’s sake, bring us in good ale.
These out of a score or more verses I might quote from Poor Robin’s
Almanack and the like. But take Campion’s more aristocratic Muse:

Now winter nights enlarge


The number of their hours,
And clouds their storms discharge
Upon the airy towers.
Let now the chimneys blaze
And cups o’erflow with wine;
Let well-attuned words amaze
With harmony divine.
Now yellow waxen lights
Shall wait on honey love,
While youthful revels, masques, and courtly sights
Sleep’s leaden spell remove.

Carry this again down to Frederick Tennyson’s The Holy Tide:

The days are sad, it is the Holy tide;


The Winter morn is short, the Night is long;
So let the lifeless Hours be glorified
With deathless thoughts and echo’d in sweet song:
And through the sunset of this purple cup
They will resume the roses of their prime,
And the old Dead will hear us and wake up,
Pass with dim smiles and make our hearts sublime.

“An Englishman’s house is his Castle,” said an immortal farmer


at a Fat Stock Dinner. “The storms may assail it and the winds
whistle round it, but the King himself cannot do so.” Dickens saw
always the Englishman’s house as his castle, fortified and
provisioned against the discharge of snow and sleet: always most
amply provisioned! Witness his picture of Christmas at Manor Farm,
Dingley Dell—Old Wardle with his friends, neighbours, poor
relations, and his farm-labourers too, all sitting down together to a
colossal supper “and a mighty bowl of wassail something smaller
than an ordinary washhouse copper, in which the hot apples were
hissing and bubbling with a rich look and jolly sound that were
perfectly irresistible.”
Old Wardle, in fact, is in the direct line of succession to
Chaucer’s Frankeleyne—

Withoute bake mete was never his hous,


Of fish and flesh, and that so plenteous,
It snewed in his hous of mete and drink.

Dickens, I repeat to you, was always, in the straight line of


Chaucer, Ben Jonson, Dryden, Fielding, a preacher of man’s dignity
in his full appetite; and quite consciously, as a national genius, he
preached the doctrine of Christmas to his nation.

VIII
But you will say perhaps “Granted his amazing popularity—
granted, too, his right to assume on it—was it really deserved?” To
this question I oppose for the moment my opinion that, were I asked
to choose out of the story of English Literature a short list of the most
fecund authors, I should start with Chaucer, Marlowe, Shakespeare,
Donne, Dryden, Pope, Samuel Johnson, Burke, Gibbon,
Wordsworth, Coleridge, Shelley, Keats, Carlyle, Dickens, Browning.
If compelled to reduce the list to three, choosing the three most
lavishly endowed by God with imagination for their fellows’ good, I
almost think that among all God’s plenty I should choose, as pre-
eminent stars, Shakespeare, Burke and Dickens. Milton, of course,
will stand apart always, a solitary star: and Chaucer for his amazing
invention, less even for what he did than for that he did it at all; Keats
for infinity of promise; and to exclude Scott seems almost an outrage
on human kindness. Yet if it come to the mere wonder-work of
genius—the creation of men and women, on a page of paper, who
are actually more real to us than our daily acquaintances, as
companionable in a crowd as even our best selected friends, as
individual as the most eccentric we know, yet as universal as
humanity itself, I do not see what English writer we can choose to
put second to Shakespeare save Charles Dickens. I am talking of
sheer creative power, as I am thinking of Tasso’s proud saying that,
next to God himself, no one but the poet deserves the name of
Creator. You feel of Dickens as of Shakespeare that anything may
happen: because it is not with them as with other authors: it is not
they who speak. Falstaff or Hamlet or Sam Weller or Mr. Micawber: it
is the god speaking:
Ἄνδρα μοι ἔννεπε, Μοῦσα.
They are as harps upon which the large wind plays: and as that is
illimitable there is no limit to their utterances. It was so with Charles
Dickens from the Sam Weller of his lost youth down to the last when,
in pain and under the shadow of death, he invented the Billickin.
In another lecture I propose to show you (if I can) that Dickens’
characters belong to a world of his own, rather than to this one. But if
he also created that world of his own, so much the grander creator
he!—As if he made men and women walk and talk in it, compelling
us to walk with them, and listen, and, above all, open our lungs and
laugh, suffer within the tremendous illusion, so much is he the more
potent magician! I also feel, in reading Shakespeare, or Dickens—I
would add Burke—as I feel with no fourth that I am dealing with a
scope of genius quite incalculable; that while it keeps me proud to
belong to their race and nation and to inherit their speech, it equally
keeps me diffident because, at any turn of the page may occur some
plenary surprise altogether beyond my power or scope of guessing.
With these three writers, as with no fourth, I have the sensation of a
certain faintness of enjoyment, of surrender, to be borne along as on
vast wings. Yet of Dickens, as of Shakespeare, the worst work can
be incredibly bad. Sorrier stuff could scarcely be written, could
scarcely conceivably have ever been written, than the whole part of
Speed in The Two Gentlemen of Verona unless it be the first chapter
of Martin Chuzzlewit. Yet in Martin Chuzzlewit you get Mrs. Gamp:
and I ask you, How much the poorer should we not all be, lacking
Mrs. Gamp?
I grant you that he has not yet passed—as he has not yet had
time to pass—the great test of a classical writer; which is that,
surviving the day’s popularity and its conditions, his work goes on
meaning more, under quite different conditions, to succeeding ages;
the great test which Shakespeare has passed more than once or
twice, remaining to-day, though quite differently, even more
significant than he was to his contemporaries. I grant—as in another
lecture I shall be at pains to show—that Dickens’ plots were usually
incredible, often monstrous. But he invented a world: he peopled it
with men and women for our joy: and my confidence in the diuturnity
of his fame rests even on more than this—on the experience that,
test this genius by whatever standard a critic may, he has by and by
to throw down his measure and admit that, while Dickens was
always a learner, out of his prodigality he could have at any moment
knocked the critic over by creating a new world with new and
delectable lasting characters to take it in charge.
DICKENS (II)

I
I TAKE up my parable for a few words more upon the point at which I
broke off last week—the essential greatness of Dickens. For
greatness is a quality in some few men: indefinable perhaps, but yet
to be recognised; a certain thing and, by those of us who would
traffic with life or literature, not to be overlooked or denied save at
our soul’s peril, no matter what standard of artistry or of refined
scholarship we may set up: a quality in itself, moreover, and not any
addition or multiplication or raising of talent by industry. For an
illustration of the peril: I was reading, the other day, a history of
French Literature by the late M. Ferdinand Brunetière, and, coming
to the time of Alexandre Dumas the elder, I found that the historian,
disapproving of Dumas, has just left him out! Now that, I contend
(saving M. Brunetière’s eminence), is to write oneself down a
pedant, outside the catholic mind. Dumas lived a scandalous life,
wrote much execrable French, and encouraged—even employed—
some of his fellows to write worse. But the author of The Three
Musketeers, Le Vicomte de Bragelonne, La Reine Margot—Dumas,
“the seven-and-seventy times to be forgiven,” is not to be treated so,
by your leave: or only so, I repeat, at the critic’s peril. Or let me take
an Englishman—John Dryden. I suspect I shall not misrepresent or
misreport the attitude of many in this room towards Dryden when I
say that we find a world of slovenly sorry stuff in his dramas, and in
his poems a deal of wit and rhetoric which our later taste—such as it
is, good or bad, true or false—refuses to pass for poetry at all. Now if
I merely wanted to prove to you that Dryden at his best could write
finely, exquisitely—that out of the strong could come forth sweetness
—I could content myself with asking you to listen to these verses:
No, no, poor suffering heart, no change endeavour,
Choose to sustain the smart, rather than leave her;
My ravish’d eyes behold such charms about her,
I can die with her, but not live without her
One tender sigh of her, to see me languish,
Will more than pay the price of my past anguish;
Beware, O cruel fair, how you smile on me,
’Twas a kind look of yours that has undone me.

Love has in store for me one happy minute,


And she will end my pain, who did begin it;
Then no day, void of bliss, of pleasure, leaving,
Ages shall slide away without perceiving:
Cupid shall guard the door, the more to please us,
And keep out Time and Death, when they would seize us:
Time and Death shall depart, and say in flying,
“Love has found out a way to live—by dying.”

There, obviously, is a virtuoso who commands his keyboard. But if I


were talking about Dryden to you for your soul’s good, I should
rather show you the man with all his imperfections on his head, then
turn and challenge you to deny his greatness. Why, you can scarcely
read a page, even of his prose—say, for choice, the opening of his
Essay of Dramatic Poesy—without recognising the tall fellow of his
hands, the giant among his peers,

ψυχἠ ...
... μακρὰ βιβᾶσα κατ’ ἀσφοδελὸν λειμῶνα,

“pacing with long stride the asphodel meadow” where, let us say,
Samuel Johnson walks, and Handel, and Hugo, nor are they
abashed to salute the very greatest—Dante, Michelangelo,
Shakespeare.
I repeat, Gentlemen, that at all risk of appearing exorbitant I
should preach this to you for your souls’ good. For I do most
earnestly want you, before all else, to recognise this quality of
greatness and respond to it. In so far as, in your fleeting generation,
you give me your confidence and honour me (shall I say?) with a
personal hope for A or B or C, I would warn you of what I have
experimentally proved to be true of my contemporaries—that the
man is most fatally destined to be great himself who learns early to
enlarge his heart to the great masters; that those have steadily sunk
who cavilled at Caesar with Cassius, or over a cigarette chatted
admiringly of the rent which envious Casca made: that anyone with
an ear learns very surely to distinguish the murmur of the true bee
from the morose hum of the drone who is bringing no honey, nor
ever will, to the hive. In my own time of apprenticeship—say in the
’nineties—we were all occupied—after the French novelists—with
style: in seeking the right word, le mot juste, and with “art for art’s
sake,” etc. And we were serious enough, mind you. We cut
ourselves with knives. To-day, if I may diagnose your more youthful
sickness, you are occupied rather with lyricism, curious and
recondite sensations, appositions of unrelated facts with magenta-
coloured adjectives. The craze has spread to the shop-fronts, to
curtains, bedspreads, as the craze for Byronic collars spread in its
day: and “Hell is empty!” cried Ferdinand, plunging overboard: but
you can still find psycho-analysis rampant, with any amount of Birth
Control, among the geese on Golder’s Green. But if from this desk I
have preached incessantly on a text, it is this—that all spirit being
mutually attractive, as all matter is mutually attractive, is an ultimate
fact: and that therefore we shall grow the greater and better critics as
we surrender ourselves to the great writers and without detraction, at
least until we have, in modesty of mind, proved them: since, to apply
a word of Emerson’s:

Heartily know—
When half-gods go,
The gods arrive.
II
So I broke off, or almost, upon a saying of Tasso’s—you may find
it repeated in Ben Jonson’s Timber, or Discoveries—that in this world
none deserves the name of Creator save God himself and the Poet
—by “Poet” meaning, of course, the great imaginative artist whether
working in restricted verse or in “that other harmony of prose.”
And you may be thinking—I don’t doubt, a number will be
thinking—that in a discourse on Dickens, I am putting the claim
altogether too high. I can feel your minds working, I think—working
to some such tune as this “Dickens and Virgil, now—Dickens and
Dante—Oh, heaven alive!”
You cannot say that I have shirked it—can you?
Well now, fair and softly! If I had said “Dickens and
Shakespeare,” it would have given you no such shock: and if I had
said “Shakespeare and Dante,” or “Dickens and Molière,” it would
have given you no shock at all. I am insisting, you understand, that
the first test of greatness in an imaginative writer is his power to
create: and I propose to begin with that which, if there should by any
chance happen to be a fool in this apparently representative
gathering, he will infallibly despise for the easiest thing in the world,
the creation of a fool. I beg to reassure him and, so far as I can,
restore his self-respect. It is about the hardest thing in the world, to
create a fool and laugh at him. It is a human, nay, even a Godlike
function (so and not by others shared) to laugh. Listen, before we go
further, to these stanzas on divine laughter:

Nay, ’tis a Godlike function; laugh thy fill!


Mirth comes to thee unsought:
Mirth sweeps before it like a flood the mill
Of languaged logic: thought
Hath not its source so high;
The will
Must let it by:
For, though the heavens are still,
God sits upon His hill
And sees the shadows fly:
And if He laughs at fools, why should He not?
“Yet hath the fool a laugh”—Yea, of a sort;
God careth for the fools;
The chemic tools
Of laughter He hath given them, and some toys
Of sense, as ’twere a small retort
Wherein they may collect the joys
Of natural giggling, as becomes their state:
The fool is not inhuman, making sport
For such as would not gladly be without
That old familiar noise:
Since, though he laugh not, he can cachinnate—
This also is of God, we may not doubt.

Shakespeare, as we know, delighted in a fool, and revelled in


creating one. (I need hardly say that I am not talking of the
professionals, such as Touchstone or the Fool in Lear, who are
astute critics rather, ridiculing the folly of their betters by reflexion by
some odd facet of common sense, administering hellebore to minds
diseased and so in their function often reminding us of the Chorus in
Greek tragedy.) I mean, of course, the fool in his quiddity, such as
Dogberry, or Mr. Justice Shallow, or Cousin Abraham Slender.
Hearken to Dogberry:

Dog. Come hither, neighbour Seacole. God hath blessed


you with a good name: to be a well-favoured man is the gift of
fortune; but to write and read comes by nature.
Sec. Watch. Both which, master Constable—
Dog. You have: I knew it would be your answer. Well, for
your favour, sir, why, give God thanks, and make no boast of it;
and for your writing and reading, let that appear when there is no
need of such vanity.
Why, it might be an extract from the Geddes Report—or so much of
it as deals with Education!
And now to Slender, bidden in by sweet Anne Page to her
father’s dinner-table:

Anne. Will it please your worship to come in, sir?


Slender. No—I thank you, forsooth—heartily. I am very well.
Anne. The dinner attends you, sir.
Slender. I am not a-hungry, I thank you, forsooth....
Anne. I may not go in without your worship; they will not sit
till you come.
Slender. I’faith, I’ll eat nothing: I thank you as much as
though I did.
Anne. I pray you, sir, walk in.
Slender. I had rather walk here—I thank you. I bruised my
shin th’ other day with playing at sword and dagger with a
master of fence—three veneys for a dish of stewed prunes—
and, I with my ward defending my head, he shot my shin, and by
my troth, I cannot abide the smell of hot meat since.... Why do
your dogs bark so? Be there bears in town?
Anne. I think there are, sir. I heard them talked of.
Slender. I love the sport well, but I shall as soon quarrel at it
as any man in England.... You are afraid, if you see a bear loose,
are you not?
Anne. Ay, indeed, sir.
Slender. That’s meat and drink to me, now: I have seen
Sackerson loose—twenty times, and have taken him by the
chain.... But women, indeed, cannot abide ’em—they are very ill-
favoured rough things.
“Othello,” as Hartley Coleridge noted, “could not brag more
amorously”: and, as I wrote the other day in an introduction to The
Merry Wives, when Anne finally persuades him to walk before her
into the house, my fellow-editor and I had written (but afterwards in
cowardice erased) the stage-direction, He goes in: she follows with
her apron spread, as if driving a goose. Yes, truly, Slender is a goose
to say grace over and to be carved “as a dish fit for the gods.” “A
very potent piece of imbecility,” writes Hazlitt, and adds,
“Shakespeare is the only writer who was as great in describing
weakness as strength.”
Well, Jane Austen and Charles Dickens came after, to confirm
Hazlitt’s observation. No one seeks in Jane Austen for examples of
strength: and you will find none in Dickens to compare with Othello
or Cleopatra or (say) with Mr. Hardy’s Mayor of Casterbridge. But,
like Charles Lamb, Jane Austen and Dickens both “loved a fool”:
Jane Austen delicately, Dickens riotously: witness the one’s Miss
Bates, the other’s Mr. Toots. But observe, pray: the fools they delight
in are always—like Slender, like Miss Bates, like Mr. Toots—simple
fools, sincere fools, good at heart, good to live with, and in their way,
the salt of the earth. Miss Bates herself bears unconscious witness
to this in one of her wisest foolishest remarks—“It is such a
happiness when good people get together—and they always do.”
(Consoling thought for you and me at this very moment.) With the
fool who is also a humbug, a self-deceiver, Dickens could find no
patience in his heart; and this impatience of his you may test again
and again, always to find it—if I may say so with reverence—as
elementary as our Lord’s. I am not speaking of conscious, malignant
hypocrites—your Stiggins’s, Pecksniffs, Chadbands—on whom
Dickens waged war, his life through; but of the self-deceiving fool
whom we will agree with him in calling an “ass”—Uncle
Pumblechook, for instance, in Great Expectations, Mr. Sapsea in
Edwin Drood; on whom, or on whose kind, as he grew older, he
seems (most of all in his last book, whenever handling Mr. Sapsea)
to lose his artistic self-control, to savage them. But of kind fools,
lovable fools, good fools, God’s fools, Dickens’ heaven will open any
moment at call and rain you down half-a-dozen, all human, each
distinct. You may count half-a-dozen in his most undeservedly
misprised book, Little Dorrit, omitting Mr. F.’s Aunt: who is an
eccentric, rather, though an unforgettable one and has left her
unforgettable mark on the world in less than 200 words. She stands
apart: for the others, apart from foolishness, share but one gift in
common, a consanguinity (as it were) in flow of language or
determination of words to the mouth. Shall we select the vulgar,
breathless, good-natured widow, Flora Finching, ever recalling the
past (without so much pause as a comma’s) to her disillusioned first
lover?—

In times for ever fled Arthur pray excuse me Doyce and


Clennam (the name of his firm) infinitely more correct and
though unquestionably distant still ’tis distance lends
enchantment to the view, at least I don’t mean that and if I did I
suppose it would depend considerably on the nature of the view,
but I’m running on again and you put it all out of my head.
She glanced at him tenderly and resumed:
In times for ever fled I was going to say it would have
sounded strange indeed for Arthur Clennam—Doyce and
Clennam naturally quite different—to make apologies for coming
here at any time, but that is past and what is past can never be
recalled except in his own case as poor Mr. F. said when in
spirits Cucumber and therefore never ate it.... Papa is sitting
prosingly, breaking his new laid egg over the City article, exactly
like the Woodpecker Tapping, and need never know that you are
here....
The withered chaplet is then perished the column is
crumbled and the pyramid is standing upside down upon its
what’s-his-name call it not giddiness call it not weakness call it
not folly I must now retire into privacy and looking upon the
ashes of departed joys no more but taking the further liberty of
paying for the pastry which has formed the humble pretext for
our interview, will for ever say Adieu!
Mr. F’s Aunt who had eaten her pie with great solemnity ...
and who had been elaborating some grievous scheme of injury
in her mind, took the present opportunity of addressing the
following sibyllic apostrophe to the relict of her late nephew:
“Bring him for’ard, and I’ll chuck him out o’ winder!”

III
Mr. Chesterton, selecting another fool from the gallery—Young
Mr. Guppy, of Bleak House—observes very wisely, that we may
disapprove of Mr. Guppy, but we recognise him as a creation flung
down like a miracle out of an upper sphere: we can pull him to
pieces, but we could not have put him together. And this (says he) is
the pessimists’ disadvantage in criticising any creation. Even in their
attacks on the Universe they are always under this depressing
disadvantage.
“A man looking at a hippopotamus may sometimes be tempted
to regard the hippopotamus as an enormous mistake: but he is also
bound to confess that a fortunate inferiority prevents him personally
from making such a mistake.”
Well, that is, of course, our difficulty in criticising all creative
genius. We tell ourselves how we could have suggested to
Shakespeare—or to Dickens—his doing this or that better than he
did; but the mischief is, we could not have done it at all. And in this
matter of Mr. Guppy, Mr. Chesterton continues: “Not one of us could
have invented Mr. Guppy. But even if we could have stolen Mr.
Guppy from Dickens, we have still to confront the fact that Dickens
would have been able to invent another quite inconceivable
character to take his place.”

IV
Here we get to it. I have instanced his fools only, and but a select
two or three of these for a test: but you may take, if you will, shrewd
men, miserly men, ruffians, doctors, proctors, prisoners,
schoolmasters, coachmen, licensed victuallers, teetotallers, thieves,
monthly nurses—whatever the choice be, Dickens will shake them
out of his sleeve to populate a world for us. For, like Balzac, he has a
world of his own and can at call dispense to us of its abundance.
What sort of a world is it out of which Dickens so enriches ours?
Well, to begin with, it is a crowded world, a world that in his
imagination positively teems with folk going, coming, hurrying: of
innumerable streets where you may knock in (and welcome) at any
chance door to find the house in accumulated misery, poverty, woe,
or else in a disorder of sausages and squalling children, with a
henpecked husband at one end of the table, a bowl of punch in the
middle, and at the other end a mortuary woman whose business in
life is to make a burden of life to all who live near her and would
have her cheerful. (There was never such a man as Dickens for
depicting the blight induced by one ill-tempered person—usually a
woman—upon a convivial gathering.) The henpecked husband
dispensing the punch is, likely as not, a city clerk contriving a double
debt to pay, a slave during office hours, bound to a usurious master:
a sort of fairy—a Puck, a Mr. Wemmick, as soon as he sheds his
office-coat and makes for somewhere in the uncertain gaslight of the
suburbs, “following darkness like a dream.”
Yes, this world is of the streets; in which Dickens was bred and
from which he drew the miseries and consolations of his boyhood. A
world “full of folk,” but not, like Piers Plowman’s, a “field full of folk.”
His understanding of England is in many ways as deep as
Shakespeare’s; but it is all, or almost all, of the urban England which
in his day had already begun to kill the rural. I ask you to consider
any average drawing of Phiz’s; the number of figures crowded into a
little room, the many absurd things all happening at once, and you
will understand why Phiz was Dickens’ favourite illustrator. A
crowded world: an urban world, largely a middle-class and lower-
class London world—what else could we expect as outcome of a
boyhood spent in poverty and in London? Of London his knowledge
is indeed, like Sam Weller’s, “extensive and peculiar”: with a
background or distance of the lower Thames, black wharves peopled
by waterside loafers or sinister fishers in tides they watch for horrible
traffic; rotting piles such as caught and held the corpse of Quilp.
Some sentiment, indeed, up Twickenham-way: a handful of flowers,
taken from the breast and dropped at the river’s brink, to be floated
down, pale and unreal, in the moonlight; “and thus do greater things
that once were in our breasts and near our hearts, flow from us to
the eternal seas.” But before they reach the eternal seas they must
pass Westminster Bridge whence an inspired dalesman saw the City
wearing the beauty of dawn as a garment.
Ships, towers, domes, theatres and temples ... and Waterloo
Bridge, Hood’s dark arch of tragedy; and London Bridge, hymned of
old by Dunbar. Dickens’ bridge is the old Iron one by Hungerford,
and under it the Thames runs down to ghastly flats, convict-haunted,
below Woolwich.
Shakespeare knew his London, his Eastcheap, its taverns. But
when you think of Shakespeare you think (I will challenge you) rather
of rural England, of Avon, of Arden, of native wood-notes wild. I hold
it doubtful that Falstaff on his death-bed babbled o’ green fields: but I
will take oath that when he got down to Gloucestershire he smelt the
air like a colt or a boy out of school. And Justice Shallow is there—
always there!

Silence. This Sir John, cousin, that comes hither anon about
soldiers?
Shallow. The same Sir John, the very same. I saw him break
Skogan’s head at the court-gate, when a’ was a crack not thus
high: and the very same day did I fight with one Sampson
Stockfish, a fruiterer, behind Gray’s Inn. Jesu, Jesu, the mad
days I have spent! and to see how many of my old acquaintance
are dead!
Silence. We shall all follow, cousin.
Shallow. Certain, ’tis certain; very sure, very sure: death, as
the Psalmist saith, is certain to all; all shall die. How a good yoke
of bullocks at Stamford fair?

You might also like