Skip to content

Commit

Permalink
Merge pull request #3365 from dfinity/rust-docs-updates
Browse files Browse the repository at this point in the history
Rust intro docs revisions
  • Loading branch information
jessiemongeon1 authored Aug 15, 2024
2 parents b8e0b25 + 2928c99 commit 747a08b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 127 deletions.
14 changes: 3 additions & 11 deletions docs/developer-docs/backend/rust/2-project-organization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow";
When a new Rust project is created with the command:

```
dfx new example
dfx new example --type=rust
? Select a backend language: ›
Motoko
❯ Rust
TypeScript (Azle)
Python (Kybra)
```

the following project structure is generated:
The following project structure is generated:
```
Cargo.lock
Expand Down Expand Up @@ -53,7 +46,6 @@ webpack.config.js
In this structure, you can see the backend canister, in this case `example_backend` contains the following components:
src/example_backend:
```
│   ├── Cargo.toml //
│   ├── example_backend.did // The backend canister's Candid file.
Expand Down Expand Up @@ -244,4 +236,4 @@ If a service method returns a result type, it can still reject the call. Therefo
:::

## Next steps
Now let's get started setting up the Rust [developer environment](./3-dev-env.mdx).
Now let's get started setting up the Rust [developer environment](/docs/current/developer-docs/backend/rust/dev-env).
55 changes: 2 additions & 53 deletions docs/developer-docs/backend/rust/4-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,8 @@ To create a new Rust project using the IC SDK, open a terminal window and run th
Use `dfx new <project_name>` to create a new project:

```
dfx new rust_hello
```

You will be prompted to select the language that your backend canister will use. Select 'Rust':

```
? Select a backend language: ›
Motoko
❯ Rust
TypeScript (Azle)
Python (Kybra)
```

:::info
`dfx` versions `v0.17.0` and newer support this `dfx new` interactive prompt. [Learn more about `dfx v0.17.0`](/blog/2024/02/14/news-and-updates/update#dfx-v0170).
:::


Then, select a frontend framework for your frontend canister, or select 'No frontend canister':

```
? Select a frontend framework: ›
❯ SvelteKit
React
Vue
Vanilla JS
No JS template
No frontend canister
```

Lastly, you can include extra features to be added to your project:

```
? Add extra features (space to select, enter to confirm) ›
⬚ Internet Identity
⬚ Bitcoin (Regtest)
⬚ Frontend tests
dfx start --clean --background
dfx new rust_hello --type=rust
```


Expand All @@ -70,22 +35,6 @@ Next, navigate into your project directory by running the following command:
cd rust_hello
```

## Starting the local canister execution environment

Next, before you can build your project, you need to connect to either the local <GlossaryTooltip>replica</GlossaryTooltip> running in your development environment or the decentralized Internet Computer mainnet. For this guide, you'll deploy locally in your developer environment. For more information on deploying on the mainnet, check out the next step [deploying canisters](./5-deploying.mdx).

To start the local canister execution environment, first check that you are still in the root directory for your project, if needed.

Then, start the local <GlossaryTooltip>replica</GlossaryTooltip> on your computer in the background by running the following command:

```
dfx start --clean --background
```

:::info
Depending on your platform and local security settings, you might see a warning displayed. If you are prompted to allow or deny incoming network connections, click **Allow**.
:::

## Register, build, and deploy your project

After you connect to the local replica running in your development environment, you can register, build, and deploy your project locally.
Expand Down
71 changes: 9 additions & 62 deletions docs/developer-docs/backend/rust/5-deploying.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,11 @@ This guide will showcase a simple 'Hello, world!' example.

## Prerequisites

Before getting started, assure you have set up your developer environment according to the instructions in the [developer environment guide](./3-dev-env.mdx).
Before getting started, assure you have set up your developer environment according to the instructions in the [developer environment guide](/docs/current/developer-docs/backend/rust/dev-env) and have created a [Rust project](/docs/current/developer-docs/backend/rust/quickstart).

## Writing the canister
## Default project structure

Open a terminal window on your local computer, if you don’t already have one open.

Use `dfx new [project_name]` to create a new project:

```
dfx new hello_world
```

You will be prompted to select the language that your backend canister will use:

```
? Select a backend language: ›
❯ Motoko
Rust
TypeScript (Azle)
Python (Kybra)
```

:::info
`dfx` versions `v0.17.0` and newer support this `dfx new` interactive prompt. [Learn more about `dfx v0.17.0`](/blog/2024/02/14/news-and-updates/update#dfx-v0170).
:::


Then, select a frontend framework for your frontend canister. In this example, select:

```
? Select a frontend framework: ›
SvelteKit
React
Vue
❯ Vanilla JS
No JS template
No frontend canister
```

Lastly, you can include extra features to be added to your project:

```
? Add extra features (space to select, enter to confirm) ›
⬚ Internet Identity
⬚ Bitcoin (Regtest)
⬚ Frontend tests
```


By default, the project structure will resemble the following:
By default, Rust projects created with `dfx new` will have a default project structure that will resemble the following:

```
Cargo.lock
Expand Down Expand Up @@ -95,8 +50,6 @@ For more information on project structure and code organization, review the [pro

## Writing the `lib.rs` file

You'll be focused on the `src/hello_world_backend/src/lib.rs` file in this step.

Open the `src/hello_world_backend/src/lib.rs` file in a text editor. Replace the existing content with the following:

```rust
Expand Down Expand Up @@ -130,9 +83,9 @@ ic-cdk = "0.7.0"

Save the file.

## Deploying the canister to your local canister execution environment
## Deploying the canister locally

## Creating the canister
### Create

First, create an empty canister for the canister code to be installed into. To create the canister, run the command:

Expand All @@ -147,31 +100,25 @@ Creating canister hello_world_backend...
hello_world_backend canister created with canister id: br5f7-7uaaa-aaaaa-qaaca-cai
```

### Building the canister
### Build

Next, you need to compile your program into a WebAssembly module that can be deployed on ICP by building the canister. To build the canister, run the command:

```
dfx build hello_world_backend
```

### Installing the canister
### Install

Then, install the compiled code into your canister with the command:

```
dfx canister install hello_world_backend
```

### Deploying to the execution environment

To deploy the canister, start the dfx local <GlossaryTooltip>replica</GlossaryTooltip> with the command:

```
dfx start --clean --background
```
### Deploy

Then, you can deploy the canister with the command:
To deploy the canister use the command:

```
dfx deploy hello_world_backend
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-docs/backend/rust/8-optimizing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow";


## Overview
Compiling Rust to Wasm often increases the file size significantly. dfx versions 0.14.0 and newer include a the `wasm-opt` optimization package that can be used to optimize cycle consumption and binary size.
Compiling Rust to Wasm often increases the file size significantly. dfx versions 0.14.0 and newer include the `wasm-opt` package that can be used to optimize cycle consumption and binary size.

## Prerequisites

Expand Down

0 comments on commit 747a08b

Please sign in to comment.