Skip to content

Commit a49d0dc

Browse files
authored
Made cargo new create library instead of main (#1061)
NEAR doesn't use main.rs. In the tutorial it tells us to do a normal `cargo new` and to delete the main.rs file and add a lib.rs file. `Cargo new` has an option to make it create a library right off the bat. I think it would be less confusing for people to not have to delete and remake a new file right off the bat.
1 parent c11ed1f commit a49d0dc

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

docs/develop/contracts/rust/intro.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,24 @@ contract using `cargo`. To create the repository, navigate back to your projects
142142
the following commands:
143143

144144
```bash
145-
$ cargo new rust-counter-tutorial
145+
$ cargo new rust-counter-tutorial --lib
146146
$ cd rust-counter-tutorial
147147
```
148148

149149
The first command creates a new directory called `rust-counter-tutorial`. We’ve named the project
150150
`rust-counter-tutorial`, and Cargo creates its files in a directory of the same name.
151151

152152
If you check the `rust-counter-tutorial` directory, you’ll see that Cargo has generated two
153-
files and one directory for us: a `Cargo.toml` file and a `src` directory with a `main.rs` file
153+
files and one directory for us: a `Cargo.toml` file and a `src` directory with a `lib.rs` file
154154
inside.
155155

156156
```bash
157157
.
158158
├── Cargo.toml
159159
└── src
160-
└── main.rs
160+
└── lib.rs
161161
```
162162

163-
> **Note:** The `main.rs` is not needed for this example, so feel free to delete it.
164-
165163
## Creating the files {#creating-the-files}
166164

167165
This smart contract project starts out with a simple layout:
@@ -215,9 +213,9 @@ overflow-checks = true
215213

216214
</details>
217215

218-
### Creating `lib.rs` {#creating-librs}
216+
### Editing `lib.rs` {#editing-librs}
219217

220-
Create a `./src/lib.rs` file in your text editor, and paste the content of the following
218+
Open the `./src/lib.rs` file in your text editor, and paste the content of the following
221219
[`lib.rs`](https://github.com/near-examples/rust-counter/blob/master/contract/src/lib.rs) file.
222220
This example uses a `lib.rs` file with the smart contract logic using a `struct`,
223221
the `struct`'s functions, and unit tests. This will all be in one file for this simple example.

0 commit comments

Comments
 (0)