100% found this document useful (8 votes)
2K views

Immediate Download Practical Rust Web Projects: Building Cloud and Web-Based Applications Shing Lyu Ebooks 2024

Practical

Uploaded by

dikercomi45
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 (8 votes)
2K views

Immediate Download Practical Rust Web Projects: Building Cloud and Web-Based Applications Shing Lyu Ebooks 2024

Practical

Uploaded by

dikercomi45
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/ 62

Download the full version of the textbook now at textbookfull.

com

Practical Rust Web Projects: Building Cloud


and Web-Based Applications Shing Lyu

https://textbookfull.com/product/practical-rust-
web-projects-building-cloud-and-web-based-
applications-shing-lyu/

Explore and download more textbook at https://textbookfull.com


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

Building web and mobile ArcGIS Server applications with


JavaScript Lewin

https://textbookfull.com/product/building-web-and-mobile-arcgis-
server-applications-with-javascript-lewin/

textbookfull.com

Practical Node.js: Building Real-World Scalable Web Apps


Azat Mardan

https://textbookfull.com/product/practical-node-js-building-real-
world-scalable-web-apps-azat-mardan/

textbookfull.com

Programming C 8 0 Build Cloud Web and Desktop Applications


Ian Griffiths

https://textbookfull.com/product/programming-c-8-0-build-cloud-web-
and-desktop-applications-ian-griffiths/

textbookfull.com

Introduction to Computing Applications in Forestry and


Natural Resource Management 1st Edition Jingxin Wang

https://textbookfull.com/product/introduction-to-computing-
applications-in-forestry-and-natural-resource-management-1st-edition-
jingxin-wang/
textbookfull.com
Pro TypeScript: Application-Scale JavaScript Development
2nd Edition Steve Fenton

https://textbookfull.com/product/pro-typescript-application-scale-
javascript-development-2nd-edition-steve-fenton/

textbookfull.com

Common On Revolution In The 21st Century Pierre Dardot

https://textbookfull.com/product/common-on-revolution-in-the-21st-
century-pierre-dardot/

textbookfull.com

The Secret of Running Maximum Performance Gains Through


Effective Power Metering and Training Analysis Van Dijk

https://textbookfull.com/product/the-secret-of-running-maximum-
performance-gains-through-effective-power-metering-and-training-
analysis-van-dijk/
textbookfull.com

Oral History and Education: Theories, Dilemmas, and


Practices 1st Edition Kristina R. Llewellyn

https://textbookfull.com/product/oral-history-and-education-theories-
dilemmas-and-practices-1st-edition-kristina-r-llewellyn/

textbookfull.com

Crisis Standards of Care A Toolkit for Indicators and


Triggers Institute Of Medicine

https://textbookfull.com/product/crisis-standards-of-care-a-toolkit-
for-indicators-and-triggers-institute-of-medicine/

textbookfull.com
Perinatal Mental Health : a Sourcebook for Health
Professionals First Edition Diana Riley

https://textbookfull.com/product/perinatal-mental-health-a-sourcebook-
for-health-professionals-first-edition-diana-riley/

textbookfull.com
Shing Lyu

Practical Rust Web Projects


Building Cloud and Web-Based Applications
1st ed.
Shing Lyu
Amsterdam, The Netherlands

Any source code or other supplementary material referenced by the


author in this book is available to readers on GitHub via the book’s
product page, located at www.​apress.​com/​9781484265888. For more
detailed information, please visit http://​www.​apress.​com/​source-code.

ISBN 978-1-4842-6588-8 e-ISBN 978-1-4842-6589-5


https://doi.org/10.1007/978-1-4842-6589-5

© Shing Lyu 2021

This work is subject to copyright. All rights are reserved by the


Publisher, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other
physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

Distributed to the book trade worldwide by Apress Media, LLC, 1 New


