You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: products/workers/src/content/tutorials/hello-world-rust/index.md
+18-22Lines changed: 18 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,41 +9,38 @@ import TutorialsBeforeYouStart from "../../_partials/_tutorials-before-you-start
9
9
10
10
# Hello World in Rust
11
11
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.
14
13
15
14
<TutorialsBeforeYouStart/>
16
15
17
16
## Generate
18
17
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.
20
19
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:
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.
28
27
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.
30
29
31
30
## Workers Playground
32
31
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):
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.
42
39
43
40
## Building
44
41
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:
47
44
48
45
```toml
49
46
## Cargo.toml
@@ -52,8 +49,7 @@ We'll add this to our `Cargo.toml`:
52
49
pulldown-cmark = "0.4.0"
53
50
```
54
51
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:
letexpected_html:&str="<p>Hello world, this is a <del>complicated</del> <em>very simple</em> example.</p>\n";
95
91
assert_eq!(expected_html, &html_output);
96
92
97
93
format!("\nHTML output:\n{}", &html_output)
98
94
}
99
95
```
100
96
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:
102
98
103
99
```javascript
104
100
addEventListener('fetch', (event) => {
@@ -125,20 +121,20 @@ If `wrangler dev` is running, you will see the output of your Rust program in yo
125
121
126
122
## Publish
127
123
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.
129
125
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:
131
127
132
128

133
129
134
130
## Resources
135
131
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).
137
133
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:
139
135
140
136
-[Authorize users with Auth0](/tutorials/authorize-users-with-auth0)
141
137
-[Build a JAMStack app](/tutorials/build-a-jamstack-app)
142
138
-[Build a QR code generator](/tutorials/build-a-qr-code-generator)
143
139
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