1. Practical Rust 1x Cookbook Rustacean Team
download
https://ebookbell.com/product/practical-rust-1x-cookbook-
rustacean-team-53166474
Explore and download more ebooks at ebookbell.com
2. Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Practical Rust 1x Cookbook Second Edition Lloyd Frank
https://ebookbell.com/product/practical-rust-1x-cookbook-second-
edition-lloyd-frank-58312558
Practical Rust 1x Cookbook Pravin Dhandre
https://ebookbell.com/product/practical-rust-1x-cookbook-pravin-
dhandre-49577586
Practical Rust Projects Build Serverless Ai Machine Learning Embedded
Game And Web Applications 2nd Edition Shing Lyu
https://ebookbell.com/product/practical-rust-projects-build-
serverless-ai-machine-learning-embedded-game-and-web-applications-2nd-
edition-shing-lyu-51003808
Practical Rust Web Projects Building Cloud And Webbased Applications
Shing Lyu
https://ebookbell.com/product/practical-rust-web-projects-building-
cloud-and-webbased-applications-shing-lyu-22853120
3. Practical Rust Projects Building Game Physical Computing And Machine
Learning Applications Shing Lyu
https://ebookbell.com/product/practical-rust-projects-building-game-
physical-computing-and-machine-learning-applications-shing-
lyu-10922658
Practical Rust Web Projects Building Cloud And Webbased Applications
Shing Lyu
https://ebookbell.com/product/practical-rust-web-projects-building-
cloud-and-webbased-applications-shing-lyu-47965580
Practical System Programming For Rust Developers Build Fast And Secure
Software For Linuxunix Systems With The Help Of Practical Examples 1st
Edition Prabhu Eshwarla
https://ebookbell.com/product/practical-system-programming-for-rust-
developers-build-fast-and-secure-software-for-linuxunix-systems-with-
the-help-of-practical-examples-1st-edition-prabhu-eshwarla-50808156
Practical Gpugraphics With Wgpu And Rust Jack Xu
https://ebookbell.com/product/practical-gpugraphics-with-wgpu-and-
rust-jack-xu-53725400
Practical Machine Learning With Rust Creating Intelligent Applications
In Rust Joydeep Bhattacharjee
https://ebookbell.com/product/practical-machine-learning-with-rust-
creating-intelligent-applications-in-rust-joydeep-
bhattacharjee-10608512
8. Contents
Preface
Chapter 1: Setting up and Configuring Rust Environment
Recipe#1: Installing Rust Compiler
What Does Rust Compiler Do?
Install Rust Compiler and Tools
Recipe#2: Creating a New Rust Project
Files and Directories
Setting Up Rust Project After Installation
Recipe#3: Managing Dependencies to Your Project
What are Dependencies?
How to Add/Remove/Modify Dependencies?
Recipe#4: Installing Visual Studio Code IDE for Rust
Understanding VS Code IDE
Benefits of VS Code IDE for Rust Users
Why VS Code IDE for Rust?
Steps to Install VS Code
Recipe#5: Supporting Non-Rust Tools and Libraries
List of Non-Rust Libraries and Packages
Step-By-Step to Load and Implement Non-Rust Libraries
Recipe#6: Setting Up Code Testing Tools
List of Various Code Testing Tools
Install and Configure Code Testing Tools
Recipe#7: Installing and Configuring Cargo
What is Cargo?
Install Cargo Package Manager
Step-By-Step Configuring Cargo
Chapter 2: Hands-on Traits, Enums and Struct
Recipe#1: Working with Traits
How to Declare Traits?
Execute a Trait for Struct
Implement Different Types of Traits
Recipe#2: Define Function Inside Traits
Define Function Inside a Trait
9. Implement Function Within a Trait
Declare Generic Functions Inside a Trait
Recipe#3: How to Define Enums
Define Enums
Implement Enums
Fix Common Issues with Enums
Recipe#4: Tips and Considerations Regarding Enums
Declare Variant Values with Types and Fields
Pattern Match with ‘match’ Expression
Use of If Let Expressions
Recipe#5: Parsing and Interpreting Enum Arguments
Why to Parse Arguments?
How to Parse Enum Arguments?
Steps to Interpret Enum Arguments
Recipe#6: Initialize Array of Structs
Define Struct and Arrays of Struct
Initialize Array of Structs Using Loop
Initialize Array of Structs Using Trait
Initializing Using Loop and Trait
Recipe#7: Cloning Structs
What Is Cloning of Structs?
Implement Clone Trait for Struct
Chapter 3: Pattern Matching, Concurrency, Pointers and Modules
Recipe#1: Pattern Matching with Enum
Need of Pattern Matching with Enum
Implement Pattern Matching In Rust Applications
Recipe#2: Working with Tokio
Basics About Tokio
Installing and Configuring Tokio
Recipe#3: Writing Concurrent Programming
What Is Concurrency In Rust?
Procedure to Build Concurrent Programs
Implementing Concurrency to Existing Applications
Recipe#4: Working with Raw Pointers
Why Raw Pointers?
How to Use Raw Pointers In Rust Applications?
10. Use of Multiple Raw Pointers
Recipe#5: Working with Smart Pointers
Understanding Smart Pointers
Smart Pointers Vs Raw Pointers?
How to Implement Smart Pointer In a Rust Program
Recipe#6: Using ‘mod’ Modules
Declaring Mod
Advantages of Using Mod
Implement Mod In Existing Rust Program?
Chapter 4: Using Declarative and Procedural Macros
Recipe#1: Declaring and Implementing Declarative Macros
Defining Declarative Macros
Creating Declarative Macro
Recipe#2: Debugging Declarative Macros
Steps to Debug Declarative Macro
How to Debug Series of Declarative Macros In Rust Programs
Recipe#3: Using Derive Macro for Implementing Traits
Understanding Derive Macro As An Procedural Macro
Implementing Derive Macros
Recipe#4: Using Function-Like Macros
Understanding Function-Like Macros
Implementing Function-Like Macro
Recipe#5: Using Attribute Macros
Understanding Attribute Macros
Implementing Attribute Macro
Recipe#6: Debugging Procedural Macros
Tips and Tricks to Debug Procedural Macros
Techniques of Debugging
Chapter 5: Implementing Concurrency and Multithreading
Recipe#1: Implementing Concurrent Threadsafe Queues
Using Arc<Mutex<T>>
Using Std::Sync::Mpsc::Channel()
Using Crossbeam::Channel::Bounded()
Recipe#2: Implementing Concurrent Hash Maps
Understanding Concurrent Hash Map
Arc<Mutex<Hashmap<K, V>>> for Concurrent Hash Map
11. Rayon for Concurrent Hash Map
Recipe#3: Using Synchronization Mechanisms
Using Mutual Exclusion Lock ‘mutex’
Using Read-Write Lock ‘rwlock’
Using Atomic
Recipe#4: Designing Efficient Parallel Algorithms
What are Parallel Algorithms?
Putting Parallel Algorithms Into Use
Designing Parallel Algorithms From Scratch
Recipe#5: Debugging and Testing Concurrent Programs
Tips and Techniques to Test and Debug
Debugging Using ‘rayon’ and ‘crossbeam’
Recipe#6: Optimizing Concurrent Programs
Procedure Steps to Rust Optimization
Optimizing Rust Program Using Rayon
Recipe#7: Dealing with Deadlocks and Livelocks
Understanding Deadlocks and Livelocks
Chapter 6: Asynchronous Programming
Recipe#1: Defining Asynchronous Functions
Async Keyword
Programming Asynchronous Function
Recipe#2: Run Asynchronous Tasks
Executor
Using Tokio for Asynchronous Tasks
Recipe#3: Error Handling
Result Type: Ok and Err
Handling Errors Using Result Type
Recipe#4: Debugging Asynchronous Code
Tokio-test Crate
Testing Asynchronous Functions
Recipe#5: Working with Asynchronous I/O
I/O Operations
Performing Asynchronous I/O using Tokio
Recipe#6: Working with Channels and MPSC/SPSC Communication Patterns
Channels: MPSC and SPSC
Using Channel Function to Create MPSC (Multiple Producer, Single
Consumer)
12. Recipe#7: Implementing Asynchronous Networking
Tasks of Asynchronous Networking
Implementing Asynchronous Networking
Recipe#8: Integrate with Asynchronous Libraries
Tools and Techniques for Integration
Using tokio-sync to Integrate Asynchronous Tasks
Chapter 7: Developing REST and SOAP APIs
Recipe#1: Creating SOAP APIs
What are SOAP API?
Benefits of SOAP API -
Creating SOP API Using ‘xml-Rs’
Recipe#2: Building RESTful APIs
What are REST API?
Benefits of REST API
Building REST API Using ‘serde’
Recipe#3: Automating API Documentation
Rust Tools and Libraries for API Documentation
Automating API Documentation Using ‘rustdoc’
Recipe#4: Managing API Orchestration
Need of API Orchestration
Managing API Orchestration Using Ocelot
Recipe#5: Adding Security to API
Need of Security to APIs
Ways to Secure APIs
Securing API Using Actix
Recipe#6: Monitoring API
API Performance Monitoring
Monitoring Errors In API
Checking API Usage
Chapter 8: Building Microservices & Architectures
Recipe#1: Applying Fine-Grained SOA
What Is Fine-Grained SOA?
Features of Fine-Grained SOA
Implement Fine-Grained SOA In Rust
Recipe#2: Layering APIs
What Is API Layering?
13. Implement API Layering
Recipe#3: Implementing Event-Driven Communication Pattern
What Is Event-Driven Communication?
Implementing Event-Driven Communication Pattern In Rust
Recipe#4: Programming Middlewares
Understanding Need of Middlewares
Programming Middlewares for Logging Service
Stacking Multiple Middlewares
Recipe#5: End-To-End API Testing
What Is API Testing?
Running End-To-End API Testing In Rust -
Recipe#6: Splitting Monoliths with Strangler Fig Pattern
What Is Splitting Monoliths?
Benefit of Splitting Monoliths
Strangler Fig Pattern Explained!
Implementing The Strangler Fig Pattern to Split Monoliths
Recipe#7: Autoscaling Rust Programs
Rust Libraries for Autoscaling Applications
Autoscaling Rust Applications with Tokio
Chapter 9: Working around CI/CD
Recipe#1: Setting Up a Version Control Repository
Choosing Version Control System
Setting Up Git Repo
Recipe#2: Configuring a CI/CD Pipeline
Understanding Continuous Integration and Continuous Delivery
Configuring CI/CD Pipeline Using GitHub Actions
Recipe#3: Customizing CI/CD Pipeline
Steps to Customize CI/CD
Recipe#4: Integrating CI/CD Pipeline with Databases and Message Queue
Procedure to Integrate CI/CD Pipeline
Use of MySQL, amiquip and RabbitMQ
Recipe#5: Setting Up Docker Hub Container Registry
What Is Docker Hub?
Understanding Container Registry
Steps to Setup Container Registry
Establishing Container Registry On Docker Hub
14. Chapter 10: Working around Kubernetes
Recipe#1: Setting Up a Kubernetes Cluster On-Premises
What Is Cluster?
What Is Kubernetes Cluster?
Establishing Kubernetes Cluster On-Premises
Recipe#2: Setting Up a Kubernetes Cluster On AWS
Using AWS CLI and kubeadm for Setting Up Kubernetes Cluster
Recipe#3: Setting Up a Kubernetes Cluster On Google Cloud
Using gcloud and kubeadm to Setup Kubernetes Cluster
Recipe#4: Setting Up a Kubernetes Cluster On Microsoft Azure
Using Azure CLI and kubeadm for Kubernetes Cluster
Recipe#5: Testing The Cluster Setup Across AWS, GCP and Azure
Procedure to Test the Kubernetes Cluster
Recipe#6: Writing Deployment Configuration YAML Files
Understanding YAML Files
Writing Deployment Configuration Files
Recipe#7: Setting Up Load Balancers
Need of Load Balancers
Steps to Establishing and Configuring Load Balancers
Installing and Configuring Load Balancers Using HAProxy
Recipe#8: Setting Up Monitoring and Logging with Prometheus and Grafana
Installing and Configuring Prometheus
Installing and Configuring Grafana
Chapter 11: Fuzz Testing and Static Analysis
Recipe#1: Identify The Target System
Steps to Follow for Identification of Target System
Use of cargo-fuzz to Perform Fuzzing
Define Wrapper Function to Call Target System
Recipe#2: Identify Inputs
Understand The Format of The Input
Identify Inputs with cargo-fuzz
Recipe#3: Generate Fuzzed Data
What Is Fuzzed Data
Use of cargo-fuzz to Generate Fuzzed Data
Recipe#4: Best Practices to Run Fuzzing
Best Practices to Run Fuzz Testing
15. Recipe#5: Checking Syntax Errors
Various Techniques to Identify Syntax Errors
Executing Techniques to Spot Syntax Errors
Recipe#6: Detecting Coding Style Issues
Various Techniques to Detect Flaws In Coding Styles
Use of CodeScene and LGTM to Improve Coding Styles
Use of Rust Style Guidelines to Avoid Coding Style Issues
Recipe#7: Identifying Security Vulnerabilities
Techniques to Find Security Vulnerabilities
Using Static Analysis Tool, ‘Miri’ to Spot Vulnerabilities
Chapter 12: Code Performance Optimization
Recipe#1: Identify Performance Bottlenecks Using ‘perf’
What Is ‘perf’ Tool?
Running ‘perf’ Tool and Recording Performance Report
Recipe#2: Analyze Performance Bottlenecks Using ‘valgrind’
What Is Valgrind?
Analyzing Performance Bottlenecks Using ‘valgrind’
Recipe#3: Running Different Optimization Flags
What are Optimization Flags In Rust?
Different Types of Optimization Flags
How to Implement Optimization Flags In Rust Programs?
Recipe#4: Using SIMD Instructions for Efficient Performance
Understanding SIMD Instructions
What Is ‘simd’ Crate?
Using ‘simd’ Crate In Rust Application
Recipe#5: Overcoming Style Violations
Different Types of Style Violations
Steps to Remove Style Violations
Using ‘rustfmt’ and ‘clippy’ to Remove Style Violations
Recipe#6: Use of Low-Level Optimization Techniques
Understanding Low-Level Optimization Techniques
Benefits of Low-Level Optimization Techniques
Using Low-Level Optimization Techniques In Rust Programs
Recipe#7: Utilizing External High Performance Libraries
List of External High Performance Libraries In Rust
Utilizing High Performance Libraries In Rust Programs
16. Preface
Practical Rust 1.x Cookbook is an in-depth guide for
experienced Rust programmers looking to create robust and
efficient applications. This solution-focused book covers a
wide range of topics, including command-line, webassembly,
networking, kubernetes, microservices, and system
programming.
This book includes over 100 real-world practical exercises that
will teach you how to use the Rust compiler and command-
line programming across every stage of software development.
Each exercise is intended to reinforce Rust’s potential for
outperforming legacy applications and bridging the high
performance gap. You’ll learn about advanced solutions like
asynchronous functions, API testing, CI/CD pipelines, Fuzz
testing, and microservices architecture as you read the book.
You’ll also have the chance to put your knowledge to use by
solving complex concurrent and parallel code challenges.
You’ll also get hands-on experience with many of Rust’s built-
in frameworks and libraries.
Practical Rust 1.x Cookbook is a must-have for both
experienced and inexperienced Rust programmers looking to
create high-performance and robust applications. This book
will help you stay ahead of the curve in Rust coding by
providing clear explanations, practical examples, and step-by-
step illustrations. Get your copy today and start making the
apps you’ve always wanted to make!
This book will teach you how to:
Employing declarative and procedural macros, pattern
matching, and enums
Create and test asynchronous code, error handling,
and communication patterns.
Working with deadlocks and livelocks, as well as
implementing hash maps and parallel algorithms
17. SOAP and REST API development, API
orchestration, and performance monitoring
API layering, middleware programming, and end-to-
end API testing
CI/CD, Docker registry, Kubernetes cluster, YAML
files, and load balancers configuration
Working with fuzz testing, checking syntax, and
identifying code vulnerabilities
This book is written by a team of Rust professionals with an
intent to contribute and return back to both industry and
academic research communities.
18. GitforGits
Prerequisites
This book assumes you have already begun with rust
programming and working towards building error-free, robust
and scalable programs. Rust is a modern, safe and efficient
systems programming language that is widely used in industry
and is a good choice for developers who want to build high-
performance, concurrent, and safe systems.
Codes Usage
Are you in need of some helpful code examples to assist you
in your programming and
documentation? Look no further! Our book offers a wealth of
supplemental material, including code examples and exercises.
Not only is this book here to aid you in getting your job done,
but you have our permission to use the example code in your
programs and documentation. However, please note that if you
are reproducing a significant portion of the code, we do
require you to contact us for
Permission.
But don’t worry, using several chunks of code from this book
in your program or answering a question by citing our book
and quoting example code does not require permission. But if
you do choose to give credit, an attribution typically includes
the title, author, publisher, and ISBN. For example, “Practical
Rust 1.x Cookbook by the Rustacean Team”.
If you are unsure whether your intended use of the code
examples falls under fair use or the permissions outlined
above, please do not hesitate to reach out to us at
kittenpub.kdp@gmail.com.
We are happy to assist and clarify any concerns.
19. Acknowledgement
The Rustacean team would express their gratitude to all of the
other contributors to Rust and work tirelessly to improve the
quality of the programming language. While they are doing
this, they would want to express their gratitude to the
copywriters, tech editors, and reviewers who helped create a
powerful yet simple book that outperforms rust coding in a
relatively short period of time.
21. Recipe#1: Installing Rust
Compiler
What Does Rust Compiler Do?
The Rust compiler is a piece of software that takes the source
code written in Rust and converts it into machine code so that
it can be run on a computer. The syntax and semantics of the
source code are both validated by the Rust compiler to ensure
that the code is accurate and well-formed. The executable file
that contains the programme written in machine code will be
generated by the compiler if the source code is correct.
Because it enables developers to write code in a high-level
language and then have it translated into machine code that
can be run on a computer, the Rust compiler is an essential
component of the Rust development process. Rust is a
computer programming language that was created by Mozilla.
It also offers a number of additional features, such as error
checking and optimization, to assist developers in writing
high-quality code, and it does this in a number of different
ways.
Install Rust Compiler and Tools
To install the Rust compiler and tools, you can follow these
steps:
● Download the Rust installer: You can download the Rust
installer from the Rust website (https://www.rust-
lang.org/). The installer is available for Windows,
macOS, and Linux. You can follow the below steps -
○ Go to the Rust website (https://www.rust-
lang.org/).
○ Click the “Download” button in the top right corner
of the page.
22. ○ Select the installer for your operating system
(Windows, macOS, or Linux).
○ Download the installer by clicking the “Download
Rust” button.
● Run the installer: Once the installer has downloaded,
you can run it to begin the installation process. Follow the
below steps -
○ Once the download is complete, open the installer
file.
○ Follow the prompts to install the Rust compiler and
tools. This may include accepting a license
agreement, choosing an installation location, and
installing any additional dependencies.
● Verify the installation: Once the installation is complete,
you can verify the installation by opening a terminal or
command prompt and running the rustc —version
command. This should output the version of the Rust
compiler that is installed on your machine. Alternatively,
you can install rustup along with rust as below -
○ Go to the Rust website (https://www.rust-
lang.org/).
○ Click the “Download” button in the top right corner
of the page.
○ Scroll down to the “Install with rustup” section.
○ Click the “Install” button for your operating system
(Windows, macOS, or Linux).
○ This will download the rustup-init script to your
machine.
○ Open a terminal or command prompt.
○ Navigate to the directory where you downloaded
the rustup-init script.
○ Run the rustup-init script by typing ./rustup-init and
pressing Enter.
23. ○ Follow the prompts to install rustup. This may
include accepting a license agreement and choosing
an installation location.
○ Once the installation is complete, you can verify
the installation by running the rustup —version
command. This should output the version of rustup
that is installed on your machine.
That’s it! You should now have rustup installed and ready to
use. You can use rustup to install and manage different
versions of Rust and its associated tools. For example, you can
use the rustup install command to install a specific version of
Rust, or the rustup default command to set a default version of
Rust to use.
24. Recipe#2: Creating a New Rust
Project
Files and Directories
A collection of files and directories that contain Rust source
code and any other resources that may be associated with it,
such as configuration files and dependencies, is referred to as a
Rust project. The cargo build system is a tool for building,
testing, and managing Rust projects. This system is typically
used to organize Rust projects, and it is referred to as the cargo
build system.
Developing a Rust project is essential because it offers a
framework that can be utilized for the purpose of arranging
and constructing your Rust code. You will be able to use the
cargo tool to build and run your code, as well as specify
dependencies and build configurations. Sharing your code
with other people and managing multiple Rust projects both
become less difficult as a result of this.
The cargo new command can be used to initiate the creation of
a new Rust project. This command will populate the new
project directory with all of the essential files and directories.
After that, you can implement your project by editing the Rust
source code files that are located in the src directory. After
that, you can use the cargo commands to build and run your
code.
Setting Up Rust Project After Installation
To create a new Rust project after installing Rust, you can
follow these steps:
● Open a terminal or command prompt.
● Navigate to the directory where you want to create your
Rust project.
25. ● Run the cargo new command, followed by the name of
your project and any desired options. For example:
cargo new my-project
This will create a new directory with the specified name, and
generate the necessary files and directories for a new Rust
project. The most important file is Cargo.toml, which specifies
the project’s dependencies and build configuration.
● Navigate to the project directory by running:
cd my-project
You can now edit the Rust source code files in the src
directory to implement your project.
● To build and run the project, you can use the cargo build
and cargo run commands, respectively. For example:
cargo build
cargo run
If your project depends on external crates or libraries, you can
add them to your Cargo.toml file by specifying them as
dependencies. This will ensure that they are installed and
available to your project when it is built.
That’s it! You should now have a basic Rust project set up and
ready to go. You can continue developing and debugging your
project as needed.
26. Recipe#3: Managing
Dependencies to Your Project
What are Dependencies?
Your Rust project must have a certain number of
dependencies, which can be thought of as external crates or
libraries, in order for it to successfully build and run.
Additional functionality, such as networking or serialisation,
that is not included in the Rust standard library can be
provided by dependencies.
Dependencies are required for a Rust project because they
enable you to incorporate code written in other languages or
by other developers. This not only prevents you from having
to reimplement functionality that is already present, but it also
gives you access to specialised libraries and tools that are not
included in the standard library. This can save you a lot of time
and effort.
Following are some helpful examples of dependencies that
you might use in a Rust project:
● reqwest: A library for making HTTP requests in Rust.
● serde: A library for serializing and deserializing data in
Rust.
● tokio: A library for building asynchronous applications
in Rust.
● clap: A library for parsing command-line arguments in
Rust.
To use a dependency in your Rust project, you need to specify
it in your Cargo.toml file and then import the necessary items
from the dependency in your Rust code. cargo will
automatically download and install the dependency when you
build your project.
27. How to Add/Remove/Modify
Dependencies?
To manage dependencies to a Rust project, you can follow
these steps:
Open the Cargo.toml file in your project directory.
This file specifies the dependencies and build
configuration for your project.
Under the [dependencies] section, add a line for
each dependency you want to include. Each line
should specify the name of the dependency and the
version you want to use, separated by an = sign. For
example:
[dependencies]
reqwest = “0.10.8”
tokio = “0.2.22”
Save the Cargo.toml file.
Run the cargo build command to build your project.
This will cause cargo to download and install any
specified dependencies, and then build your project
using those dependencies.
If you want to update or remove a dependency, you
can edit the Cargo.toml file accordingly and run the
cargo build command again to update the
dependencies in your project.
That’s it! You should now have your desired dependencies
included in your Rust project. You can use them in your Rust
code by adding extern crate declarations and importing the
necessary items from the dependencies.
For example, to add dependencies to a Rust project, you can
use the cargo add command. This command allows you to add
28. new dependencies to your Cargo.toml file and install them in
your project. For example, to add the serde library as a
dependency, you can run the following command:
cargo add serde
To remove dependencies from a Rust project, you can use the
cargo remove command. This command removes the
dependency from the Cargo.toml file and uninstalls it from the
project. For example, to remove the serde library as a
dependency, you can run the following command:
cargo remove serde
To modify dependencies in a Rust project, you can edit the
Cargo.toml file directly. This file lists all of the dependencies
for the project, along with their version numbers. You can
change the version numbers or add/remove dependencies as
needed. For example, to update the version of the serde library
to the latest version, you can modify the Cargo.toml file as
follows:
[dependencies]
serde = “1.0”
[dependencies]
serde = “1.1”
After making any changes to the Cargo.toml file, you will
need to run cargo build or cargo run to rebuild the project with
the updated dependencies.
29. Recipe#4: Installing Visual
Studio Code IDE for Rust
Understanding VS Code IDE
Visual Studio Code (VS Code) is a free and open-source code
editor developed by Microsoft. It is a powerful and feature-
rich code editor that is widely used by developers to write and
debug code. It is available for Windows, Linux, and macOS.
VS Code includes a built-in terminal, code debugging,
integrated Git support, code snippets, and a wide range of
extensions to add additional functionality. It supports many
programming languages and has a syntax highlighting feature
that helps to make code easier to read. It is also highly
customizable, so you can customize the interface and change
settings to suit your workflow.
Benefits of VS Code IDE for Rust Users
There are several benefits of using Visual Studio Code (VS
Code) as an Integrated Development Environment (IDE) for
Rust programming:
Syntax highlighting: VS Code has excellent support
for Rust syntax highlighting, which makes it easy to
read and write Rust code.
Debugging: VS Code has a built-in debugger that
allows you to set breakpoints, inspect variables, and
step through code.
Code completion: VS Code has IntelliSense, a
feature that provides code completion suggestions
as you type. This can save you time and improve
your productivity.
Formatting: VS Code has an automatic code
formatting feature that helps to keep your code
30. organized and easy to read.
Git integration: VS Code has built-in support for
Git, allowing you to easily manage your version
control from within the editor.
Extension ecosystem: VS Code has a large
ecosystem of extensions that can add additional
functionality to the editor. There are extensions
available for Rust that provide additional features
such as code snippets, linting, and integration with
popular Rust tools.
Overall, VS Code is a feature-rich and powerful IDE that is
well-suited for Rust development.
Why VS Code IDE for Rust?
Visual Studio Code (VS Code) is a popular cross-platform
code editor that includes support for Rust development. Some
benefits of using VS Code for Rust include:
Syntax highlighting: VS Code includes syntax highlighting for
Rust code, which can make it easier to read and write code by
highlighting different elements such as keywords, variables,
and functions.
Code completion: VS Code includes code completion for Rust,
which can help you write code faster by suggesting possible
completions as you type.
Debugging: VS Code includes debugging support for Rust,
which allows you to set breakpoints, inspect variables, and
step through code to help identify and fix issues.
Integrated terminal: VS Code includes an integrated terminal
that allows you to run cargo and other command-line tools
directly from the editor.
Extension marketplace: VS Code has a large extension
marketplace that includes a number of extensions specifically
designed for Rust development, such as Rust Analyzer and
Rust symbol completion.
31. Overall, VS Code is a powerful and user-friendly IDE that can
make Rust development more efficient and enjoyable.
Steps to Install VS Code
To install Visual Studio Code (VS Code) for Rust
development, you can follow these steps:
Go to the Visual Studio Code website
(https://code.visualstudio.com/).
Click the “Download” button to download the VS
Code installer for your operating system (Windows,
macOS, or Linux).
Once the download is complete, open the installer
file.
Follow the prompts to install VS Code. This may
include accepting a license agreement and choosing
an installation location.
Once the installation is complete, open VS Code.
To install the Rust extension for VS Code, click the
“Extensions” icon in the left-hand side menu, or
press Ctrl+Shift+X (Windows) or Cmd+Shift+X
(macOS).
In the search bar at the top of the extensions
window, search for “Rust”.
Click the “Install” button for the “Rust (rls)”
extension.
Once the extension is installed, you may be
prompted to install the Rust compiler and tools. If
so, follow the prompts to install Rust.
To verify that the Rust extension is installed and
working correctly, you can create a new Rust file
(e.g. main.rs) and write some Rust code. The syntax
highlighting and code completion should work as
expected.
32. That’s it! You should now have Visual Studio Code installed
and configured for Rust development. You can use it to edit
and debug your Rust code, and use the integrated terminal to
run cargo and other command-line tools.
33. Recipe#5: Supporting Non-Rust
Tools and Libraries
List of Non-Rust Libraries and Packages
There are many non-Rust libraries and packages that support
Rust development. Here is a list of some popular ones:
Reqwest: A Rust library for making HTTP requests.
Serde: A Rust library for serializing and
deserializing data.
Tokiio: A Rust library for building asynchronous
applications.
Clap: A Rust library for parsing command-line
arguments.
NumPy: A Python library for scientific computing
that includes support for Rust through the pyo3
crate.
PostgreSQL: A database management system that
includes support for Rust through the postgres
crate.
GTK: A GUI toolkit that includes support for Rust
through the gtk crate.
OpenCV: A computer vision library that includes
support for Rust through the opencv crate.
Diesel: A Rust library for interacting with
databases.
Hyper: A Rust library for writing HTTP clients and
servers.
Rustls: A Rust library for TLS (Transport Layer
Security).
34. RabbitMQ: A message broker that includes support
for Rust through the amqp crate.
Protobuf: A serialization library that includes
support for Rust through the prost crate.
FFmpeg: A multimedia framework that includes
support for Rust through the av crate.
LLVM: A compiler infrastructure that includes
support for Rust through the llvm-sys crate.
OpenGL: A graphics library that includes support
for Rust through the glium crate.
These libraries and packages can be used to add various
functionality to your Rust projects, such as networking,
database access, GUI development, and multimedia
processing. They can be included as dependencies in your
Cargo.toml file and imported in your Rust code to make use of
their functionality.
Step-By-Step to Load and Implement Non-
Rust Libraries
To load and implement non-Rust libraries into a Rust project,
you can follow these steps:
Determine the name and version of the library you
want to use. This information should be available in
the library’s documentation.
Open the Cargo.toml file in your Rust project
directory. This file specifies the dependencies and
build configuration for your project.
Under the [dependencies] section, add a line for the
library you want to use. The line should specify the
name of the library and the version you want to use,
separated by an = sign. For example:
[dependencies]
35. reqwest = “0.10.8”
Save the Cargo.toml file.
In your Rust code, add an extern crate declaration
for the library at the top of the file where you want
to use it. For example:
extern crate reqwest;
Use the use keyword to import the necessary items
from the library. For example:
use reqwest::Client;
You can now use the library in your Rust code by
calling functions or methods from the imported
items.
Run the cargo build command to build your project.
This will cause cargo to download and install the
specified dependency, and then build your project
using the dependency.
If you encounter any errors while building or using the library,
you may need to consult the library’s documentation or seek
assistance from the library’s authors or community.
If you want to update or remove the dependency, you can edit
the Cargo.toml file accordingly and run the cargo build
command again to update the dependency in your project.
36. Recipe#6: Setting Up Code
Testing Tools
List of Various Code Testing Tools
Code testing tools are used to verify that code is working
correctly and meets certain requirements or expectations. They
are needed because they help ensure that code is reliable and
of high quality, and can help catch bugs and other issues
before they become problems in production.
In Rust, there are several popular code testing tools available:
cargo test: This is a built-in command in the cargo
build tool that allows you to run tests for your Rust
project. Tests are specified in special test files in the
tests directory of your project, and can be run using
the cargo test command.
assert_eq!: This is a macro in the Rust standard
library that allows you to assert that two values are
equal. It can be used in test functions to verify that
the output of a function or expression is as
expected.
assert!: This is a macro in the Rust standard library
that allows you to assert that a boolean expression
is true. It can be used in test functions to verify that
certain conditions are met.
quickcheck: This is a Rust library that provides
support for automated property-based testing. It
allows you to specify properties that should hold for
a piece of code, and then generates random inputs
to test those properties.
proptest: This is a Rust library that provides
advanced support for property-based testing. It
allows you to specify complex properties and
37. constraints, and provides a range of features for
debugging and minimizing failing test cases.
These are just a few examples of the code testing tools
available in Rust. There are many more available, each with
their own strengths and features. You can choose the testing
tools that best fit your needs and workflow.
Install and Configure Code Testing Tools
To install and configure code testing tools in a Rust project,
you can follow these steps:
Make sure you have the cargo build tool installed
on your system. If you don’t have it installed, you
can install it by following the instructions at
https://www.rust-lang.org/tools/install.
Create a new Rust project or open an existing one.
To add the assert_eq! and assert! macros to your
project, you will need to include the std crate in
your code. You can do this by adding an extern
crate std declaration at the top of the file where you
want to use the macros.
To use the assert_eq! macro, you can call it with
two arguments: the expected value and the actual
value. For example:
assert_eq!(2 + 2, 4);
To use the assert! macro, you can call it with a
boolean expression as an argument. For example:
assert!(2 + 2 == 4);
To add the quickcheck library to your project, you
will need to add it as a dependency in your
Cargo.toml file. You can do this by adding a line
under the [dependencies] section like this:
38. quickcheck = “0.10.0”
To use quickcheck, you will need to include it in
your code by adding an extern crate quickcheck
declaration at the top of the file where you want to
use it.
To write a property-based test using quickcheck,
you will need to define a function with the #
[quickcheck] attribute and specify the inputs and
output as function arguments. For example:
#[quickcheck]
fn sum_is_greater_than_its_parts(x: i32, y: i32) ->
bool {
x + y > x && x + y > y
}
To add the proptest library to your project, you will
need to add it as a dependency in your Cargo.toml
file. You can do this by adding a line under the
[dependencies] section like this:
proptest = “0.10.0”
To use proptest, you will need to include it in your
code by adding an extern crate proptest declaration
at the top of the file where you want to use it.
To write a property-based test using proptest, you
will need to define a function with the #[proptest]
attribute and specify the inputs and output as
function arguments. You can use the proptest!
macro to specify the test case and any constraints or
configuration options. For example:
39. #[proptest]
fn sum_is_greater_than_its_parts(x: i32, y: i32) ->
prop::TestResult {
prop::proptest!(|(x, y)| {
assert!(x + y > x && x + y > y);
})
}
To run your tests, you can use the cargo test
command. This will build your project and run all
of the tests in the tests directory. You can also
specify the name of a specific test function to run
just that test.
That’s it! You should now have code testing tools installed and
configured in your Rust project. You can use these tools to
write and run tests for your code, and verify that it is working
correctly and meeting your requirements.
40. Recipe#7: Installing and
Configuring Cargo
What is Cargo?
Cargo is Rust’s build system and package manager. with this
tool, you’ll get a repeatable build because it allows Rust
packages to declare their dependencies in the manifest,
Cargo.toml. When you install Rust through rustup, Cargo is
also installed.
Cargo allows Rust packages to declare their dependencies.
This is done in the Cargo.toml file. All you have to do is
declare the dependencies required to run your program in the
Cargo.toml file. Next, Cargo extracts all the necessary
information about your dependencies and build information
into the Cargo.lock file.
The function of the Cargo.lock file is to allow for a repeatable
build. Therefore, there should be no cases of different builds,
even when you share your project.
You may be wondering how the Cargo.toml and Cargo.lock
files are different. Cargo.toml is a manifest, which is a
document that contains detailed information about passengers,
goods, etc. In Rust, the manifest contains detailed information
about a given project, such as the project name, version,
dependencies, etc. The manifest tells Cargo which dependency
it needs to download to compile your project successfully.
Install Cargo Package Manager
To install Cargo, the official build and package manager for
Rust, you can follow these steps:
Make sure you have Rust installed on your system.
You can check if Rust is already installed by
running the rustc —version command. If Rust is not
installed, you can install it by following the
41. instructions at https://www.rust-
lang.org/tools/install.
Cargo is distributed with Rust, so you don’t need to
install it separately. However, you may need to
update it to the latest version if it is out of date. To
update Cargo, run the following command:
cargo install cargo-update
Once Cargo is updated, you can use it to manage
your Rust projects. To create a new Rust project
with Cargo, run the following command:
cargo new myproject
This will create a new directory called myproject
with the basic files and directories needed for a
Rust project, including a Cargo.toml file that
specifies the dependencies and build configuration
for the project.
To build and run your project, you can use the cargo
build and cargo run commands, respectively. For
example:
cargo build
cargo run
You can also use Cargo to manage dependencies, run tests, and
perform other tasks related to your Rust project. for more
information, you can refer to the Cargo documentation at
https://doc.rust-lang.org/cargo/.
Step-By-Step Configuring Cargo
To configure Cargo, the official build and package manager
for Rust, you can follow these steps:
42. Make sure you have Cargo installed on your
system. You can check if Cargo is already installed
by running the cargo —version command. If Cargo
is not installed, you can install it by following the
instructions at https://www.rust-
lang.org/tools/install.
To configure Cargo, you will need to edit the
Cargo.toml file in your Rust project directory. This
file specifies the dependencies and build
configuration for your project.
The Cargo.toml file has several sections that you
can use to configure your project. Some of the most
important ones are:
[package]: This section specifies metadata about your project,
such as the name, version, and authors.
[dependencies]: This section specifies the dependencies for
your project. You can add dependencies by specifying the
name and version of the crate, like this:
[dependencies]
reqwest = “0.10.8”
[dev-dependencies]: This section specifies dependencies that
are only needed for development and testing, but not for
production.
[build-dependencies]: This section specifies dependencies that
are needed for building your project, but not for running it.
[features]: This section allows you to enable or disable
optional features of your project.
Once you have edited the Cargo.toml file to specify
the desired configuration for your project, you can
use the cargo build command to build your project
with the new configuration.
43. You can also use the cargo check command to
check your project for errors and warnings without
building it, or the cargo run command to build and
run your project.
45. There are a number of essential concepts and features that are
important to know when coding in Rust. Some of the most
important ones include:
Ownership and borrowing: Rust has a unique
ownership and borrowing system that allows you to
specify which parts of your code have access to
which data. This helps ensure that data is used
safely and efficiently, and can help prevent common
programming errors such as null or dangling pointer
references.
Traits: Traits are a way to define generic behavior
in Rust. They allow you to specify a set of methods
that a type must implement, and can be used to
abstract over different types in a flexible and
reusable way.
Enums: Enums (enumerations) are a way to define
a type that can have a fixed set of values. They can
be used to represent a choice between a finite set of
options, and can be used in pattern matching to
perform different actions depending on the value of
an enum.
Structs: Structs are a way to define a custom data
type in Rust. They allow you to group related data
together into a single entity, and can be used to
define complex data structures such as trees or
graphs.
Matching: Matching is a powerful and expressive
way to control the flow of execution in Rust. It
allows you to match a value against a set of patterns
and execute different code depending on which
pattern matches.
Concurrency: Rust has strong support for
concurrent programming, with features such as
threads, channels, and the async/await syntax.
These features allow you to write code that can run
concurrently and communicate with each other,
46. enabling you to take advantage of multiple CPU
cores and write efficient, parallel code.
Unsafe code: Rust has a strong emphasis on safety
and correctness, but sometimes it is necessary to
write code that bypasses the borrow checker and
other safety checks. This is known as “unsafe”
code, and should be used with caution as it can
introduce vulnerabilities and other risks.
Macros: Rust has a powerful macro system that
allows you to define custom code transformations at
compile-time. Macros can be used to generate code,
define custom syntax, or perform other tasks that
would be difficult or impractical to do using regular
Rust code.
Modules: Modules are a way to organize and
encapsulate your code in Rust. They allow you to
divide your code into logical units and control
visibility and access to different parts of your code.
Cargo: Cargo is the official build and package
manager for Rust. It provides a convenient way to
build, test, and publish Rust projects, and is an
essential tool for any Rust developer.
These are just a few examples of the essential concepts and
features that are important to know when coding in Rust.
There are many more to learn and explore, and you will
discover and learn new things as you continue to work with
Rust.
47. Recipe#1: Working with Traits
How to Declare Traits?
In Rust, you can define a trait by using the trait keyword and
specifying the associated types, functions, and other items that
the trait defines. Following is a sample program on how you
might define a trait in Rust:
trait MyTrait {
type Output;
fn do_something(&self) -> Self::Output;
}
In this example, MyTrait is a trait that defines an associated
type Output and a method do_something() that takes a
reference to self and returns a value of type Self::Output. The
Self keyword refers to the type that is implementing the trait,
and the Output associated type refers to the type that is
associated with the implementing type.
To implement a trait for a type, you can use the impl keyword
and specify the type and the trait, like this:
struct MyStruct;
impl MyTrait for MyStruct {
type Output = i32;
fn do_something(&self) -> Self::Output {
42
}
}
48. In this example, we are implementing MyTrait for the
MyStruct type. We specify that the Output associated type is
i32, and we implement the do_something() method to return
the value 42.
Execute a Trait for Struct
To implement a trait for a type in Rust, you can use the impl
keyword and specify the type and the trait, like this:
struct MyStruct;
impl MyTrait for MyStruct {
type Output = i32;
fn do_something(&self) -> Self::Output {
42
}
}
In this example, we are implementing the MyTrait trait for the
MyStruct type. We specify that the Output associated type is
i32, and we implement the do_something() method to return
the value 42.
You can implement a trait for a type as many times as you like,
as long as the trait is fully implemented for that type. You can
also implement a trait for a type multiple times with different
associated types or method implementations, as long as the
different implementations have different generic type
parameters.
Following is a sample program on how you might implement a
trait multiple times for the same type:
struct MyStruct;
impl MyTrait for MyStruct {
49. type Output = i32;
fn do_something(&self) -> Self::Output {
42
}
}
impl MyTrait for MyStruct {
type Output = bool;
fn do_something(&self) -> Self::Output {
true
}
}
In this example, we have implemented MyTrait twice for the
MyStruct type, with different associated types and method
implementations. The first implementation has an Output
associated type of i32 and returns the value 42, while the
second implementation has an Output associated type of bool
and returns the value true.
Implement Different Types of Traits
To implement different types of traits for a type in Rust, you
can use the impl keyword and specify the type and the trait,
like this:
struct MyStruct;
impl MyTrait1 for MyStruct {
type Output = i32;
fn do_something(&self) -> Self::Output {
42
50. }
}
impl MyTrait2 for MyStruct {
fn do_something_else(&self) {
println!(“Doing something else”);
}
}
In this example, we are implementing the MyTrait1 and
MyTrait2 traits for the MyStruct type. The MyTrait1 trait
defines an associated type Output and a method
do_something(), while the MyTrait2 trait defines a method
do_something_else(). We implement these methods for the
MyStruct type as needed.
You can implement as many different types of traits for a type
as you like, as long as the traits are fully implemented for that
type. You can also implement the same trait multiple times for
a type with different associated types or method
implementations, as long as the different implementations
have different generic type parameters.
Following is a sample program on how you might implement
multiple traits for the same type:
struct MyStruct;
impl MyTrait1 for MyStruct {
type Output = i32;
fn do_something(&self) -> Self::Output {
42
}
}
51. impl MyTrait2 for MyStruct {
fn do_something_else(&self) {
println!(“Doing something else”);
}
}
impl MyTrait3 for MyStruct {
fn do_something_else_again(&self) {
println!(“Doing something else again”);
}
}
In this example, we have implemented three different traits for
the MyStruct type: MyTrait1, MyTrait2, and MyTrait3. Each
trait defines a different set of methods and associated types,
and we have implemented these methods and types for the
MyStruct type as needed.
52. Recipe#2: Define Function
Inside Traits
Define Function Inside a Trait
In Rust, you can define functions inside a trait to specify the
behavior that must be implemented by any type that
implements the trait. To write a function inside a trait, you can
use the fn keyword and specify the function signature, like
this:
trait MyTrait {
fn do_something(&self) -> i32;
}
In this example, MyTrait is a trait that defines a function
do_something() that takes a reference to self and returns an i32
value.
Implement Function Within a Trait
To implement a function inside a trait for a type, you can use
the impl keyword and specify the type and the trait, like this:
struct MyStruct;
impl MyTrait for MyStruct {
fn do_something(&self) -> i32 {
42
}
}
53. In this example, we are implementing the do_something()
function for the MyStruct type. We implement the function by
specifying the body of the function, which in this case is a
simple return statement that returns the value 42.
You can define as many functions inside a trait as you like,
and you can implement them for a type as needed. You can
also define generic functions inside a trait, which allow you to
abstract over different types in a flexible and reusable way.
Declare Generic Functions Inside a Trait
Following is a sample program on how you might define a
generic function inside a trait:
trait MyTrait<T> {
fn do_something_with<U>(&self, value: U) -> (T,
U);
}
struct MyStruct<T> {
value: T,
}
impl<T> MyTrait<T> for MyStruct<T> {
fn do_something_with<U>(&self, value: U) -> (T,
U) {
(self.value, value)
}
}
In this example, MyTrait is a trait that defines a generic
function do_something_with() that takes a reference to self
and a value of type U, and returns a tuple of type (T, U), where
T is the type parameter of the trait and U is the type parameter
54. of the function. We implement the trait for the MyStruct type,
which also has a type parameter T, and we specify the body of
the function to return a tuple containing the value of self.value
and the value of value.
56. Deacons
appointed for
serving Tables.
At Troas the
Supper deferred
till Midnight.
Money, which the Believers, having sold their Possessions, gave unto
them, and finding themselves overcharged with that Burthen,
appointed Deacons for that Business, that they might give
themselves continually to Prayer, and to the Ministry of the Word;
not leaving that, to serve Tables. This cannot be
meant of any sacramental Eating, or religious Acts
of Worship; seeing our Adversaries make the
Distributing of that the proper Act of Ministers, not of Deacons: And
yet there can be no Reason alleged, That that breaking of Bread,
which they are said to have continued in, and to have done from
House to House, was other than those Tables which the Apostles
served; but here gave over, as finding themselves overcharged with
it. Now as the Increase of the Disciples did incapacitate the Apostles
any more to manage this; so it would seem their further Increase,
and dispersing in divers Places, hindered the Continuance of that
Practice of having Things in common: But notwithstanding, so far at
least to remember or continue that ancient Community, they did at
certain Times come together, and break Bread together. Hence it is
said, Acts xx. 7. on Paul’s coming to Troas, That
upon the fist Day of the Week, when the Disciples
came together to break Bread, Paul preached unto
them, ready to depart on the Morrow, and continued his Speech
until Midnight. Here is no Mention made of any sacramental Eating;
but only that Paul took Occasion from their being together to preach
unto them. And it seems it was a Supper they intended (not a
Morning-bit of Bread, and Sup of Wine) else it is not very probable
that Paul would from the Morning have preached until Midnight. But
the 11th Verse puts the Matter out of Dispute, which is thus: When
he therefore was come up again, and had broken Bread, and eaten,
and talked a long While, even till Break of Day, so he departed. This
shews, That the breaking of Bread was deferred till that Time; for
these Words [and when he had broken Bread, and eaten] do shew,
That it had a Relation to the breaking of Bread before-mentioned,
and that that was the Time he did it. Secondly, These Words joined
together [and when he had broken Bread, and eaten, and talked]
shew, it was no religious Act of Worship, but only an Eating for
57. They only did eat
for refreshing the
Body.
By some called a
Love-feast.
The Christians
began by Degrees
to depart from the
Primitive Purity.
1 Cor. 11. 17.
Concerning the
Supper of the
Lord (so called)
explained.
bodily Refreshment, for which the Christians used
to meet together some Time; and doing it in God’s
Fear, and Singleness of Heart, doth
notwithstanding difference it from the Eating or Feasting of profane
Persons. And this by some is called a Love-feast, or
a being together, not merely to feed their Bellies,
or for outward Ends; but to take thence Occasion
to eat and drink together, in the Dread and Presence of the Lord, as
his People; which Custom we shall not condemn. But let it be
observed, That in all the Acts there is no other nor further Mention
of this Matter. But if that Ceremony had been some solemn Sacrifice,
as some will have it, or such a special Sacrament as others plead it
to be; it is strange that that History, which in many less Things gives
a particular Account of the Christians Behaviour, should have been
so silent in the Matter: Only we find, That they used sometimes to
meet together to break Bread, and eat. Now as the
early Christians began by Degrees to depart from
that primitive Purity and Simplicity, so did they also
to accumulate superstitious Traditions, and vitiate
the innocent Practices of their Predecessors, by the Intermixing
either of Jewish or Heathenish Rites; and likewise in the Use of this,
Abuses began very early to creep in among Christians, so that it was
needful for the Apostle Paul to reform them, and reprove them for it,
as he doth at large, 1 Cor. xi. from Ver. 17. to the End: Which Place
we shall particularly examine, because our
Adversaries lay the chief Stress of their Matter
upon it; and we shall see whether it will infer any
more than we have above granted. First, Because
they were apt to use that Practice in a superstitious
Mind beyond the true Use of it, so as to make of it
some mystical Supper of the Lord, he tells them, Ver. 20. That their
coming together into one Place, is not to eat the Lord’s Supper; he
saith not, This is not the right Manner to eat; but, This is NOT to eat
the Lord’s Supper; because the Supper of the Lord is spiritual, and a
Mystery. Secondly, He blames them, in that they came together for
the Worse, and not for the Better; the Reason he gives of this is, Ver.
58. Why the Custom
of Supping in
common was
used among
Christians.
The Rise of that
Custom.
21. For in Eating every one hath taken before his own Supper; and
one is hungry, and another is drunken. Here it is
plain that the Apostle condemns them in that
(because this Custom of Supping in General was
used among Christians to increase their Love, and
as a Memorial of Christ’s Supping with the
Disciples) they had so vitiated it, as to eat it apart, and to come full,
who had Abundance; and hungry, who had little at Home; whereby
the very Use and End of this Practice was lost and perverted: And
therefore he blames them, that they did not either eat this in
Common at Home, or reserve their Eating till they came all together
to the publick Assembly. This appears plainly by the following Ver.
22. Have ye not Houses to eat and drink in? Or despise ye the
Church of God, and shame them that have not? Where he blames
them for their irregular Practice herein, in that they despised to eat
orderly, or reserve their Eating to the publick Assembly; and so
shaming such, as not having Houses, nor Fulness at Home, came to
partake of the common Table; who, being hungry, thereby were
shamed, when they observed others come thither full and drunken.
Those that without Prejudice will look to the Place, will see this must
have been the Case among the Corinthians: For supposing the Use
of this to have been then, as now used either by Papists, Lutherans,
or Calvinists, it is hard making Sense of the Apostle’s Words, or
indeed to conceive what was the Abuse the Corinthians committed in
this Thing. Having thus observed what the Apostle said above,
because this Custom of Eating and Drinking
together some Time had its Rise from Christ’s Act
with the Apostles the Night he was betrayed;
therefore the Apostle proceeds, Ver. 23. to give them an Account of
that: For I have received of the Lord that which also I delivered unto
you, that the Lord Jesus, the same Night in which he was betrayed,
took Bread, &c. Those that understand the Difference betwixt a
Narration of a Thing, and a Command, cannot but see, if they will,
That there is no Command in this Place, but only an Account of
Matter of Fact; he saith not, I received of the Lord, that as he took
Bread, so I should command it to you to do so likewise; there is
59. That [As often]
imports no
Command of this
Supper.
Object.
Answ.
Christ’s outward
and inward
Coming.
To remember
Christ’s Death till
he come to arise
in the Heart.
nothing like this in the Place: Yea, on the contrary, Ver. 25. where he
repeats Christ’s imperative Words to his Apostles, he placeth them so
as they import no Command; This do ye, as oft as ye drink it, in
Remembrance of me: And then he adds, For as often as ye eat this
Bread, and drink this Cup, ye do shew the Lord’s Death till he come:
But these Words [As often] import no more a
Command, than to say, As often as thou goest to
Rome, see the Capitol, will infer a Command to me
to go thither.
But whereas they urge the last Words, Ye shew
forth the Lord’s Death till he come; insinuating,
That this imports a necessary Continuance of that Ceremony, until
Christ come at the End of the World to Judgment;
I answer, They take two of the chief Parts of the
Controversy here for granted, without Proof. First,
That [as often] imports a Command; the contrary whereof is shewn;
neither will they ever be able to prove it. Secondly,
That this Coming is to be understood of Christ’s
last outward Coming, and not of his inward and
spiritual, that remains to be proved: Whereas the Apostle might well
understand it of his inward Coming and Appearance, which perhaps
some of those carnal Corinthians, that used to come drunken
together, had not yet known; and others, being weak among them,
and inclinable to dote upon Externals, this might have been indulged
to them for a Season, and even used by them who knew Christ’s
Appearance in Spirit (as other Things were, of which we shall speak
hereafter) especially by the Apostle, who became weak to the Weak,
and all to All, that he might save some. Now those
weak and carnal Corinthians might be permitted
the Use of this, to shew forth, or remember Christ’s
Death, till he came to arise in them; for though
such need those outward Things to put them in Mind of Christ’s
Death, yet those who are dead with Christ, and not only dead with
Christ, but buried, and also arisen with him, need not such Signs to
remember him: And to such therefore the Apostle saith, Col. iii. 1. If
60. To abstain from
Things strangled.
The Anointing
with Oil.
Object.
Answ.
ye then be risen with Christ, seek those Things which are above,
where Christ sitteth on the right Hand of God: But Bread and Wine
are not those Things that are above, but are Things of the Earth. But
that this whole Matter was a mere Act of Indulgence and
Condescension of the Apostle Paul to the weak and carnal
Corinthians, appears yet more by the Syriack[133] Copy, which Ver.
17. in his entering upon this Matter, hath it thus; In that concerning
which I am about to command you (or instruct you) I commend you
not, because ye have not gone forward, but are descended unto that
which is less, or of less Consequence: Clearly importing, That the
Apostle was grieved that such was their Condition, that he was
forced to give them Instructions concerning those outward Things;
and doting upon which, they shewed they were not gone forward in
the Life of Christianity, but rather sticking in beggarly Elements. And
therefore Ver. 20. the same Version hath it thus, When then ye meet
together, ye do not do it, as it is just ye should do in the Day of the
Lord, ye eat and drink it: Therefore shewing to them, That to meet
together to eat and drink outward Bread and Wine, was not the
Labour and Work of that Day of the Lord. But since our Adversaries
are so zealous for this Ceremony, because used by the Church of
Corinth (though with how little Ground is already shewn) how come
they to pass over far more positive Commands of the Apostles, as
Matters of no Moment? As First, Acts xv. 29. where the Apostles
peremptorily command the Gentiles, as that which
was the Mind of the Holy Ghost, To abstain from
Things strangled, and from Blood: And James v.
14. where it is expresly commanded, That the Sick
be anointed with Oil in the Name of the Lord.
[133] And likewise the other Oriental Versions, as the Arabick and
Æthiopick, have it the same Way.
If they say, Those were only temporary Things, but
not to continue;
What have they more to shew for this; there being
no express Repeal of them?
61. Object.
Answ.
Object.
Answ.
A Ceremony
ought to cease,
its Virtue failing.
Thus laying on of
Hands.
The Ceremony of
Bread and Wine is
ceased.
If they say, The Repeal is implied, because the
Apostle saith, We ought not to be judged in Meats
and Drinks;
I admit the Answer: But how can it be prevented
from militating the same Way against the other
Practice? Surely not at all: Nor can there be any Thing urged for the
one more than for the other, but Custom and Tradition.
As for that of James, they say, There followed a
Miracle upon it, to wit, The Recovery of the Sick;
but this being ceased, so should the Ceremony.
Though this might many Ways be answered, to wit,
That Prayer then might as well be forborn, to which
also the Saving of the Sick is there ascribed; yet I shall accept of it,
because I judge indeed that Ceremony is ceased;
only methinks, since our Adversaries, and that
rightly, think a Ceremony ought to cease where the
Virtue fails, they ought by the same Rule to forbear the laying on of
Hands, in Imitation of the Apostles, since the Gift
of the Holy Ghost doth not follow upon it.
§. IX. But since we find that several Testimonies of Scripture do
sufficiently shew, That such external Rites are no necessary Part of
the New Covenant Dispensation, therefore not needful now to
continue, however they were for a Season practised of old, I shall
instance some few of them, whereby from the Nature of the Thing,
as well as those Testimonies, it may appear, That the Ceremony of
Bread and Wine is ceased, as well as those other Things confessed
by our Adversaries to be so. The first is Rom. xiv.
17. For the Kingdom of God is not Meat and Drink,
but Righteousness and Peace, and Joy in the Holy
Ghost: Here the Apostle evidently shews, That the Kingdom of God,
or Gospel of Christ, stands not in Meats and Drinks, and such like
Things, but in Righteousness, &c. as by the Context doth appear,
where he is speaking of the Guilt and Hazard of judging one another
about Meats and Drinks. So then, if the Kingdom of God stand not in
62. ’Tis but a Sign
and Shadow they
confess.
And which do
perish with the
Using.
them, nor the Gospel, nor Work of Christ, then the eating of outward
Bread and Wine can be no necessary Part of the Gospel-worship, nor
any perpetual Ordinance of it. Another of the same Apostle is yet
more plain, Col. ii. 16. the Apostle throughout this whole second
Chapter doth clearly plead for us, and against the Formality and
Superstition of our Opposers: For in the Beginning he holds forth the
great Privileges which Christians have by Christ, who are indeed
come to the Life of Christianity; and therefore he desires them, Ver.
6. As they have received Christ, so to walk in him; and to beware,
lest they be spoiled through Philosophy and vain Deceit, after the
Rudiments or Elements of the World; because that in Christ, whom
they have received, is all Fulness: And that they are circumcised with
the Circumcision made without Hands (which he calls the
Circumcision of Christ) and being buried with him by Baptism, are
also arisen with him through the Faith of the Operation of God. Here
also they did partake of the true Baptism of Christ; and being such
as are arisen with him, let us see whether he thinks it needful they
should make use of such Meat and Drink as Bread and Wine, to put
them in Remembrance of Christ’s Death; or whether they ought to
be judged, that they did it not; Ver. 16. Let no Man therefore judge
you in Meat and Drink: Is not Bread and Wine Meat and Drink? But
why? Which are a Shadow of Things to come: But the Body is of
Christ. Then since our Adversaries confess, That
their Bread and Wine is a Sign or Shadow;
therefore, according to the Apostle’s Doctrine, we
ought not to be judged in the Non-observation of it. But is it not fit
for those that are dead with Christ to be subject to such Ordinances?
See what he saith, Ver. 20. Wherefore if ye be dead
with Christ from the Rudiments of the World, why,
as though living in the World, are ye subject to
Ordinances? (Touch not, taste not, handle not: Which all are to
perish with the Using) after the Commandments and Doctrines of
Men. What can be more plain? If this serve not to take away the
absolute Necessity of the Use of Bread and Wine, what can it serve
to take away? Sure I am, the Reason here given is applicable to
them, which all do perish with the Using; since Bread and Wine
63. The Law was
Meats and Drinks;
not so the Gospel.
Object.
Answ.
The Law has
Shadows, the
Gospel brings the
Substance.
Their Sacraments
confer not Grace.
perish with the Using, as much as other Things. But further, If the
Use of Water, and Bread and Wine, were that wherein the very Seals
of the New Covenant stood, and did pertain to the chief Sacraments
of the Gospel and Evangelical Ordinances (so called) then would not
the Gospel differ from the Law, or be preferable to it. Whereas the
Apostle shews the Difference, Heb. ix. 10. in that
such Kind of Observations of the Jews were as a
Sign of the Gospel, for that they stood only in
Meats and Drinks, and divers Washings. But if the Gospel-worship
and Service stand in the same, where is the Difference?
If it be said, These under the Gospel have a
spiritual Signification;
So had those under the Law; God was the Author
of those, as well as Christ is pretended to be the
Author of these. But doth not this contending for the Use of Water,
Bread and Wine, as necessary Parts of the Gospel-worship, destroy
the Nature of it, as if the Gospel were a Dispensation of Shadows,
and not of the Substance? Whereas the Apostle, in
that of the Colossians above-mentioned, argues
against the Use of these Things, as needful to
those that are dead and arisen with Christ, because
they are but Shadows. And since, through the whole Epistle to the
Hebrews, he argues with the Jews, to wean them from their old
Worship, for this Reason, because it was typical and figurative; is it
agreeable to right Reason to bring them to another of the same
Nature? What Ground from Scripture or Reason can our Adversaries
bring us, to evince that one Shadow or Figure should point to
another Shadow or Figure, and not to the Substance? And yet they
make the Figure of Circumcision to point to Water-baptism, and the
Paschal Lamb to Bread and Wine. But was it ever known that one
Figure was the Anti-type of the other, especially seeing Protestants
make not these their Anti-types to have any more Virtue and Efficacy
than the Type had? For since, as they say, and that
truly, That their Sacraments confer not Grace, but
that it is conferred according to the Faith of the
64. Opposers claim a
Power to give
their Sacraments;
from whence do
they derive it?
Tradition no
sufficient Ground
for Faith.
The Supper they
gave to young
Receiver, it will not be denied but the Faithful among the Jews
received also Grace in the Use of their Figurative Worship. And
though Papists boast that their Sacraments confer Grace ex opere
operato, yet Experience abundantly proveth the contrary.
§. X. But supposing the Use of Water-baptism
and Bread and Wine to have been in the Primitive
Church, as was also that of abstaining from Things
strangled, and from Blood, the Use of Legal
Purification, Acts xxi. 23, 24, 25. and anointing of the Sick with Oil,
for the Reasons and Grounds before mentioned; yet it remains for
our Adversaries to shew us how they come by Power or Authority to
administer them. It cannot be from the Letter of the Scripture, else
they ought also to do those other Things, which the Letter declares
also they did, and which in the Letter have as much Foundation.
Then their Power must be derived from the Apostles, either
mediately or immediately; but we have shewn before, in the tenth
Proposition, that they have no mediate Power, because of the
Interruption made by the Apostasy; and for an immediate Power or
Command by the Spirit of God to administer these Things, none of
our Adversaries pretend to it. We know that in this, as in other
Things, they make a Noise of the constant Consent of the Church,
and of Christians in all Ages; but as Tradition is not
a sufficient Ground for Faith, so in this Matter
especially it ought to have but small Weight; for
that in this Point of Ceremonies and superstitious Observations the
Apostasy began very early, as may appear in the Epistle of Paul to
the Galatians and Colossians; and we have no Ground to imitate
them in those Things, whose Entrance the Apostle so much
withstood, so heavily regretted, and so sharply reproved. But if we
look to Antiquity, we find that in such Kind of Observances and
Traditions they were very uncertain and changeable; so that neither
Protestants nor Papists do observe this Ceremony as they did, both
in that they gave it to young Boys, and to little Children: And for
aught can be learned, the Use of this and Infant-
baptism are of a like Age, though the one be laid
65. Boys and
Children.
Dallæus.
Calvin’s ingenuous
Confession
commended.
aside both by Papists and Protestants, and the
other, to wit, Baptism of Infants, be stuck to. And
we have so much the less Reason to lay Weight upon Antiquity, for
that if we consider their Profession of Religion, especially as to
Worship, and the ceremonial Part of it, we shall not find any Church
now, whether Popish or Protestant, who differ not widely from them
in many Things, as Dallæus, in his Treatise
concerning the Use of the Fathers, well observeth
and demonstrateth. And why they should obtrude this upon us
because of the Ancients Practice, which they themselves follow not,
or why we may not reject this, as well as they do other Things no
less zealously practised by the Ancients, no sufficient Reason can be
assigned.
Nevertheless I doubt not but many, whose Understandings have
been clouded with these Ceremonies, have notwithstanding, by the
Mercy of God, had some secret Sense of the Mystery, which they
could not clearly understand, because it was sealed from them by
their sticking to such outward Things; and that through that secret
Sense diving in their Comprehensions they ran themselves into these
carnal Apprehensions, as imagining the Substance of the Bread was
changed, or that if the Substance was not changed, yet the Body
was there, &c. And indeed I am inclinable very
favourably to judge of Calvin in this Particular, in
that he deals so ingenuously to confess he neither
comprehends it, nor can express it in Words; but yet by a feeling
Experience can say, The Lord is spiritually present. Now as I doubt
not but Calvin sometimes had a Sense of his Presence without the
Use of this Ceremony, so as the Understanding given him of God
made him justly reject the false Notions of Transubstantiation and
Consubstantiation, though he knew not what to establish instead of
them, if he had fully waited in the [134]Light that makes all Things
manifest, and had not laboured in his own Comprehension to settle
upon that external Ceremony, by affixing the spiritual Presence as
chiefly or principally, though not only, as he well knew by
Experience, there, or especially to relate to it, he might have further
66. In Tenderness of
Conscience, God
winketh at our
Ignorance.
The Day is
dawned wherein
God is risen, and
worshipped in
Spirit.
reached unto the Knowledge of this Mystery than many that went
before him.
[134] Ephes. 5. 13.
§. XI. Lastly, If any now at this Day, from a true
Tenderness of Spirit, and with real Conscience
towards God, did practise this Ceremony in the
same Way, Method, and Manner as did the
Primitive Christians recorded in Scripture, I should not doubt to
affirm but they might be indulged in it, and the Lord might regard
them, and for a Season appear to them in the Use of these Things,
as many of us have known him to do to us in the Time of our
Ignorance; provided always they did not seek to obtrude them upon
others, nor judge such as found themselves delivered from them, or
that they do not pertinaciously adhere to them. For
we certainly know that the Day is dawned, in which
God hath arisen, and hath dismissed all those
Ceremonies and Rites, and is only to be
worshipped in Spirit, and that he appears to them
who wait upon him; and that to seek God in these Things is, with
Mary at the Sepulchre, to seek the Living among the Dead: For we
know that he is risen, and revealed in Spirit, leading his Children out
of these Rudiments, that they may walk with him in his Light: To
whom be Glory for ever. Amen.
68. What Conscience
is.
PROPOSITION XIV.
Concerning the Power of the Civil Magistrate in Matters purely
Religious, and pertaining to the Conscience.
[135]Since God hath assumed to himself the Power and Dominion of
the Conscience, who alone can rightly instruct and govern it,
therefore it is not lawful for any whosoever, by Virtue of any
Authority or Principality they bear in the Government of this
World, to force the Consciences of others; and therefore all
Killing, Banishing, Fining, Imprisoning, and other such Things
which are inflicted upon Men for the alone Exercise of their
Conscience, or Difference in Worship or Opinion, proceedeth
from the Spirit of Cain the Murderer, and is contrary to the
Truth; providing always, that no Man, under the Pretence of
Conscience, prejudice his Neighbour in his Life or Estate, or do
any Thing destructive to, or inconsistent with, Human Society;
in which Case the Law is for the Transgressor, and Justice is to
be administered upon all, without Respect of Persons.
[135] Luke 9. 55, 56. Matt. 7. 12, 13. 29. Tit. 3. 10.
§. I. Liberty of Conscience from the Power of the Civil Magistrate
hath been of late Years so largely and learnedly handled, that I shall
need to be but brief in it; yet it is to be lamented that few have
walked answerably to this Principle, each pleading it for themselves,
but scarce allowing it to others, as hereafter I shall have Occasion
more at length to observe.
It will be fit in the first Place, for clearing of Mistakes, to say
something of the State of the Controversy, that what follows may be
the more clearly understood.
By Conscience then, as in the Explanation of the
fifth and sixth Propositions I have observed, is to
69. be understood, That Persuasion of the Mind which arises from the
Understanding’s being possessed with the Belief of the Truth or
Falsity of any Thing; which though it may be false or evil upon the
Matter, yet if a Man should go against his Persuasion or Conscience,
he would commit a Sin; because what a Man doth contrary to his
Faith, though his Faith be wrong, is no Ways acceptable to God.
Hence the Apostle saith, [136]Whatsoever is not of Faith, is Sin; and
he that doubteth is damned if he eat; though the Thing might have
been lawful to another; and that this Doubting to eat some Kind of
Meats (since all the Creatures of God are good, and for the Use of
Man, if received with Thanksgiving) might be a Superstition, or at
least a Weakness, which were better removed. Hence Ames. de Cas.
Cons. saith, The Conscience, although erring, doth evermore bind,
so as that he sinneth who doth contrary to his Conscience,[137]
because he doth contrary to the Will of God, although not materially
and truly, yet formally and interpretatively.
[136] Rom. 14. 23.
[137] i. e. As he supposeth.
So the Question is First, Whether the Civil Magistrate hath Power to
force Men in Things religious to do contrary to their Conscience; and
if they will not, to punish them in their Goods, Liberties, and Lives?
This we hold in the Negative. But Secondly, As we would have the
Magistrate to avoid this Extreme of incroaching upon Men’s
Consciences, so on the other Hand we are far from joining with or
strengthening such Libertines as would stretch the Liberty of their
Consciences to the Prejudice of their Neighbours, or to the Ruin of
Human Society. We understand therefore by Matters of Conscience
such as immediately relate betwixt God and Man, or Men and Men,
that are under the same Persuasion, as to meet together and
worship God in that Way which they judge is most acceptable unto
him, and not to incroach upon, or seek to force their Neighbours,
otherwise than by Reason, or such other Means as Christ and his
Apostles used, viz. Preaching and instructing such as will hear and
receive it; but not at all for Men, under the Notion of Conscience, to
70. do any Thing contrary to the moral and perpetual Statutes generally
acknowledged by all Christians; in which Case the Magistrate may
very lawfully use his Authority; as on those, who, under a Pretence
of Conscience, make it a Principle to kill and destroy all the Wicked,
id est, all that differ from them, that they, to wit, the Saints, may
rule, and who therefore seek to make all Things common, and would
force their Neighbours to share their Estates with them, and many
such wild Notions, as is reported of the Anabaptists of Munster;
which evidently appears to proceed from Pride and Covetousness,
and not from Purity or Conscience; and therefore I have sufficiently
guarded against that in the latter Part of the Proposition. But the
Liberty we lay claim to is such as the Primitive Church justly fought
under the Heathen Emperors, to wit, for Men of Sobriety, Honesty,
and a peaceable Conversation, to enjoy the Liberty and Exercise of
their Conscience towards God and among themselves, and to admit
among them such as by their Persuasion and Influence come to be
convinced of the same Truth with them, without being therefore
molested by the Civil Magistrate. Thirdly, Though we would not have
Men hurt in their Temporals, nor robbed of their Privileges as Men
and Members of the Commonwealth, because of their inward
Persuasion; yet we are far from judging that in the Church of God
there should not be Censures exercised against such as fall into
Error, as well as such as commit open Evils; and therefore we believe
it may be very lawful for a Christian Church, if she find any of her
Members fall into any Error, after due Admonitions and Instructions
according to Gospel Order, if she find them pertinacious, to cut them
off from her Fellowship by the Sword of the Spirit, and deprive them
of those Privileges which they had as Fellow-members; but not to
cut them off from the World by the temporal Sword, or rob them of
their common Privileges as Men, seeing they enjoy not these as
Christians, or under such a Fellowship, but as Men, and Members of
the Creation. Hence Chrysostom saith well, (de Anath.) We must
condemn and reprove the evil Doctrines that proceed from
Hereticks; but spare the Men, and pray for their Salvation.
§. II. But that no Man, by Virtue of any Power or Principality he
71. Conscience the
Throne of God.
hath in the Government of this World, hath Power over the
Consciences of Men, is apparent, because the
Conscience of Man is the Seat and Throne of God
in him, of which God is the alone proper and
infallible Judge, who by his Power and Spirit can alone rectify the
Mistakes of Conscience, and therefore hath reserved to himself the
Power of punishing the Errors thereof as he seeth meet. Now for the
Magistrate to assume this, is to take upon him to meddle with
Things not within the Compass of his Jurisdiction; for if this were
within the Compass of his Jurisdiction, he should be the proper
Judge in these Things; and also it were needful to him, as an
essential Qualification of his being a Magistrate, to be capable to
judge in them. But that the Magistrate, as a Magistrate, is neither
proper Judge in these Cases, nor yet that the Capacity so to be is
requisite in him as a Magistrate, our Adversaries cannot deny; or
else they must say, That all the Heathen Magistrates were either no
lawful Magistrates, as wanting something essential to Magistracy,
and this were contrary to the express Doctrine of the Apostle, Rom.
xiii. or else (which is more absurd) that those Heathen Magistrates
were proper Judges in Matters of Conscience among Christians. As
for that Evasion that the Magistrate ought to punish according to the
Church Censure and Determination, which is indeed no less than to
make the Magistrate the Church’s Hangman, we shall have Occasion
to speak of it hereafter. But if the chief Members of the Church,
though ordained to inform, instruct, and reprove, are not to have
Dominion over the Faith nor Consciences of the Faithful, as the
Apostle expresly affirms, 2 Cor. i. 24. then far less ought they to
usurp this Dominion, or stir up the Magistrate to persecute and
murder those who cannot yield to them therein.
Secondly, This pretended Power of the Magistrate is both contrary
unto, and inconsistent with the Nature of the Gospel, which is a
Thing altogether extrinsick to the Rule and Government of political
States, as Christ expresly signified, saying, His Kingdom was not of
this World; and if the propagating of the Gospel had had any
necessary Relation thereunto, then Christ had not said so. But he
72. abundantly hath shewn by his Example, whom we are chiefly to
imitate in Matters of that Nature, that it is by Persuasion and the
Power of God, not by Whips, Imprisonments, Banishments, and
Murderings, that the Gospel is to be propagated; and that those that
are the Propagators of it are often to suffer by the Wicked, but never
to cause the Wicked to suffer. When he sends forth his Disciples, he
tells them, he sends them forth as [138]Lambs among Wolves, to be
willing to be devoured, not to devour: He tells them of their being
whipped, imprisoned, and killed for their Conscience; but never that
they shall either whip, imprison, or kill: And indeed if Christians must
be as Lambs, it is not the Nature of Lambs to destroy or devour any.
It serves nothing to allege, that in Christ’s and his Apostles Times
the Magistrates were Heathens, and therefore Christ and his
Apostles, nor yet any of the Believers, being no Magistrates, could
not exercise the Power; because it cannot be denied but Christ,
being the Son of God, had a true Right to all Kingdoms, and was
righteous Heir of the Earth. [139]Next, as to his Power, it cannot be
denied but he could, if he had seen meet, have called for Legions of
Angels to defend him, and have forced the Princes and Potentates of
the Earth to be subject unto him, Matt. xxvi. 53. So that it was only
because it was contrary to the Nature of Christ’s Gospel and Ministry
to use any Force or Violence in the gathering of Souls to him. This
he abundantly expressed in his Reproof to the two Sons of Zebedee,
who would have been calling for Fire from Heaven to burn those that
refused to receive Christ: It is not to be doubted but this was as
great a Crime as now to be in an Error concerning the Faith and
Doctrine of Christ. That there was not Power wanting to have
punished those Refusers of Christ cannot be doubted; for they that
could do other Miracles, might have done this also. And moreover,
they wanted not the Precedent of a holy Man under the Law, as did
Elias; yet we see what Christ saith to them, Ye know not what Spirit
ye are of, Luke ix. 55. For the Son of Man is not come to destroy
Men’s Lives, but to save them. Here Christ shews that such Kind of
Zeal was no Ways approved of him; and such as think to make Way
for Christ or his Gospel by this Means, do not understand what Spirit
73. they are of. But if it was not lawful to call for Fire from Heaven to
destroy such as refuse to receive Christ, it is far less lawful to kindle
Fire upon Earth to destroy those that believe in Christ, because they
will not believe, nor can believe, as the Magistrates do, for
Conscience Sake. And if it was not lawful for the Apostles, who had
so large a Measure of the Spirit, and were so little liable to Mistake,
to force others to their Judgment, it can be far less lawful now for
Men, who as Experience declareth, and many of themselves confess,
are fallible, and often mistaken, to kill and destroy all such as
cannot, because otherwise persuaded in their Minds, judge and
believe in Matters of Conscience just as they do. And if it was not
according to the Wisdom of Christ, who was and is King of Kings, by
outward Force to constrain others to believe him or receive him, as
being a Thing inconsistent with the Nature of his Ministry and
spiritual Government, do not they grosly offend him, who will needs
be wiser than he, and think to force Men against their Persuasion to
conform to their Doctrine and Worship? The Word of the Lord said,
Not by Power and by Might, but by the Spirit of the Lord, Zech. iv. 6.
But these say, Not by the Spirit of the Lord, but by Might and carnal
Power. The Apostle saith plainly, [140]We wrestle not with Flesh and
Blood; and the Weapons of our Warfare are not carnal, but spiritual:
But these Men will needs wrestle with Flesh and Blood, when they
cannot prevail with the Spirit and the Understanding; and not having
spiritual Weapons, go about with carnal Weapons to establish
Christ’s Kingdom, which they can never do: And therefore when the
Matter is well sifted, it is found to be more out of Love to Self, and
from a Principle of Pride in Man to have all others to bow to him,
than from the Love of God. [141]Christ indeed takes another Method;
for he saith, He will make his People a willing People in the Day of
his Power; but these Men labour against Men’s Wills and
Consciences, not by Christ’s Power, but by the outward Sword, to
make Men the People of Christ, which they never can do, as shall
hereafter be shewn.
[138] Matt. 10. 16.
[139] Matt. 28. 18.
74. Object.
Answ.
[140] 2 Cor. 10. 4.
[141] Psal. 110. 3.
But Thirdly, Christ fully and plainly declareth to us his Sense in this
Matter in the Parable of the Tares, Matt. xiii. of which we have
himself the Interpreter, Ver. 38, 39, 40, 41. where he expounds them
to be the Children of the Wicked One, and yet he will not have the
Servants to meddle with them, lest they pull up the Wheat
therewith. Now it cannot be denied but Hereticks are here included;
and although these Servants saw the Tares, and had a certain
Discerning of them; yet Christ would not they should meddle, lest
they should hurt the Wheat: Thereby intimating, That that Capacity
in Man to be mistaken, ought to be a Bridle upon him, to make him
wary in such Matters; and therefore, to prevent this Hurt, he gives a
positive Prohibition, But he said, Nay, Ver. 29. So that they who will
notwithstanding be pulling up that which they judge is Tares, do
openly declare, That they make no Scruple to break the Commands
of Christ. Miserable is that Evasion which some of our Adversaries
use here, in alleging these Tares are meant of Hypocrites, and not of
Hereticks! But how to evince that, seeing Hereticks, as well as
Hypocrites, are Children of the Wicked One, they have not any Thing
but their own bare Affirmation, which is therefore justly rejected.
If they say, Because Hypocrites cannot be
discerned, but so may Hereticks;
This is both false and a begging of the Question.
For those that have a spiritual Discerning, can
discern both Hypocrites and Hereticks; and those that want it,
cannot certainly discern either. Seeing the Question will arise,
Whether that is a Heresy which the Magistrate saith is so? And
seeing it is both possible, and confessed by all to have often fallen
out, that some Magistrates have judged that Heresy which was not,
punishing Men accordingly for Truth, instead of Error; there can be
no Argument drawn from the Obviousness or Evidence of Heresy,
unless we should conclude Heresy could never be mistaken for
Truth, nor Truth for Heresy; whereof Experience shews daily the
75. Object.
Answ.
Object.
Answ.
contrary, even among Christians. But neither is this Shift applicable
to this Place; for the Servants did discern the Tares, and yet were
liable to hurt the Wheat, if they had offered to pull them up.
§. III. But they object against this Liberty of
Conscience, Deut. xiii. 5. Where false Prophets are appointed to be
put to Death; and accordingly they give Example thereof.
The Case no Way holds parallel; those particular
Commands to the Jews, and Practices following
upon them, are not a Rule for Christians; else we might by the same
Rule say, It were lawful for us to borrow of our Neighbours their
Goods, and so carry them away, because the Jews did so by God’s
Command; or that it is lawful for Christians to invade their
Neighbours Kingdoms, and cut them all off without Mercy, because
the Jews did so to the Canaanites, by the Command of God.
If they urge, That these Commands ought to
stand, except they be repealed in the Gospel;
I say, The Precepts and Practices of Christ and his
Apostles mentioned are a sufficient Repeal: For if
we should plead, That every Command given to the Jews is binding
upon us, except there be a particular Repeal; then would it follow,
That because it was lawful for the Jews, if any Man killed one, for
the nearest Kindred presently to kill the Murderer, without any Order
of Law, it were lawful for us to do so likewise. And doth not this
Command of Deut. xiii. 9. openly order him who is enticed by
another to forsake the Lord, though it were his Brother, his Son, his
Daughter, or his Wife, presently to kill him or her? Thou shalt surely
kill him, thy Hand shall be first upon him, to put him to Death. If this
Command were to be followed there needed neither Inquisition nor
Magistrate to do the Business; and yet there is no Reason why they
should shuffle by this Part, and not the other; yea, to argue this Way
from the Practice among the Jews, were to overturn the very Gospel,
and to set up again the carnal Ordinances among the Jews, to pull
down the spiritual Ones of the Gospel. Indeed we can far better
argue from the Analogy betwixt the figurative and carnal State of the
76. Object.
Answ.
Jews, and the real and spiritual One under the Gospel; that as Moses
delivered the Jews out of outward Egypt, by an outward Force, and
established them in an outward Kingdom, by destroying their
outward Enemies for them; so Christ, not by overcoming outwardly,
and killing others, but by suffering and being killed, doth deliver his
chosen ones, the inward Jews, out of mystical Egypt, destroying
their spiritual Enemies before them, and establishing among them
his spiritual Kingdom, which is not of this World. And as such as
departed from the Fellowship of outward Israel were to be cut off by
the outward Sword, so those that depart from the inward Israel are
to be cut off by the Sword of the Spirit: For it answers very well,
That as the Jews were to cut off their Enemies outwardly, in order to
establish their Kingdom and outward Worship, so they were to
uphold it the same Way: But as the Kingdom and Gospel of Christ
was not to be established or propagated by cutting off or destroying
the Gentiles, but by persuading them, so neither is it to be upheld
otherwise.
But Secondly, they urge, Rom. xiii. where the
Magistrate is said, Not to bear the Sword in vain,
because he is the Minister of God, to execute Wrath upon such as do
Evil. But Heresy, say they, is Evil. Ergo.
But so is Hypocrisy also; yet they confess he ought
not to punish that. Therefore this must be
understood of moral Evils, relative to Affairs betwixt Man and Man,
not of Matters of Judgment or Worship; or else what great
Absurdities would follow, considering that Paul wrote here to the
Church of Rome, which was under the Government of Nero, an
impious Heathen, and Persecutor of the Church? Now if a Power to
punish in Point of Heresy be here included, it will necessarily follow,
That Nero had this Power; yea, and that he had it of God; for
because the Power was of God, therefore the Apostle urges their
Obedience. But can there be any Thing more absurd, than to say
that Nero had Power to judge in such Cases? Surely if Christian
Magistrates be not to punish for Hypocrisy, because they cannot
outwardly discern it; far less could Nero punish any Body for Heresy,
77. Object.
Answ.
Object.
Answ.
which he was uncapable to discern. And if Nero had not Power to
judge or punish in Point of Heresy, then nothing can be urged from
this Place; since all that is said here, is spoken as applicable to Nero,
with a particular Relation to whom it was written. And if Nero had
such a Power, surely he was to exercise it according to his Judgment
and Conscience, and in doing thereof he was not to be blamed;
which is enough to justify him in his persecuting of the Apostles, and
murdering the Christians.
Thirdly, They object that Saying of the Apostle to
the Galatians, v. 12. I would they were even cut off
which trouble you.
But how this imports any more than a Cutting off
from the Church, is not, nor can be shewn. Beza
upon the Place saith, We cannot understand that otherwise than of
Excommunication, such as was that of the incestuous Corinthian.
And indeed it is Madness to suppose it otherwise; for Paul would not
have these cut off otherwise than he did Hymenæus and Philetus,
who were Blasphemers; which was by giving them over to Satan,
not by cutting of their Heads.
The same Way may be answered that other Argument, drawn from
Rev. ii. 20. where the Church of Thyatira is reproved for suffering the
Woman Jezabel: Which can be no other Ways understood, than that
they did not excommunicate her, or cut her off by a Church Censure.
For as to Corporal Punishment, it is known that at that Time the
Christians had not Power to punish Hereticks so, if they had had a
Mind to it.
Fourthly, They allege, That Heresies are numbered
among the Works of the Flesh, Gal. v. 20. Ergo, &c.
That Magistrates have Power to punish all the
Works of the Flesh, is denied, and not yet proved.
Every Evil is a Work of the Flesh, but every Evil comes not under the
Magistrate’s Cognizance. Is not Hypocrisy a Work of the Flesh, which
our Adversaries confess the Magistrates ought not to punish? Yea,
78. Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com