York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax
(201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the
sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For my wife Wei-Chi, my father Ching-Chuan, and my mother Man-Yun.
Table of Contents
Chapter 1:​Rust in the Web World
Who Is This Book For?​
Who Is This Book Not For?
Criteria for Selecting Libraries
Pure-Rust
Maturity
Popularity
How To Use This Book
Chapter Overview
Source Code
Chapter 2:​Developing Websites
What Are You Building?​
Hello World!
Serving Static Files
Rendering Dynamic Templates
Using a Database
Adding Cats with a Form
Showing the Cat Detail Page
Other Alternatives
Chapter 3:​REST APIs
What Are You Building?​
Converting the Cats List to a REST API
API Testing
Building the Cat Detail API
Input Validation
Error Handling
Using a ResponseBuilder or Response
Using the actix web:​:e
​ rror Helpers
Using a Generic Error That Implemented the ResponseError
Trait
Using a Custom-Built Error Type
Customize the web:​:P
​ ath Extractor Error
Logging
Enabling HTTPS
Other Alternatives
Chapter 4:​Chatting in Real-Time with WebSocket
Introduction to WebSocket
What Are You Building?​
A WebSocket Echo Server
Pushing Notifications from the Server
Cleaning Up Unresponsive Clients
Two-Way Chat
Sending Structural JSON Data
Other Alternatives
Chapter 5:​Going Serverless
What Are You Building?​
Registering an AWS Account
Hello World in Lambda
Making a REST API with Lambda
Using the Serverless Framework
Building the /​cats API
Building the Upload API
Uploading the Image Using S3 Presigned URL
Adding the Frontend
Other Alternatives
Chapter 6:​High-Performance Web Frontend Using WebAssembly
What Is WebAssembly?​
What Are You Building?​
Hello WebAssembly!
Setting Up the Development Environment
Creating the Project
Creating the Frontend
Resizing Images with WebAssembly
Loading an Image File Onto the <canvas>
Passing the Image to Wasm
Writing the Whole Frontend in Rust
Setting Up Yew
A Hello World Example
Reimplement the Image-Processing Frontend with Yew
Other Alternatives
Index
About the Author
Shing Lyu
is a software engineer who is passionate
about open source software. He’s
worked with Rust professionally at
Mozilla, on the Firefox (Gecko) and Servo
browser engine project. Currently, he
works at DAZN, a sports-streaming
platform as a backend developer, with a
focus on AWS and serverless technology.
Shing has worked for many world-
famous brands like Mozilla,
Booking.com, and Intel. He is also active
in the open source community. As one of
the founders of the Taiwan Rust
community, he loves to share his enthusiasm for Rust with others.
About the Technical Reviewer
Carlo Milanesi
is a professional software developer and
expert in C++, graphics programming,
and GUI design. He graduated from the
State University of Milan and has worked
in the financial and CAD/CAM software
industries. He enjoys writing software in
Smalltalk and Rust.
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
© Shing Lyu 2021
S. Lyu, Practical Rust Web Projects
https://doi.org/10.1007/978-1-4842-6589-5_1

1. Rust in the Web World


Shing Lyu1
(1) Amsterdam, The Netherlands

If you are reading this book, you are probably as excited about Rust as I
am. Since the first stable release in 2015, Rust has come a long way in
terms of features and stability. Developers around the world are
fascinated about how Rust can combine features that were once
thought of as unavoidable trade-offs: performance with memory safety,
low-level control with productivity. Despite its infamous steep learning
curve, Rust has gained popularity over the years. It was named the
“most loved programming language” in a StackOverflow survey four
years in a row, from 2016 to 2020. Many big companies and
organizations—like Facebook, Microsoft, Dropbox, and npm—have
started using Rust in production.
How are people using Rust? If we take a look at crates.io, the official
Rust crates (libraries) registry, there are over 28,900 crates and over a
billion downloads. There are 47 categories on crates.io,1 ranging from
the command-line interfaces, cryptography, databases, games,
operating systems, and many more. But one of the most exciting fields
is web programming. Many people spend most of their waking time
online. There are roughly 1.5 billion websites on the World Wide Web.
So it’s natural that Rusticians are looking for ways to build websites and
web applications with Rust.

Note If you look for web development job postings nowadays,


you’ll come across the terms “frontend developer,” “backend
developer,” and “full-stack developer.” A frontend developer builds
things that run in the frontend; usually, this is the end user’s browser.
A backend developer builds things that run in the backend, usually
the server that acts as an HTTP server, WebSocket server, or other
protocols. A full-stack developer works on both.
The typical technologies these roles need to work with include:
Frontend: HTML, JavaScript, CSS, and WebAssembly (see
Chapter 6).
Backend: Web framework, REST API, database, WebSocket (see
Chapters 2 to 5).

This book focuses on Rust for web applications. Since the backend is
usually more language-agnostic, most of the chapters will be about the
backend. We’ll follow the history of how the backend evolves, starting
with server-side-rendered websites. Then we’ll develop REST APIs and
WebSocket servers. Finally, we’ll deploy this API onto the cloud using
serverless technologies. That doesn’t mean Rust can’t be used in the
frontend. With WebAssembly now available in most mainstream
browsers, we can compile our Rust code to WebAssembly and run it in
browsers. This unlocks a lot of potential for highly-performant
applications in the frontend. After reading this book, you should have a
good grasp of how to build a full-stack application in Rust.
Who Is This Book For?
This book will be useful for:
People who already know basic Rust syntax, but want to learn how to
build web applications in Rust.
People who are considering using Rust to build production-ready
systems.
People who have experience in web development and want to see
how Rust can fit in.
If you already know how to code Rust, this book will help you learn
web development in Rust. You have probably built a few command-line
games and tools while reading The Rust Book2 or other introductory
courses. The final project in The Rust Book teaches you to build a toy
web server. But how do you build production-ready web services? This
book will introduce you to web frameworks and crates in order to apply
your Rust skill on the web. If you already know web development in
other languages (e.g., Node.js, Java, Go, Python, Ruby, etc.), this book
will help you see how Rust makes it more secure and ergonomic to
building web applications.
Who Is This Book Not For?
This book might not be that useful for:
People who want to learn the Rust programming language itself.
People who want to learn the fundamentals of web development.
This book is not a course on the Rust programming language itself,
nor is it trying to teach Rust’s syntax via examples. We’ll focus on how
to apply Rust to web applications, assuming you already know Rust’s
syntax and its language features. There are many excellent books on
Rust, like The Rust Programming Language by Steve Klabnik and Carol
Nichols. You can also find online books, interactive tutorials, and videos
on the Learn Rust section of the official website.3 I try to explain the
fundamental web development concepts before implementing them.
But this book does not focus on teaching general web development
concepts through Rust, so the explanations will be brief. You’ll get more
out of this book if you already have some experience with web
development in other languages.

Criteria for Selecting Libraries


Rust is a relatively young language for web development. Therefore,
although there are many frameworks and libraries out there, it was
hard to decide which one to include in this book. The following sections
cover the criteria for selecting which framework or library to use in this
book.

Pure-Rust
I try to find libraries that are built purely in Rust. Rust’s FFI (foreign
function interface) allows you to call existing C libraries (and many
other languages) from Rust. Therefore, the easiest way to build Rust
applications quickly is to leverage existing libraries in other languages.
These libraries are usually designed with other languages in mind, so
wrapping them in Rust results in a weird and not idiomatic Rust API. So
if there are pure Rust libraries, I tend to choose those.

Maturity
However, not every pure Rust library is mature. Because many Rust
libraries are built from a clean slate, the developers tried to experiment
with the latest technology, but that might mean that the architecture
and API design is very fragile and changes frequently. Some of the
libraries showed great potential in their early days, but then the
development slowed down, and the projects eventually went into
maintenance mode or were even abandoned. We aim to build useful
software rather than experiment with exciting technologies and then
throw the code away. Therefore, we need to be pragmatic and choose a
library that is mature enough and uses widely-accepted design
patterns.

Popularity
If two or more candidates meet the previous criteria, I choose the most
popular one. Popularity is based on a combination of factors, including:
Number of downloads on crates.io
Pace of development and release
Discussions on issue trackers and discussion forums
Media coverage
Although popularity is not a guarantee of success, a popular project
is more likely to have a big enough community that supports it and
keeps it alive. This can help us find a library that has the most potential
to stick around longer in the future. You are also more likely to get
support and answers online.
For backend-heavy chapters, I try to use plain JavaScript, HTML, and
CSS, without additional frameworks like React.js, jQuery, or SCSS. This
helps to keep the focus on the backend and avoid the need to learn a
new framework that might be out of fashion soon.

How To Use This Book


The chapters in this book do not strictly depend on each other.
However, the example website in Chapters 2, 3, and 5 has the same
functionality, but is built with different technologies. Reading these
chapters in sequence will help you compare the pros and cons of each
approach. Chapters 4 and 6 are relatively independent of the other
chapters, so you can read them in any order.

Chapter Overview
In Chapter 2, I started with the traditional form of website architecture:
server-side rendered websites. You’ll learn how to use the actix-web
framework to set up a web server. Then, you’ll learn how to render
dynamic HTML pages using a template engine. To make the website
even more interactive, you’ll set up a database and render the website
using the data in that database. Finally, you’ll learn how to build a page
that adds new information to the database.
In Chapter 3, you’ll learn about a different website architecture that
is popular among modern websites: using JavaScript to render dynamic
data provided by a REST API. You’ll learn how to return JSON-formatted
data from the API. I also introduce other commonly used techniques
that didn’t fit into the previous chapter: input validation, error
handling, logging, and enabling HTTPS.
In Chapter 4, you’ll learn about a different protocol, WebSocket, that
can help you build real-time, bidirectional communication. I’ll show you
how to use WebSocket to push real-time notifications to the client.
Then you’ll build a full-duplex chat application.
In Chapter 5, you’ll learn how to build a REST API using AWS
Lambda and other serverless services. You’ll learn how to use the AWS
SDK to communicate with the DynamoDB database. You’ll also learn
how to deploy the frontend to AWS S3 and connect it to the REST API.
After finishing this chapter, you’ll have a fully-functional website on the
Internet without worrying about server maintenance.
In Chapter 6, I change the focus to the frontend. First, you’ll learn
how to compile your Rust code to WebAssembly (Wasm) so it can run
in browsers. You’ll build a JavaScript-Wasm hybrid image-processing
application in the browser so you can leverage Wasm’s high
performance. Then you’ll learn how to use a frontend framework to
build the whole frontend application using only Rust.

Source Code
All the source code for this book is available on GitHub at
https://github.com/apress/practical-rust-web-
projects. The source code is also accessible via the Download Source
Code button located at
https://www.apress.com/us/book/9781484265888.
When I include source code in the book, I only include the part that
is relevant to the point being discussed. The irrelevant parts are
omitted with comments like this:

// ...

Therefore, not all code examples can be compiled successfully. To


check the fully working examples, use the source code on GitHub.
All the examples are developed and tested on a Linux (Ubuntu
16.04) machine. The Rust version is stable-x86_64-unknown-
linux-gnu unchanged - rustc 1.44.1 (c7087fe00
2020-06-17).

Footnotes
1 https://crates.io/categories

2 https://doc.rust-lang.org/book/

3 https://www.rust-lang.org/learn
© Shing Lyu 2021
S. Lyu, Practical Rust Web Projects
https://doi.org/10.1007/978-1-4842-6589-5_2

2. Developing Websites
Shing Lyu1
(1) Amsterdam, The Netherlands

There is no denying that the web is one of the most popular platforms on
Earth now. There are over 1.7 billion websites on the World Wide Web. And if
you look at job boards for developers, web developers take up a large
proportion of it. There are already many established programming languages
for building the backend: Java, PHP, Python, Ruby, Node.js, and Go, just to
name a few. But Rust fits perfectly into the web domain because of a few
reasons:
Security
Concurrency
Low-level control
Web security has been a big headache for everyone involved in building
websites. But many vulnerabilities are due to bugs that can be caught by
Rust’s type checker and borrow checker. By having Rust check your code at
compile-time, you can prevent many runtime vulnerabilities that might go
undetected and be exploited when you least expect them to.
Nowadays, popular websites need to handle a large number of concurrent
users. Therefore, concurrency and efficiency are crucial for web server
software to handle more and more users. Rust’s focus on ”fearless
concurrency” makes it easier to handle a large number of concurrent
requests. The relatively new async/await syntax also makes async I/O
more accessible to the average Rust programmer. On top of thread safety and
async I/O, Rust’s ability to control low-level CPU and memory opens up the
possibility of squeezing more performance out of the server hardware.
Rust also has a vibrant ecosystem that provides both high-level
frameworks and low-level control over networking, database access, and
type-safe templating. We are going to explore how to build a server-side
rendered website in Rust.
What Are You Building?
In the game Pokémon, there is a device called Pokédex, which is an
index/encyclopedia of all Pokémons. In this chapter, we are going to build a
cat index called Catdex. The Catdex should have the following features:
Show a list of cats. This demonstrates how to render a list of things using a
server-side template.
Read the cats from a database. This demonstrates how to set up a database
with Object Relational Mapping (ORM).
Use a form to add a new cat to the database. This demonstrates how to send
POST requests and insert the data into a database.
Show a specific detail page for each cat. This demonstrates how to read
parameters from the URL path.
There are many ways to architect a website. One important distinction is
server-side rendering versus client-side rendering. In server-side rendering,
the HTML is generated on the server-side when a request comes in. In client-
side rendering, the page is mostly generated in the browser by client-side
frameworks like React, Vue, or Angular. The client-side framework then makes
an HTTP request to a backend API to retrieve data that should go on the page.
We’ll talk about RESTful APIs in Chapter 3 and client-side rendering in
Chapter 6. But in this chapter, we’ll focus on server-side rendering.
We’ll be using the actix-web framework as our web framework.
actix-web doesn’t dictate which template engine and database you should
use. We’ll be choosing the Handlebar for templating. For the database, we’ll be
using a PostgreSQL database through the Diesel ORM and r2d2 connection
pool.

Hello World!
To start an Actix application, you first need to create an empty project with
cargo, then add actix-web as dependencies. Run the following command
in your terminal:

cargo new hello-world


cd hello-world
cargo install cargo-edit
cargo add actix-web
Tip The cargo-edit extension will add a new command called cargo
add. This helps you add new cargo dependencies without manually editing
Cargo.toml.

Once cargo adds the dependencies, your Cargo.toml should look like
Listing 2-1.

[package]
name = "hello-world"
# ...

[dependencies]
actix-web = "3"
Listing 2-1 Cargo.toml for a Hello World Actix Application

Now, open the src/main.rs file and copy Listing 2-2 into it.

use actix_web::{web, App, HttpResponse, HttpServer,


Responder};

async fn hello() -> impl Responder {


HttpResponse::Ok().body("Hello world")
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("Listening on port 8080");
HttpServer::new(|| {
App::new().route("/hello",
web::get().to(hello))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
Listing 2-2 Hello World Actix Application

The core of Listing 2-2 is the App builder in the main() function. The App
struct uses the builder pattern to build a new application instance. When you
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
call route(), you specify which handler should be called when the user
visits a specific path under the website. In this example, when the user visits
/hello with an HTTP GET method (web::get()), it invokes the hello()
handler.
The hello() handler is an async function that returns something that
implements a Responder trait. A Responder is something that can be
converted into an HTTP response. It’s implemented on common types like
&str, String, and u8 arrays. In this simple example, we respond with an
HttpResponse::Ok() (i.e., status code 200) and a string body “Hello
world”.
An HttpServer wraps the App. The HttpServer handles the incoming
requests and passes them to the App. We bind() an address
(127.0.0.1:8080) to the server so it will listen on the specific IP and port.
Finally, we call run() to start the server and await on it. Notice that the
HttpServer doesn’t take an App instance. Instead, it takes an App factory,
which is a simple closure that creates a new App instance every time. This is
because the HttpServer will create multiple worker threads, each running
one instance of the App. This way, we can better utilize multiple CPU cores
and achieve higher scalability.
You might also notice that the main() function is annotated with an #
[actix_web::main] attribute macro. This attribute tells Actix to execute
the main() function in a special runtime called actix-rt, which is built on
top of the popular Tokio1 runtime.

Note You might be aware that the functions in the “hello world” program
all have async in front, and you need to put .await after them when
calling. This is an important language feature that makes it possible to
build highly-efficient web servers. When you call a normal (i.e., blocking)
function, the whole thread blocks and waits for the function to return. But
if the function is async, it immediately returns a Future instead of
blocking. When you .await on that Future, the program asynchronously
waits for it to complete, which allows other tasks on the same thread to
make progress.
This is extremely important when building web servers. A modern web
server usually needs to handle a large number of clients at the same time. If
the server processes only one thing at a time and blocks whenever it’s
waiting for I/O (input/output) like in a socket communication, it can only
serve one client at a time. One way to solve this is to use an operating
system (OS) construct called a process . A process is an instance of your
server program, and the OS allows you to start multiple processes. This
way, you can have one process handling one client. But processes have a
high overhead so this won’t scale very well.
Another alternative is to use several threads. A thread is a series of
instructions (and their surrounding execution context) that can run
independently of other threads. Threads and processes are implemented
differently in each operating system, but in general, a thread is a
component of a process. Threads in the same process share some common
resources like memory space, so they have a lower overhead to run than a
process. Therefore, we can run more threads than processes on the same
hardware, thus serving more clients.
However, because network I/O is much slower than CPU, most of the
time, the threads are sitting idle, waiting for network I/O. Although threads
are lighter than processes, they still have some overhead. By using
async/await, we can potentially serve multiple clients per thread. When the
server is waiting for a client’s network I/O, it can yield the execution to
other clients served by the same thread.
This is an overly simplified explanation of async/await and how it can
help web development. If you want to learn more about the history and
rationale of Rust’s async/await design, watch Steve Klabnik’s talk called
“Rust’s Journey to Async/Await.”2 You can also read the Asynchronous
Programming in Rust book3.

To run this example, simply run the cargo run command in the terminal
under this project directory. A web server will start on 127.0.0.1:8080, as
we specified. Once the server is running, open a web browser and go to
http://127.0.0.1:8080/hello, and you’ll see the “Hello world” text
(Figure 2-1).

Figure 2-1 Web server responding with “hello world”

Serving Static Files


In the “hello world” example, we respond with a simple string. But most web
pages are built with HTML (HyperText Markup Language). You could write
HTML as a very long string in the Rust code and serve them that way, but it
would be hard to manage. A more common way is to store the HTML as
separate .html files and serve them with the web server. An HTML file
usually also includes other CSS, JavaScript, or media files (e.g., images or
videos). Actix allows you to serve all these files easily without explicitly
writing code to read the file from disk.
First, let’s create the files that will be served. Let’s create a new project
named catdex and add the dependencies. Then we’ll create a folder called
static, which will hold the static files. Under ./static/, we’ll also create
a css folder for CSS and an image folder for images:

cargo new catdex


cd catdex
cargo add actix-web actix-files
mkdir static
mkdir static/css
mkdir static/image

You can put some cat images (in JPEG format) in the static/image
folder. We also need to create an index.css file in static/css that will be
used by static/index.html.

.
+-- Cargo.lock
+-- Cargo.toml
+-- src
| +-- main.rs
+-- static
+-- css
| +-- index.css
+-- image
| +-- british-short-hair.jpg
| +-- persian.jpg
| +-- ragdoll.jpg
+-- index.html

Next, create a file called static/index.html and paste the HTML code
in Listing 2-3 into it.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Catdex</title>
</head>
<body>
<h1>Catdex</h1>
</body>
</html>
Listing 2-3 A Minimal Static HTML
To serve this HTML file, you need to install the actix-files crate. We
already did this in the previous cargo add step. Next, let’s paste the
following code into src/main.rs (Listing 2-4).

use actix_files::{NamedFile};
use actix_web::{web, App, HttpServer, Result};

async fn index() -> Result<NamedFile> {


Ok(NamedFile::open("./static/index.html")?)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("Listening on port 8080");
HttpServer::new(|| {
App::new()
.route("/", web::get().to(index))
})
.bind("127.0.0.1:8080")?
.run()
.await
Listing 2-4 Serving the index.html File

The code is almost the same as the “hello world” example, except:
The path is now / (root)
The handler, named index(), now returns a NamedFile
The NamedFile::open() function opens the file in read-only mode.
Because NamedFile implements Responder, we can return it directly in
the handler. It’s wrapped in a Result just in case the file reading failed.
If you run cargo run in a terminal, a server should start on port 8080.
Then you can open a browser and go to http://127.0.0.1:8080/ and
see the contents of index.html being rendered.
Since we are building a cat encyclopedia, we need to add some cat
pictures. You can add the following HTML to static/index.html (Listing
2-5).

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Catdex</title>
<link rel="stylesheet" href="static/css/index.css"
type="text/css">
</head>
<body>
<h1>Catdex</h1>
<section class="cats">
<article class="cat">
<h3>British short hair</h3>
<img src="static/image/british-short-
hair.jpg" />
</article>
<article class="cat">
<h3>Persian</h3>
<img src="static/image/persian.jpg" />
</article>
<article class="cat">
<h3>Ragdoll</h3>
<img src="static/image/ragdoll.jpg" />
</article>
</section>
</body>
</html>
)
Listing 2-5 index.html with External Image and CSS

This file now imports four extra resources:


Random documents with unrelated
content Scribd suggests to you:
"Oh," he said, in a completely changed tone, and made his way quickly
to where Carstairs was.

"Who are you?" he asked.

Carstairs was dressed and just moving off, "My name is Carstairs. I'm
an engineer too, electrical and mechanical. I'm staying at the Blue Boar in
the village, I have an engagement now. If you will call there this evening, I
shall be pleased to have a talk with you."

"But what's the fight about? Have my men been molesting you?"

"Oh no." Carstairs looked round, the navvies were beginning to move
off hurriedly. He did not want to get them into trouble, still he was not good
at lying. "I was to blame," he said. "We had a difference of opinion and
settled it in the time-honoured way; they behaved like gentlemen."

The little man's eyes sparkled. He looked round, but the last of the five
hundred was disappearing hurriedly, like a cart horse colt over the hillock.
He laughed aloud. "They're just damn great kids! those chaps, but the very
best. I shan't be able to get within earshot of one of 'em till Monday
morning now. They'll shun me like the plague." He laughed again. "By
George they are rum chaps. About the first week they were here there was a
violent row with the old farmer on the hill there." He pointed to a farm
house in the distance. "They went rabbiting with dogs and ferrets right in
front of his house; when he expostulated, they were going to pull his place
to pieces. He sent for me. I couldn't stop their poaching, of course, nobody
could; but I objected to their threatening the man. 'Well, sir,' they said (it
was that man Moore by the way), 'what beat us was the cheek o' the beggar
coming an' talking to three on us.' He didn't speak to one of them
afterwards, poor chap, he was frightened out of his wits; they're a mean sort
of swine, farmers. Fancy grousing about a blooming rabbit."

Carstairs laughed. "How about the woods over there?" he asked.

"Oh, I don't think there's much left in 'em now. The keepers keep away
when my chaps are about." The little man laughed. "They have elaborate
shooting parties with plenty of beer, and about six old guns between 'em.
Take it in turns for a shot. Gravely presented me with a pair of pheasants
once, and got quite shirty when I wouldn't have 'em; couldn't understand
that they were stolen. 'Why! the keeper seen us,' they explained. 'If he'd
been a wise man he would have not seen you,' I said. 'Will 'e 'ave a trout
then, mister?' 'No thanks,' I said. 'Well, I'm beggared,' they answered, and
went away growling. They still think I'm a bit mad."

They laughed together and strolled on. Carstairs was obviously


impatient, but the little man did not see it. He only met men with a soul
above beer at very rare intervals.

"Damn funny chaps, you know, but the best, the very best, at heart.
Don't care tuppence for anybody, and quite fail to see why they should.
'When my 'at's on, my roof's on, an' off I goes,' they say. They wander up
and get a start, work for a day, 'sub' a 'bob,' and slope off. Sometimes a man
will start one day, and next a policeman arrives, and the man is missing, two
or three more with him very likely. Damn funny chaps. What for? Oh,
nothing serious as a rule, pinching a pair of boots from a shop window, or
something like that, you know; I had a man murdered once, though; not
here—up in the midlands, had a hole knocked in his head with a pick axe,
never found out who did it. There are black sheep in every flock, of course."

"Men are about the same as any other machine, I think, you get out
rather less than you put in. Breed simply means efficiency and reliability."

"Yes. By Jove, that's so. Look here, come up to my digs, will you?
What! an engagement. Oh, I see. Well, ta-ta for the present."

They were quite close to the caravan, and the little man looked at
Carstairs curiously as he saw where he was going. He made no comment,
but turned and made his way back to the village.

The camp was quite silent, the vans were all drawn up together in the
form of a square. The dogs and children all seemed to have disappeared.
Carstairs went up the steps of the caravan, and knocked at the little door. He
began to wonder vaguely if the gipsies had all deserted the place, till he
caught sight of the crown of a hat and the muzzle of a gun on the roof of a
caravan.
The door was very quietly opened by the old woman (she was in ragged
male attire), and her eyes gleamed like an eagle's in the sunlight as she
looked at Carstairs. She put a hand on his shoulder. "Well done, well done,"
she said.

He put her hand gently aside. "Where is your daughter?" he asked.

"Gone to London," she answered.

Carstairs frowned like a thunder-storm. "Confound it! She gave me this


ring about two minutes ago."

The woman smiled and looked at the ring. "Yes, that's her mother's.
Don't lose it."

"Yours?" he said. "What's she bolted away again for?"

She positively laughed, and Carstairs turned to go away. She stopped


him with a hand on his shoulder. "I'm not her mother," she said.

"What! Then who is?"

"Lady Cleeve's sister. She's dead."

"Holy God! But that man—Sir Thomas, said——"

"He didn't know and didn't care much. She's his child, but not mine;
mine died, and we stole this one. God forgive me! She's been more than a
daughter to me. And he—he was always drunk, always drunk when he
wasn't playing the fiddle, always drunk. And now he's dead."

"Oh!" Carstairs said; it was all he could think of at the time.

The gipsy woman sat on the top step of the little ladder, her head in her
hands, crooning to herself. "My God! My God! And now he's dead! He
charmed me with his singing and his playing, and he was in the gutter
playing for coppers and drink, while his lawful wife lay dying in her
mother's home. Oh, my God! my God!"
Carstairs stood in wonder; he did not know whether to stay or go. She
took no notice of him, but crooned on, rocking herself from side to side.
"And now he's dead. Dead! Him that opened the gates of Heaven with his
fiddle! dead and along with her, but I shall have him; he's mine, mine, and
there's another. O my God! My God! but I'm going too! I shall be the first."

Carstairs tapped her on the shoulder. "Pull yourself together," he said.


"Shall I get you some brandy?"

"Brandy? No! that's been the curse of it all." She raised her head and
glared at him with eyes like live coals. "I stole this child, his child, that
ought to have been brought up in the lap of luxury, I stole her and brought
her up like a gipsy to try and bring him back." She dropped her head into
her hands again and wailed. "God forgive me! God forgive me!"

He shook her quite roughly. "It's no use groaning now," he said, "try and
make amends. Have you told the girl who she is?"

"Yes, to-day, and gave her the ring. All there is to prove it."

"Is that why she left you, then?" Carstairs could hardly believe it,
remembering the affection the girl had always shown for this woman whom
she believed to be her mother.

"No, no, she kissed me like an angel from heaven. It's you, you who
made her leave."

"Me! but she's just given me this ring, and—and she kissed me too."

The woman looked up at him again, but her eyes were now dim with
tears. "You don't understand, she's very proud, prouder than that old man
who's just dead. She'll come for that ring some day."

"No! By God, she won't. I'll find her, and take it to her." He pulled out a
card. "Look here, that's my address. If I don't find her before I go back next
week, will you send me her address, or any news of her you may have?"

"I shall be dead in a month; it's no use leaving me this."


"What's the use of talking rot like that?" he said, angrily. "Are you going
to help me?"

"No," she answered simply.

He turned and left her without another word. "Bounce," he said, as he


climbed into the dog-cart, "you've had some experience. Are all women
mad?"

"Every one on 'em, sir. That is, them wots any good."

"Ah! Well, let her go like hell for Southville."

On the way they passed the little civil engineer. "Hullo!" he shouted,
"are you off, then?"

Carstairs pulled up. "Yes, jump up and come on into Southville with me,
I want some one to swear at."

"Ha! That's it, is it?" He climbed in. "What else are you going to do with
me?"

"Put you up for the week-end, swear at you all day, Sunday, and send
you back about your business on Monday."

"Well, half a minute; let's go via my digs—that farm over there—and I'll
collect some togs."

"Not a sock or a pyjama. Come as you are, and we'll go to church to-
morrow, yellow leggings, and all. I want you to be best man."

"This is rather sudden, isn't it?"

"Not at all, the only obstacle is whether I can catch the bride in time."

"Ah, I see, but there's some formality about banns, and living in the
parish, and so on."

"My dear fellow, I'm a parson's son."


"I might have known that by your command of swear words. So am I."

"Is that so? I might have known that too by your perverted morals.
Never saw such an indignant chap as you when you thought those navvies
had cheated you out of a fight."

"Yes. By Jove, I shall wake those chaps up about that on Monday."

They all three laughed.

"The bride is along this road somewhere; she's only got about twenty
minutes or half an hour's start. We're bound to catch her, and then, by Jove!
I'll gag and bind her if she won't come quietly."

"They never do that," Bounce said, wagging his head sagely.

"Look here, Bounce, if you sit up there croaking away like some old
raven, I'll chuck you out of the cart."

"Very sorry, sir, but fax is fax, ain't 'em?"

Carstairs turned to the civil engineer. "They call him Bull-dog Bounce,"
he explained, "it's no use arguing with him. By the way, I don't know your
name. Mine's Carstairs."

"Whitworth. Jack Whitworth."

"Jack. I'm a Jack, too. So is Bounce here. That's strange."

"No, sir. Beggin' your pardon, sir. A. E. Bounce, sir. Algernon Edward
Bounce, A.B. That's how it's writ down in the Service books."

"Yes, of course, so you told me before. I'd forgotten. I'm sorry."

The little civil engineer was inclined to smile till he glanced at Bounce's
perfectly serious face, then he stared straight ahead, and they drove in
silence for some time.
As they neared the outskirts of Southville and still saw no signs of the
girl on the road, Carstairs got angry. "I wonder if that woman lied to me,"
he muttered.

They drove on till they reached the hotel. "No luck this journey," he
said, with a resigned smile. "Come on in and have a drink, Bounce." They
held a council of war in the smoking room. Whitworth raised his brows in
wonder at the tale which was partially disclosed to him.

"The curse of it is, I've got to go up north again on Wednesday,"


Carstairs said.

"Ah, that is awkward. I'll keep an eye on the camp for you, and let you
know if the girl's there, or if that dark chap is hanging around."

"Mister Darwen's 'ad enough I expect, sir."

"Not he, Bounce. He'll turn up smiling again."

Bounce left them shortly afterwards, and the two engineers, after
partaking of a substantial meal, strolled round the town, particularly the
railway station part of it, in the hope of meeting the girl. At about ten
o'clock they went home and went straight to bed, they had both had a busy
day, particularly Carstairs.

The hotel was old fashioned and very comfortable, but the resources in
the way of bedrooms were strictly limited, partly due to the reputation of
the place. Anyhow that evening the only bedroom they had to offer for
Whitworth was a small one right at the top of an obscure wing of the
building. Carstairs said nothing, but had his own luggage taken up there,
and gave Whitworth his room, fairly large, close to a bathroom and over-
looking a nicely kept lawn and shrubbery. He saw him installed in it,
supplying his wants as much as possible from his own portmanteau.

"I'm sorry I brought you away in such a hurry."

"That's alright, I'm used to roughing it. It's quite a treat to me to have the
electric light in my room and listen to the traffic outside. I feel like a kid on
a holiday in London."

"Hope you'll sleep alright. Good night."

"Trust me for that. Good night."

Carstairs was soon in bed and asleep, but it was still dark when in his
obscure corner of the building he became aware of some sort of commotion
going on downstairs; he had a sort of vague impression that he had been
awakened by a cry. He lay for a moment and heard a police whistle blown
violently, and a voice shouting, "Police! Police!"

He sprang out of bed, hurriedly donned a few garments, and wound his
way along tortuous passages to the entrance hall. Whitworth was standing
there (the centre of a group) in shirt and trousers, with a small bedroom
poker in his hand.

"What's the trouble?" Carstairs asked.

"Trouble! By Gad!" The little man was red as a turkey cock and
furiously angry. "Some damned swine tried to rob me, came in through the
window. I was awake and heard him climbing up, wondered what it was.
The window was open—I always sleep with it open—he pushed up the
bottom sash and got inside, then I switched on the light and went for him.
Look here!" he stretched his neck and pulled down the collar of his shirt
showing finger marks still there. "He had no boots or stockings on; he took
me by the throat and held me off, with one foot shoved into the pit of my
stomach. I was as helpless as a kid. His arms were so long I was quite clear
of him, and he was as strong as a tiger. Then—what do you think? he
looked in my face a minute, and chucked me across the room. Look here,"
he exposed a bruised elbow. "I grabbed the poker, and he hopped out of the
window like a monkey. I'll swear he was more like a monkey than anything
I've ever seen; he was doubled up, hunchbacked, and his head tilted
upwards all the time. His hands were below his knees; he jumped from all
fours. Most hideous brute I've ever seen. I ran to the window, intending to
chuck the poker at him, but he was gone; whether up or down, I couldn't
say."
Carstairs listened in silence, his face was very grave. A policeman
arrived, and took profuse notes. "Hunchback," he said. "There was a gang
here about three year ago with a hunchback bloke."

Then the excitement abated, and the few male visitors who had come
out half dressed, to ascertain the cause of the trouble, wandered back to bed.
The engineers did likewise.

Carstairs, before getting into bed, carefully examined the room; he


locked the door, wedged the window, and put his big pocket knife under his
pillow. Then he slept like a top, for he was at heart a fatalist, and felt that
nothing would happen that night, and he was right. The morning broke
bright and clear, and he and Whitworth were down to breakfast early.

The little man chatted away merrily about his adventure as he disposed
of a very liberal breakfast. "The cheek of the swine, to try and rob me!" he
said, with unbounded astonishment and indignation, so that Carstairs
smiled.

"You seem to have imbibed the spirit of your navvies pretty well."

Whitworth laughed. "By Gad, if I'd got that poker a second or two
sooner, I'd have flattened him out. Wish old Hiscocks had been there. He's
my sort of body servant, chain-bearer, carries the instruments, and that sort
of thing, one of the finest men on top of this earth, sixteen stone odd, and no
stomach; he'd have flattened that chap to a pulp, he's been in the marine
artillery."

"Yes, I know. Bounce knocked him out in a ten-round contest in Japan."

"What!" Whitworth dropped his knife and fork in astonishment.

"That's right, because I remember my uncle telling me about it."

"Good Lord! That little Bounce. Well, I'm hanged."

"My dear chap, Bounce is invincible. You ought to have seen him chuck
a seven-foot policeman out of the works in this town one night."
Whitworth went on with his breakfast with a business like air. "I must
find a job for Bounce," he said, decidedly. "What's his pay now?"

"That's been arranged; he's coming up north with me, driving on the test
plate. He's worth his weight in gold there, so prompt, clear-headed, and
reliable."

"Mean swine! Fancy keeping a man like that indoors driving dirty
engines, he ought to be outside in the sun and the rain with the birds and the
flowers."

Carstairs laughed. "When you've finished grubbing we'll get outside


with the flowers and the birds," he said.

Shortly after they sallied forth together and went for a brisk walk in the
country. Coming back they were just in time for the people trooping out of
church, and who should they meet but Darwen, prayer book in hand,
smiling, gay, as usual.

"Hullo, there's that chap—" Whitworth commenced.

"Yes. He's probably the biggest sweep unhung, but I know his mother,
and I must have a word with him."

Darwen held out his hand. "May I presume to congratulate you on a


good score yesterday?" he said.

"I was lucky," Carstairs answered, ignoring the hand. Whitworth


strolled on.

Darwen still smiled. "I can't allow that, my dear chap. You were good,
scientific. I ought to have known you were not such a fool as you look."

"Thanks."

"Don't mention it, old chap, honestly I consider you a smart chap; in
fact, it begins to seem as if there's not room on this earth for both you and
I." He smiled in his happy, genial way, but his eyes were taking in every
movement of Carstairs' features.
"Oh, the earth is a big place, we can avoid each other. I'm going to
Chilcombe to-morrow, and next day up north again, I expect, but can't say
for certain till I get my letters. I shall call to see your mater when I'm that
way."

"Yes, do! Of course she need never know of our little scrap, eh?"
Darwen's eyes had the same old sparkle in them, and Carstairs with
immobile face and calm eyes was watching him as he watched an engine
under test.

"No, of course not!"

"By the way one of my old friends in the force told me there was a
burglary at some hotel here last night." His eyes flickered with a sunny
smile as he watched Carstairs' face.

"Ye-es, my hotel. A drunken sailor climbed in at one of the windows


and left by the same route." Carstairs' face was almost expressionless.

"Ah! You didn't see the fun, then?"

"No, there wasn't much to see, I understand."

Darwen stepped up close and looked intently into his eyes. "Do you
ever lie, Carstairs?"

"Oh, yes! not, I think, frequently; as often as you, for instance." His face
was sphinx-like still.

"No, by God, I don't believe you could! Decently!" He stepped back and
laughed aloud. "You've neglected the most vital accomplishment of modern
life—to lie well. Ta, ta, old chap, I wish we could be pals." He passed on
with a happy smile and looked up to the sun. "The Lord has delivered him
into my hands," he said, to himself.

Carstairs rejoined Whitworth, and they returned to the hotel. After


dinner, as they sat smoking, he said, suddenly: "Would you like to catch that
chap who tried to rob you last night?"
"By Gad, I should like to give him a hiding."

Carstairs puffed his pipe in silence for a few moments, his steady,
shrewd eyes observing Whitworth closely. "That man came to murder me,
not to rob you," he said, at length.

"Good God, man! What are you talking about?"

"What I believe to be the truth. Can you get to-morrow off, and come
home to my place with me—that is, if you're game for a man hunt."

"Rather! But I say—are you sure?"

"Well, er—reasonably. The solution I have in mind seems to satisfy


most of the conditions of the problem; we are up in the clouds somewhere,
beyond all rules. The only methods for such problems are trial and error.
Will you come?"

"You bet, but I must get a change of togs, first. What time do you want
to go?"

"Oh, in the afternoon some time. You can slip over to your digs in the
morning, and you might bring your man, Hiscocks, if you can. I'll get
Bounce."

So it was settled, and at half-past three on Monday afternoon, a select-


party of four got into a third-class carriage en route for Chilcombe.
Carstairs explained the situation. "We're going to catch a burglar, that's all,
but I want to keep him myself, that's why I don't want the police brought
into it. I hope that they'll come into action later for a double bag."

Bounce and the ex-marine nodded and asked no questions. They were
trained that way, but Whitworth leaned forward and spoke. "I say, it's a
ghastly business you know, that—that thing was half an animal, I'll swear it,
he didn't speak a word, only gave an animal sort of snarl, and his eyes as he
looked into my face were the eyes of a wild beast." He gave a little shudder.
"By God, we ought to kill it on sight."
"We can't do that, you know, but we can stun it. You saw that man who
was killed at the vicarage before, Bounce?"

"Yes, sir; mangled 'e was."

"I know. I saw Donovan." Carstairs puffed at his pipe. "Must be as


strong as an elephant. We'd better stun him for a start."

They arrived at Chilcombe and Bounce and Hiscocks put up at the


village inn, while Carstairs took Whitworth home. It was a merry gathering
that night at the vicarage; Stanley Carstairs was there, and the Bevengtons
came in. Whitworth was as lively as a cricket, he kept the whole company
continually on the smile with his humour and endless anecdotes of his
navvies and other people he had met. Jack Carstairs lay back in his chair
and listened with a steady smile. He was watching Bessie Bevengton and
Whitworth and was rather glad he'd brought the little man home.

It was after eleven when the party broke up, and Jack took Whitworth to
his bedroom. "Here you are," he said, handing him a heavy cudgel. "I'll
meet you in the hall in half an hour's time."

"Alright. I say, jolly evening. Who's that girl? Is she—engaged?"

"Oh, no, one of the best, too. We've been chums since we were kids, so I
know."

The little man whirled his cudgel round his head thereby seriously
endangering the furniture. "We'll flatten that beast out," he said, with
extraordinary fervour.

Carstairs laughed. "In half an hour," he said, and went to his room. He
turned the gas full on and stood by the window for some minutes with the
blind up, in full view of the lawn and shrubbery below. The sky was quite
clear, and a full moon was climbing up behind the distant Cotswold Hills.
The beauty of the night enchanted him, this was his home, and many
memories thronged his brain as he gazed out at the old familiar landscape
silvered over with the soft, romantic light of the moon. For a moment he
forgot his mission, but a rustle of leaves among the evergreens below and
the hoot of an owl quite close at hand, brought him back from the dim and
distant past to the pressing, urgent present. He pulled down the blind,
picked up a book, and lay on the bed reading for half an hour; then he got
up, lighted a bull's-eye dark lantern, turned out the gas, and crept softly
downstairs; a dark figure was sitting quietly on one of the hall chairs, a big
stick across its knees. It was Whitworth. "This way," Carstairs said, softly,
and together they climbed quietly out of the back kitchen window; they
stood in the shadow of the wall for a minute and looked round. The lawn
was flooded with the soft moonlight, and the big chestnut tree cast a
shadow over the clump of laurel bushes near where they stood. Silently they
flitted across the narrow strip of moonlight and disappeared into the dense
shadow of the evergreens. A hand stretched out in the darkness and touched
Carstairs on the arm.

"Is that you, Bounce?" he whispered, very low.

"Yes, sir; nothing in sight yet."

"Alright. Get along a bit further where you can see my window. Is
Hiscocks there?" Something that seemed part of the wall murmured, "Yes,
sir."

"This way then." Carstairs moved forward and stepped on a dry twig
which snapped with a report loud enough to wake the dead, so it seemed to
their tensed nerves. Bounce stepped to the front. "I can see," he whispered,
"used to the dark at sea." They moved round the shrubbery in single file,
very slowly, till they came to a point where they could see the bedroom
window, full in the moonlight, just missed by the shade of the big chestnut
tree.

They stood there for half an hour, peering out from the darkness into the
moonlight. Suddenly they heard something stirring in the big tree, and next
instant Whitworth gripped Carstairs by the arm. "Good God! Did you see
that?" Something, a man or an animal, had shot out from the high branches
of the tree, and landed on the sill of Carstairs' bedroom window. They stood
there motionless, gazing at the thing on the window ledge, astonished,
paralysed; all except Bounce. For one second only was he held motionless,
the next he was on the lawn throwing his heavy stick at the window sill.
The thing turned as the stick struck it, and looking down, snarled like an
angry dog; next minute it sprang on to the tree again and disappeared, from
sight. That broke the spell, and they all ran out. "Don't shout!" Carstairs
whispered, hoarsely.

Before they were there the thing was down the tree and racing across
the grass on all fours. They saw Bounce fling himself on to it, and the next
thing was an indistinguishable tangle whirling about the lawn. As they
raced up the little sailor sprang clear and lashed out with his fist. The thing
stood erect, and they saw it was a hunchbacked man. He rushed at Bounce
who stepped aside. "Stand back!" he commanded the others in a hoarse
whisper. "I'll tackle 'im."

He closed in and they heard the dull thud of a body blow as the
hunchback reeled back. He charged again, snarling angrily. And again they
heard a thud as Bounce's bony knuckles came in contact with the man's
deformed breast bone.

Hiscocks raised his stick and rushed forward, but the sailor motioned
him back. They circled round each other in the moonlight, while the other
three stood silently by. The weirdness of it seemed to have cast a spell over
all of them. They saw the sailor step in, they heard a gasping pant, and next
minute the hunchback dropped limply to the ground. At once Bounce bent
over him, and pulling some cord from his pocket tied up his wrists and
ankles in his masterly, definite manner. "Quick," he whispered, "'e's such a
funny built bloke, I couldn't get at 'im afore." He stood up and putting his
hand to his mouth sucked it and spat. "Bit me, 'e did," he observed.

"That's nasty."

"Yes! Any'ow now we'll pack 'im up. 'Ave you got the sack, sir?"

Next day, at half-past two in the afternoon, Carstairs called at Darwen's


office in London. As soon as they were alone, he produced a revolver.

"We captured a bit of property of yours last night, Darwen."


"Ha! Is that so?" He sat down calmly in his chair, toying with an ebony
ruler, watching Carstairs carefully, and smiling all the time.

"Put that ruler down; it's no use, your man has gone back on you. I'll
give you twenty-four hours to corpse yourself, however you like, otherwise
I put the police on you. Before I leave this office I want a written
confession."

The brilliant eyes sparkled with amusement. "Dear old Carstairs! It's not
bad for a first attempt, but you were not built for a liar. It needs practice,
Carstairs! Constant practice. That man is dumb. I cut his tongue before I
utilized him for these little missions. Ha! Ha! I'm always willing to learn
from the experience of others. Old Donovan was bowled out by a tongue, I
removed it; swotted up the literature on the subject, and removed it myself;
the human body is a fascinating machine, better than greasy engines. What's
the next move, old chap?" His smile was the most charming he had ever
worn.

Carstairs toyed with the revolver, keeping his eye on him all the time. "I
think," he said, at length, "that as a duty to civilization I ought to wipe you
out here and now."

"My dear chap, how absurd! What's civilization done for you? Nothing!
Yes, by Jove, it has though, a service of a negative value. Civilization has
made you a poor man! As a savage, you would have been a chief! Don't
make yourself a bigger ass than nature intended, Carstairs, old chap! If I go,
you go too, and there's the girl, eh? The girl we scrapped over. The girl who
kissed you on the cheek; I saw her do it, and you blushed like a kid. She'd
be left all alone. Now let's talk this matter over quietly."

Carstairs looked him steadily in the eyes, toying meanwhile with the
revolver. "Do you know," he said, "that that girl is your sister?"
HE LOOKED ROUND, TO MEET THE GRIM GREY EYES OF
CARSTAIRS
Darwen doubled up with sudden laughter; in the intensity of it he almost
rolled into the fireplace. A sudden click pulled him up; he looked round
solemnly to meet the grim, grey eye of Carstairs gazing at him along the
revolver barrel; he had cocked it with his thumb.

"Damn it! You're not going to assassinate me, old chap."

"Come away from that poker! This is a six shot, a Colt's forty-four, and
every shot means a dead man. With it cocked as I have it, I can't miss at this
distance."

"By God, old chap, I'm proud of you. You're a credit to my up-bringing!
Impossible as it may seem you are becoming day by day less and less of the
fool that you look."

"I tell you again that girl is your sister."

"Well, what the devil am I to do! You won't let me laugh."

"Then you don't believe it?"

He spread out his hands in a deprecating gesture. "My dear Carstairs!"

Carstairs was thoughtful. "No! I suppose I shouldn't believe it myself,"


he said. "The man's dead, I have no proof except my word. Your mater
might——"

"Leave the mater out of it, Carstairs."

"Ye-es. I think so too. You're not fit to live anyway, and you know my
life won't be much to me as long as you're alive."

"Quite so. Quite so. Still there's no need to get personal over it. There is
not room for you and I on this little globe. That's it in a nutshell, isn't it?
One has to be eliminated, that's obvious; I'm a generous sort of chap, but I
can't oblige you in this. I'm in love, yes, by God, in real love for the first
and only time. I want that girl, also you want her! We have fought with
fists, and you won, but that is not the finish. I'm a sportsman; I'll go back a
hundred years with you and we'll fight a duel, eh? A fair and square duel—
to a finish."

Carstairs considered, watching him all the time. "What with?" he asked.

"Anything you like. I suggest rifles, magazine rifles, to make a clean


and engineering job of it."

"Well, I may as well tell you that rifle shooting has been my hobby for
the past two years."

"Noble savage! I won the Gascoign Cup myself."

"Alright, I'll take it at that. Where shall it be?"

"Oh, France! of course. We'll cross to-morrow, and open at a thousand


yards. We'll stalk each other among the sand hills, just below Havre there.
How's that for real sport, eh?" He looked at Carstairs' steady, thoughtful
face with genuine admiration. "By God, Carstairs, you're one of the best!
The best. It's a pity we crossed. I suppose you're not prepared to give up the
girl?"

"Only to a better man, not to a blasted sweep like you."

"No, quite so! I should never under any circumstances fight you with
sledge hammers, Carstairs. We'll cross to-morrow, or this evening then. I
think the Havre boats only go at night. Shall we go round to Cook's together
and book now? Then we'll buy a couple of rifles." He was like a school boy
at the prospect of a holiday, the sporting spirit had bitten very deeply into
him. "Come on, old chap," he said, in the height of good humour, and they
went out together. They had dinner together and journeyed to Southampton
together. Carstairs, his hand on the revolver in his coat pocket, never for
one minute taking his eyes off him. They got aboard the little steamer, and
she cleared the dock at midnight. They paced the deck together, watching
the receding lights of the town; the sky was sprayed and flecked with
numberless little clouds, the moonlight shining through the cracks, and ever
and anon breaking out into full power between the larger gaps.
As they walked together, and the Solent widened out into the broad
English Channel and the Island faded from view, Darwen grew strangely
pensive and poetical.

"By Jove, there's nothing like the sea, you know! the sea, by moonlight!
Look at that!"

They stood together at the rail, and gazed out over the tossing, tumbling
waste of waters, Carstairs still watchful, still suspecting treachery at any
minute. Darwen stood silently for some moments, then he burst forth into
poetry.

"Weary of myself and sick of asking


What I am, and what I ought to be,
At this vessel's prow I stand which bears me
Forwards, forwards o'er the star-lit sea.

And a look of passionate desire


O'er the sea and to the stars I send.
Ye who from my childhood up have calmed me,
Calm me, ah, compose me to the end!

'Ah,' once more I cried, 'Ye stars, ye waters,


On my heart your mighty charm renew;
Still, still let me, as I gaze upon you,
Feel my soul becoming vast like you!'

From the intense, clear, star-sown vault of Heaven,


Over the lit sea's unquiet way,
In the rustling night air came the answer:
Wouldst thou be as these are? Live as they."

"Do you hear that, Carstairs."

"Yes, I like it."


"Ah, I always knew you had a soul somewhere, deep down the abysmal
depth of that great carcase of yours. Listen! I'll finish it.

'Wouldst thou be as these are? Live as they?'

'Unaffrighted by the silence round them,


Undistracted by the sights they see,
These demand not that the things without them
Yield them love, amusement, sympathy.

And with the joys the stars perform their shining,


And the sea its long moon-silvered roll;
For self-poised they live, nor pine with noting
All the fever of some differing soul.'

Mark that, Carstairs.

'All the fever of some differing soul.'"

"Yes. It's good."

"That is so. It goes on:—

Bounded by themselves, and unregardful


In what state God's other works may be,
In their own tasks all their powers pouring,
These attain the mighty life you see.

A cry like thine in mine own heart I hear.


'Resolve to be thyself; and know that he
Who finds himself, loses his misery!'"

He had spoken softly and slowly, but quite distinctly; the silver cadence
of his rich, cultured voice died away, and they stood together in silence for
some minutes.
"In my opinion, Carstairs, that's one of the finest things in the English
language. When I read that, it seemed to express exactly what I had been
vaguely feeling for years past. It contains the germs, the kernel, of all the
philosophy in the world. 'Resolve to be thyself.' Ye gods, think of that!
Define 'yourself,' Carstairs! A German professor would fill six volumes and
then not do the job. Matthew Arnold does it in one.

'Unaffrighted by the silence round them,


Undistracted by the sights they see,
In their own tasks all their powers pouring.'

There you are. Take that to heart, Carstairs. God knows how much energy
you've dissipated uselessly, in thoughts on other people, hopes and fears.
Lord! I've been as happy as a bird all my life. That's true religion, Carstairs.
I should like to have a talk with your guv'nor on that. He's a sound man,
your guv'nor, but with a weakness for worrying over other people's troubles.
I never do, or very seldom. 'Keep fit, and answer the impulses of your
reason.' That's my motto."

Carstairs said nothing, but watched him closely. He continued. "I say 'I
never worry over other people's troubles,' you're the only man I've ever
worried over; honestly, Carstairs, you appeal to me exceedingly. I've often
wondered whether you're before your time or after, there is much of the
noble savage about you. I regard you with awe, yet you can think. You use
steam, and coal, and electricity; but you totally disregard men and women.
This little globe is just a box of bricks, you and I are part of them—
everything fits in—your duty here below is to look after yourself, to fill
your little niche efficiently."

Carstairs spoke. "You do that best by considering carefully your true


relation to other people, the real interdependence of every one, and the
lubrication of sentiment. As an engineer you must know that only the truth
endures."

"By Jove, that's true. 'Because right is right,' etc. As an individual you
would shine, your conception of the truth is very exact and your ability to
act up to it high. As an engineer you are good, but this is the age of states
and municipalities, of diplomacy and intrigue; when men are judged for
what they say, and not for what they do. Had my lot been cast among
companies, instead of municipalities, I should have had to entirely alter my
tactics. You can talk to a man and smile at him till you're blue in the face,
but if he sees that your work don't pan out into tangible dividends, you've
got to go. Municipalities don't put much on dividends, they like a smile and
a loud voice. If socialism comes to pass, your type will die out and my type
will flourish."

"God forbid."

"My dear chap, happiness is a condition of the mind, not of the body. I
bet I've made more people happy by my smile, than you have by your work.
Socialists are of two classes; wise men and fools (the same as everybody
else), the wise men want to develop and get a good price for their natural
powers of persuasion, the fools are sentimental idiots who propose to do
away with misery by doing away with individuals and the slums. By Jove!
the slums are about the happiest places, slum-bred people never commit
suicide, when they feel depressed, they go in for murder, a much more
healthy occupation. Garden mould is rotten-looking stuff, but the worms
enjoy it, and if you take 'em out and put 'em in nice, clean cotton wool,
they'll kick the bucket, and if there were no worms, there'd be no men, you
know. At the present time, England is overflowing with people who want to
put the worms in cotton wool. It's a question of religion; they have forsaken
their Gods. I suppose there are some Christians in England, I haven't met
them, probably they could be counted on the fingers of one hand. England
is a pagan country still; your guv'nor is one of the best men I've met, but
he's a pure pagan: I'd give a hundred to one in quids that if I slapped him on
the right cheek, he'd instantly plug me in the left eye—and his entire
congregation, also his Bishop, would back him up. The Englishman
worships Thor, the magnified man with the sledge hammer; I'm a Dago, I
worship those brainy old chaps who lived in the Pantheon; they took life
easily in the sun, and hadn't a moral amongst them; I've rather a contempt
for Thor, he never showed any great brain capacity, but simply slogged
around blindly with a sledge hammer. It's a question of my Gods versus
your Gods: A man's religion is what he bases the conduct of his life on, not
which church he attends on Sunday: our stars were in opposition from the
start, Carstairs, and the moving finger of Fate is approaching very rapidly to
a blot—the elimination of a unit, with large-bore magazine rifles—and I
don't think it'll be me."

He paused and gazed out over the sea.

Carstairs, watching him closely, was lost in admiration of the beauty of


his profile silhouetted against the moon.

"The whole blooming world," he continued, "seems to be slopping over


with a sticky sort of sentiment. The centre of gravity of civilization is
becoming too high, it'll topple over presently. We have a new God 'The
people' and the people are those thick-headed fools one passes in the street:
the artizan, who makes things by the 'piece' (cheap and nasty), because he
can't be trusted to act on the square otherwise; he gets more than his whack
of the good things of life, and puts the surplus into beer and baccy; his
'missus' would like to keep a servant, and objects to bringing up kids. Then
there's the middle class man, brought up with the ideas and the ambitions of
an aristocrat, the physique of a clerk, and the ability of a navvy; his
recreation is suicide: and the aristocrats, I suppose, are those wishy-washy
young men, all nose and no chin, who loaf about the West End, and die of
ennui. All due to excessive sentiment! Sentiment is far more dangerous than
drink or drugs: in exceedingly small doses it adds to the flavour of life.
Sentiment will get you out of a job quick enough, but it'll never damn well
get you into one. You're my best friend, I honestly like you and admire you,
but to-morrow I'm going to shoot you, afterwards I shall be intensely sorry
—for precisely five minutes. Hullo! Who the devil is this?" His voice
changed to a note of anger.

Carstairs turned and saw something crawling, creeping, sidling


cautiously along the deck, like a dog that knows he's done wrong. It was the
hunchback. He got close up to Darwen, crouching down, and held up his
hands to view; the moon shone out suddenly from behind a cloud, and they
saw in the sudden burst of light that the flesh was riven from hands and
wrists as though they had been wrenched through something which was too
small for them.

Darwen looked at him a moment, then, stooping down, struck him


across the face with his flat hand. "You failed, and I have no use for
failures; as an intelligence department Sam failed—and he's gone; as an
executive, you have failed, too. What use are you?"

Carstairs listened spellbound.

The hunchback gave a piteous moan and looked up in Darwen's face


with a singular, dog-like, appealing look. He stooped and struck him again
in the face. "You're a fool, I tell you, a useless fool."

With a sudden bound the thing leaped on to the railing and over into the
sea.

Carstairs sprang to the side, Darwen was looking over like an eager boy.
"By Jove!" he said, "the poor devil can't swim a stroke." He vaulted lightly
on to the top of the broad handrail and stood for one second balancing with
the graceful ease of the practised gymnast, then he dived after him. "Stop
the ship, Carstairs," he said, as he went. A sailor on the poop threw a life
belt overboard, and raised the alarm. The ship was turned about, and went
round in a circle three times, but nothing was to be seen of either of them,
so she turned to her course again.

Carstairs leaned long over the side, gazing into the dark water swirling
past. A great big "Why?" confronted him. "Why? Why? Why?" he asked
himself, and the answer was locked away, with many another mystery, deep
down in the depth of the water at his feet.

For the rest of the night he paced the deck. Next day he gave all the
information he could to the authorities: the other passenger, they said, must
have been a stowaway, Carstairs thought so too. He took the train to Calais,
and returned as quickly as possible to break the news to Darwen's mother.

She had been up all night and was very haggard. "Where's Charlie?" she
asked, as soon as she saw him.

"He's had an accident——"

"He's dead!" she screamed, seizing him by the hand and looking into his
eyes. "Dead! Dead! I knew it."
"I'm afraid he is."

"Oh, my God! My God! Tell me, how was it?"

"We were going to Havre, he and I; he jumped overboard in the night to


rescue a stowaway."

She drew herself up with pride, the bleared eyes shone with an
unnatural light. "There! He was a sportsman to the last! He played wing
three-quarter for England when he was nineteen, and the same year he
scored fifty-six against the M.C.C. I was so proud, he was so handsome!
And now he's gone! Oh, my boy, my boy, my lovely boy! Oh God, take me
too." She fell forward on her face.

Carstairs picked her up and threw water over her; he called a servant,
and hurried out for a doctor.

She was dead—quite dead—her heart, the doctor said.

Carstairs went away and hurried north, he was a day overdue as it was.
He explained the matter as much as he could to the hard-headed ex-fitter.

"Ay!" the latter said, shaking his head, and there was a world of
sympathy in that shake of the head. "It's a bad business, lad, a bad
business." He had a commercial head equal to the best in the world, this
man, but his heart was exactly in the right place, too. He broached the
subject then to Carstairs that he was going to retire, and offered him a much
more important position in the firm, which ultimately led (with the great
success of his many patents) to a partnership.

For six months or so he was kept hard at the grindstone, external affairs
troubled him not at all; he heard that Bessie Bevengton was engaged to
Whitworth, who had got a good appointment on the staff of Sir Donald Cox
of Westminster; Bounce never ceased to marvel at the manner in which the
hunchback had broken out of the double lashing he had put round his
wrists; his brother Stephen had got a picture hung in the academy: all these
things seemed to affect Jack Carstairs like vague unimportant rumours, for
he knew, in his soul, that the girl was his, waiting for him, and he wanted to
go and fetch her: only, sometimes, in the early morning, when the
atmosphere outside was some ten or fifteen degrees below freezing point,
and he wallowed in his cold bath, breathing deeply and steadily through the
nose, then with the exhilarating reaction of his blood as he briskly wiped
down with a rough towel, these whispers from an external world would find
an echo in his brain. "By Jove, I must write and congratulate old
Whitworth," or "Jolly glad Stephen's done something at last."

Then he got a spell, and went to London. He stayed with his artist
brother.

"We'll go to the opera, and hear the new singer," the latter said on their
first evening together.

"Who is she?" Jack asked.

"Madame Edith D'Arcy, daughter of the late Sir Thomas D'Arcy, you
know. She's wonderful. Perfect statue, and a marvellous voice."

"Let us go by all means. Do you know her to speak to?"

"Well, not exactly. She's a protégée of Lady Cleeve's, you know."

"Is that so?"

Before the performance was half over, Jack surprised his brother by
getting up and leaving his seat.

"Where are you going?" he asked.

"To see Edith."

"Who?"

"Madame Edith D'Arcy. I'm going to marry her."

"Good Lord!"
"That's what I think, too; she's been dodging me for years." Carstairs
was quite confident, his income for the year had totalled considerably
nearer £4000, than the £400 stipulated by the autocratic old aristocrat.

He sent up his card and was admitted to her dressing-room. She was
dressed in magnificent robes for the part she was taking; he looked at her
for some moments, in silence, fascinated; she had attained the full
perfection of her beauty, and it was exceeding rare; her eyes looked into his
with a wondrous light. Still in silence he stepped up close and took her
hand, then, much to his own astonishment, his great shoulders bent forward,
and he kissed the back of her fingers; he had never imagined himself doing
such a thing, it was quite spontaneous. He raised his head and looked into
her eyes. "You are my queen," he said, with a smile, and then he took her in
his arms and kissed her on the lips.

"So you've come," she said, "you've been a long time—I—I wanted to
do something."

"Ye-es! That is the external—paradox, I imagine," he answered, gazing


steadily into the depths of her eyes. They were silent for some minutes. The
full tide of his deep, strong nature set to this beautiful woman; the splendid
purpose of life tingled in his blood and shone out through his eyes as he
gazed into hers. Only men like Carstairs feel such a tide. He felt that this
was the summit of his life. "The world was made for you and me," he said.

"There's the call," she answered, suddenly releasing herself. "I must go."

He stepped to the door and stood with his back to it, the big bulk of him
nearly filled it. "No! By Jove, you won't! Not this time."

"But I must," she said, "the manager will be frantic."

"Show me the manager, and I'll flatten him out."

"Please let me go."

"Not till you promise to marry me to-morrow."


"To-morrow! I can't."

"Alright, then, I'll burn this place down," he produced a box of matches
from his pocket.

"Don't be silly. Let me go, please."

"Never again!" He held a lighted match in his hand. "I'm willing to


compromise; will you name the day?"

"This time next year."

"Absurd!" He held the match to some drapery stuff near, and watched it
slowly kindle. "I'll give you till this time next month."

"Two months?" she pleaded.

"Alright," he said, crumpling up the cloth in his hands. He produced her


mother's ring from his waistcoat pocket, and slipped it on her finger. "That's
sealed then. What's the price of the curtain?"

"Five pounds," she said, as she disappeared through the door.

"Dirt cheap," he answered. "I'd buy a hundred at the same price." And
the audience, who were competent to judge, said that Madame Edith D'Arcy
had never sung as she sang that night.

PRINTED BY
TURNBULL AND SPEARS,
EDINBURGH

You might also like