Skip to content

Commit becdc0d

Browse files
deadlypants1973lukeedpedrosousa
authored
[Workers] Rust tutorial revision (cloudflare#2309)
* [Workers] Rust tutorial revision * update 500 * Apply suggestions from code review Luke's fix Co-authored-by: Luke Edwards <[email protected]> * dev upate * dev update * Update products/workers/src/content/tutorials/hello-world-rust/index.md * Update products/workers/src/content/tutorials/hello-world-rust/index.md dev correct definition * Apply suggestions from code review Pedro's suggestions Co-authored-by: Pedro Sousa <[email protected]> * Apply suggestions from code review Co-authored-by: Luke Edwards <[email protected]> Co-authored-by: Pedro Sousa <[email protected]>
1 parent 521b0e5 commit becdc0d

File tree

1 file changed

+18
-22
lines changed
  • products/workers/src/content/tutorials/hello-world-rust

1 file changed

+18
-22
lines changed

products/workers/src/content/tutorials/hello-world-rust/index.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,38 @@ import TutorialsBeforeYouStart from "../../_partials/_tutorials-before-you-start
99

1010
# Hello World in Rust
1111

12-
This tutorial will walk you through the steps of generating, building, previewing, configuring, and publishing
13-
a Rust-generated WebAssembly serverless function that parses Markdown for Cloudflare Workers.
12+
In this tutorial, you will learn how to generate, build, preview, configure, and publish a Rust-generated WebAssembly serverless function that parses Markdown for Cloudflare Workers.
1413

1514
<TutorialsBeforeYouStart/>
1615

1716
## Generate
1817

19-
Cloudflare's command-line tool for managing Workers projects, Wrangler, has great support for templates pre-built collections of code that make it easy to get started writing Workers. We'll make use of the [rustwasm-worker template](https://github.com/cloudflare/rustwasm-worker-template/) to start building your project.
18+
Cloudflare's command-line tool for managing Workers projects, [Wrangler](https://github.com/cloudflare/wrangler), supports various templates pre-built collections of code that make it easy to get started writing Workers. You will use the [rustwasm-worker template](https://github.com/cloudflare/rustwasm-worker-template/) to start building your project.
2019

21-
In the command line, generate your Workers project by passing in a project name (we'll use rustwasm-markdown-parser), and the template URL to base your project on.
20+
In the command line, generate your Workers project by passing in a project name and the template URL to base your project on:
2221

2322
```sh
2423
~ $ wrangler generate rustwasm-markdown-parser https://github.com/cloudflare/rustwasm-worker-template/
2524
```
2625

27-
This creates a directory called `rustwasm-markdown-parser` which you can now `cd` into.
26+
This command creates a directory called `rustwasm-markdown-parser` which you can now `cd` into.
2827

29-
Wrangler templates are just Git repositories, so if you want to create your own templates, or use one from our [Template Gallery](/templates), there's a ton of options to help you get started.
28+
Wrangler templates are Git repositories. If you want to create your own templates, or use one from the [Template Gallery](/examples), there is a variety of options to help you get started.
3029

3130
## Workers Playground
3231

33-
You can test how your Workers function will look when it's deployed by using the preview service, which you can access with the `preview` command:
32+
You can test how your Workers function will execute when it is deployed by using the [`dev` command](/cli-wrangler/commands#dev):
3433

3534
```sh
36-
rustwasm-markdown-parser $ wrangler preview --watch
35+
rustwasm-markdown-parser $ wrangler dev
3736
```
3837

39-
Using the `preview` command will open a browser tab with your Cloudflare Workers function loaded in the Cloudflare preview UI.
40-
41-
The `--watch` flag for `preview` tells Wrangler to watch your Worker project for changes and update the preview tab live with the latest URL. Let's leave Wrangler running in `--watch` mode for now as we continue the tutorial.
38+
Using the `dev` command will establish a connection between localhost and an edge server that operates your Worker in development.
4239

4340
## Building
4441

45-
Let's make our Workers function more interesting. We'll pull in a dependency from the `crates.io` ecosystem called `pulldown-cmark`.
46-
We'll add this to our `Cargo.toml`:
42+
Begin building your project by pulling in a dependency from the `crates.io` ecosystem called `pulldown-cmark`.
43+
Add the following content to your `Cargo.toml` file:
4744

4845
```toml
4946
## Cargo.toml
@@ -52,8 +49,7 @@ We'll add this to our `Cargo.toml`:
5249
pulldown-cmark = "0.4.0"
5350
```
5451

55-
Now we'll leverage the code in the `string-to-string` example from the `pulldown-cmark` GitHub repository. Let's change
56-
our `src/lib.rs` to look like this:
52+
Use the code in the `string-to-string` example from the `pulldown-cmark` GitHub repository. Change your `src/lib.rs` to look like this:
5753

5854
```rust
5955
---
@@ -90,15 +86,15 @@ pub fn parse() -> String {
9086
let mut html_output: String = String::with_capacity(markdown_input.len() * 3 / 2);
9187
html::push_html(&mut html_output, parser);
9288

93-
// Check that the output is what we expected.
89+
// Check that the output is what you expected.
9490
let expected_html: &str = "<p>Hello world, this is a <del>complicated</del> <em>very simple</em> example.</p>\n";
9591
assert_eq!(expected_html, &html_output);
9692

9793
format!("\nHTML output:\n{}", &html_output)
9894
}
9995
```
10096

101-
Now we'll update our `worker/worker.js` to use the new code we've written:
97+
Update your `worker/worker.js` to use the new code:
10298

10399
```javascript
104100
addEventListener('fetch', (event) => {
@@ -125,20 +121,20 @@ If `wrangler dev` is running, you will see the output of your Rust program in yo
125121

126122
## Publish
127123

128-
And with that, you're finished writing a Cloudflare Workers function with Rust-generated Wasm!
124+
At this point in the tutorial, you have finished writing a Cloudflare Workers function with Rust-generated Wasm.
129125

130-
Wrangler has built-in support for bundling, uploading, and releasing your Cloudflare Workers application. To do this, we'll run `wrangler publish`, which will _build_ and _publish_ your code:
126+
Wrangler has built-in support for bundling, uploading, and releasing your Cloudflare Workers application. To do this, run `wrangler publish`, which will build and publish your code:
131127

132128
![Publish](./media/publish.gif)
133129

134130
## Resources
135131

136-
In this tutorial, you built and published a Rust-generated WebAssembly serverless function that parses Markdown. If you'd like to see the full source code for this application, you can find it [on GitHub](https://github.com/granjef3/rustwasm-markdown-parser).
132+
In this tutorial, you built and published a Rust-generated WebAssembly serverless function that parses Markdown. If you would like to review the full source code for this application, you can find it [on GitHub](https://github.com/granjef3/rustwasm-markdown-parser).
137133

138-
If you enjoyed this tutorial, we encourage you to explore our other tutorials for building on Cloudflare Workers:
134+
If you enjoyed this tutorial, below you can find other tutorials for building on Cloudflare Workers:
139135

140136
- [Authorize users with Auth0](/tutorials/authorize-users-with-auth0)
141137
- [Build a JAMStack app](/tutorials/build-a-jamstack-app)
142138
- [Build a QR code generator](/tutorials/build-a-qr-code-generator)
143139

144-
If you want to get started building your own projects, check out the quick-start templates we've provided in our [Starters](/starters).
140+
If you want to get started building your own projects, review the existing list of [Quickstart templates](/get-started/quickstarts).

0 commit comments

Comments
 (0)