Skip to content

Commit f7ffeb4

Browse files
authored
Merge pull request #16 from akien-mga/getting-started-misc-fixes
Misc fixes in Getting Started
2 parents e2689bd + 6dbc4d0 commit f7ffeb4

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

src/faq.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
**Question**
66

7-
What is the `BorrowFailed` error and why I keep getting it? I'm only trying to call another method that takes `&mut self` while holding one!
7+
What is the `BorrowFailed` error and why do I keep getting it? I'm only trying to call another method that takes `&mut self` while holding one!
88

99
**Answer**
1010

11-
In Rust, [there can only be *one* `&mut` reference to the same memory location at the same time](https://docs.rs/dtolnay/0.0.9/dtolnay/macro._02__reference_types.html). To enforce this while making simple use cases easier, the bindings make use of [interior mutability](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html). This works like a lock: whenever a method with `&mut self` is called, it will try to obtain a lock on the `self` value, and hold it *until it returns*. As a result, if another method that takes `&mut self` in called in the meantime for whatever reason (e.g. signals), the lock will fail and a error (`BorrowFailed`) will be produced.
11+
In Rust, [there can only be *one* `&mut` reference to the same memory location at the same time](https://docs.rs/dtolnay/0.0.9/dtolnay/macro._02__reference_types.html). To enforce this while making simple use cases easier, the bindings make use of [interior mutability](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html). This works like a lock: whenever a method with `&mut self` is called, it will try to obtain a lock on the `self` value, and hold it *until it returns*. As a result, if another method that takes `&mut self` is called in the meantime for whatever reason (e.g. signals), the lock will fail and an error (`BorrowFailed`) will be produced.
1212

1313
It's relatively easy to work around this problem, though: Because of how the user-data container works, it can only see the outermost layer of your script type - the entire structure. This is why it's stricter than what is actually required. If you run into this problem, you can [introduce finer-grained interior mutability](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html) in your own type, and modify the problematic exported methods to take `&self` instead of `&mut self`.
1414

@@ -119,7 +119,7 @@ impl AnotherNativeScript {
119119
// 3. Map over the RefInstance to extract the underlying user data.
120120
my_object
121121
.map(|my_object, _owner| {
122-
// now my_object is of type MyObject
122+
// Now my_object is of type MyObject.
123123
})
124124
.expect("Failed to map over my_object instance");
125125
}
@@ -140,4 +140,4 @@ impl AnotherNativeScript {
140140

141141
People [reported](https://github.com/rust-analyzer/rust-analyzer/issues/5040) similar issues and found that switching on the `"rust-analyzer.cargo.loadOutDirsFromCheck": true` setting fixed it:
142142

143-
![completion](images/completion.png)
143+
![completion](images/completion.png)

src/getting-started/hello-world.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Follow this tutorial to learn how to create an empty project that simply prints "Hello, world!" to the Godot console on ready. The code might not compile or work as intended while it's in-progress, but at the end of this section, the code will be compiling and working fine.
44

5-
The full, finished code is available in the main repo: https://github.com/godot-rust/godot-rust/tree/master/examples/hello_world
5+
The full, finished code is available in the main repo: [https://github.com/godot-rust/godot-rust/tree/master/examples/hello_world](https://github.com/godot-rust/godot-rust/tree/master/examples/hello_world).
66

77
## Creating the project
88

@@ -22,9 +22,8 @@ Your file structure should look like this:
2222
│ ├ Cargo.toml
2323
├─── my-godot-project
2424
│ ├─── .import
25-
│ └─── assets
26-
│ │ ├ icon.png
27-
│ │ └ icon.png.import
25+
│ ├ icon.png
26+
│ ├ icon.png.import
2827
│ └ project.godot
2928
```
3029

@@ -83,15 +82,15 @@ This declares an empty callback function, which is called when the library is lo
8382
godot_init!(init);
8483
```
8584

86-
These macros define the necessary C callbacks used by Godot. You only need *one* of these in the entire library. Note how the `init` function defined earlier is given to the `godot_nativescript_init` macro as a callback.
85+
This macro defines the necessary C callbacks used by Godot. You only need *one* invocation of this macro in the entire library. Note how the `init` function defined earlier is given to the `godot_init!` macro as a callback.
8786

8887
> ### GDNative internals
8988
>
90-
> The purposes of these macros will be discussed in detail in [_An Overview of GDNative_](../gdnative-overview.md). For now, treat these as magic incantations.
89+
> The purposes of this macro will be discussed in detail in [_An Overview of GDNative_](../gdnative-overview.md). For now, treat it as a magic incantation.
9190
9291
## Your first script
9392

94-
With the boilerplate put into place, you can now create your first Rust script! We will go step by step and discover what's needed to create script "class"es. Intermediate code versions might not compile, but at the end of this section it should be working!
93+
With the boilerplate put into place, you can now create your first Rust script! We will go step by step and discover what's needed to create script "classes". Intermediate code versions might not compile, but at the end of this section it should be working!
9594

9695
A script is simply a Rust type that implements (derives) the `NativeScript` trait:
9796

@@ -128,7 +127,7 @@ impl HelloWorld {
128127
}
129128
```
130129

131-
The `HelloWorld` type is like any regular Rust type, and can have any number of ordinary `impl` blocks. However, it must have **one and only one** `impl` block with the `#[methods]` attribute, which tells godot-rust to generate code that automatically bind any exported methods to Godot.
130+
The `HelloWorld` type is like any regular Rust type, and can have any number of ordinary `impl` blocks. However, it must have **one and only one** `impl` block with the `#[methods]` attribute, which tells godot-rust to generate code that automatically binds any exported methods to Godot.
132131

133132
## Creating the NativeScript resource
134133

@@ -175,10 +174,10 @@ Now, re-compile the crate using `cargo build` and copy the resulting binary to t
175174

176175
## Wrapping it up
177176

178-
Congratulations! You have just created your first Rust GDNative library. You have learned how to expose scripts, methods to Godot using the bindings, and how to use them in Godot. A lot of the details are still unexplained, but you're off to a good start!
177+
Congratulations! You have just created your first Rust GDNative library. You have learned how to expose scripts and methods to Godot using the bindings, and how to use them in Godot. A lot of the details are still unexplained, but you're off to a good start!
179178

180-
You can find the full code for this example in the main repo: https://github.com/godot-rust/godot-rust/tree/master/examples/hello_world
179+
You can find the full code for this example in the main repo: [https://github.com/godot-rust/godot-rust/tree/master/examples/hello_world](https://github.com/godot-rust/godot-rust/tree/master/examples/hello_world).
181180

182181
## Work-in-progress
183182

184-
**The Getting Started tutorial is a work-in-progress, and unfortunately it ends here for now!** To learn more about the API, you'll have to dive into the [documentation on docs.rs](https://docs.rs/gdnative/0.9), and the [other examples in the main repo]( https://github.com/godot-rust/godot-rust/tree/master/examples/). If you have any questions using the bindings, ask away in the `#gdnative_dev` channel on the [Godot Engine community Discord server](https://godotengine.org/community)!
183+
**The Getting Started tutorial is a work-in-progress, and unfortunately it ends here for now!** To learn more about the API, you'll have to dive into the [documentation on docs.rs](https://docs.rs/gdnative/0.9), and the [other examples in the main repo]( https://github.com/godot-rust/godot-rust/tree/master/examples/). If you have any questions using the bindings, ask away in the `#gdnative_dev` channel on the [Godot Engine community Discord server](https://godotengine.org/community)!

src/getting-started/setup.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Before we can start creating a hello-world project using godot-rust, we'll need
66

77
The default API version is currently 3.2.3-stable. For the rest of the tutorial, we'll assume that you have Godot 3.2.3-stable installed, and available in your `PATH` as `godot`.
88

9-
You may download binaries of Godot 3.2.3-stable from the official repository: https://downloads.tuxfamily.org/godotengine/3.2.3/
9+
You may download binaries of Godot 3.2.3-stable from the official repository: [https://downloads.tuxfamily.org/godotengine/3.2.3/](https://downloads.tuxfamily.org/godotengine/3.2.3/).
1010

1111
> ### Using another build of the engine
1212
>
1313
> For simplicity, we assume that you use the official build of 3.2.3-stable for the Getting Started tutorial. If you want to use another version of the engine, see the [Using custom builds of Godot](../advanced-guides/custom-bindings.md) guide.
1414
1515
## Rust
1616

17-
[rustup](https://rustup.rs/) is the recommended way to install the Rust toolchain, including the compiler, standard library, and Cargo, the package manager. Visit https://rustup.rs/ to see instructions for your platform.
17+
[rustup](https://rustup.rs/) is the recommended way to install the Rust toolchain, including the compiler, standard library, and Cargo, the package manager. Visit [https://rustup.rs/](https://rustup.rs/) to see instructions for your platform.
1818

1919
After installation of rustup and the `stable` toolchain, check that they were installed properly:
2020

@@ -33,11 +33,11 @@ When working on Windows, it's also necessary to install the [Visual Studio Build
3333

3434
## LLVM
3535

36-
The godot-rust bindings depend on `bindgen`, which in turn [depends on LLVM](https://rust-lang.github.io/rust-bindgen/requirements.html). You may download LLVM binaries from https://releases.llvm.org/.
36+
The godot-rust bindings depend on `bindgen`, which in turn [depends on LLVM](https://rust-lang.github.io/rust-bindgen/requirements.html). You may download LLVM binaries from [https://releases.llvm.org/](https://releases.llvm.org/).
3737

3838
After installation, check that LLVM was installed properly:
3939

4040
```bash
41-
# Check if CLang is installed and registered in PATH
41+
# Check if Clang is installed and registered in PATH
4242
clang -v
43-
```
43+
```

0 commit comments

Comments
 (0)