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: src/faq.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@
4
4
5
5
**Question**
6
6
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!
8
8
9
9
**Answer**
10
10
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.
12
12
13
13
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`.
14
14
@@ -119,7 +119,7 @@ impl AnotherNativeScript {
119
119
// 3. Map over the RefInstance to extract the underlying user data.
120
120
my_object
121
121
.map(|my_object, _owner| {
122
-
//now my_object is of type MyObject
122
+
//Now my_object is of type MyObject.
123
123
})
124
124
.expect("Failed to map over my_object instance");
125
125
}
@@ -140,4 +140,4 @@ impl AnotherNativeScript {
140
140
141
141
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:
Copy file name to clipboardExpand all lines: src/getting-started/hello-world.md
+10-11Lines changed: 10 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
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.
4
4
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).
6
6
7
7
## Creating the project
8
8
@@ -22,9 +22,8 @@ Your file structure should look like this:
22
22
│ ├ Cargo.toml
23
23
├─── my-godot-project
24
24
│ ├─── .import
25
-
│ └─── assets
26
-
│ │ ├ icon.png
27
-
│ │ └ icon.png.import
25
+
│ ├ icon.png
26
+
│ ├ icon.png.import
28
27
│ └ project.godot
29
28
```
30
29
@@ -83,15 +82,15 @@ This declares an empty callback function, which is called when the library is lo
83
82
godot_init!(init);
84
83
```
85
84
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.
87
86
88
87
> ### GDNative internals
89
88
>
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.
91
90
92
91
## Your first script
93
92
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!
95
94
96
95
A script is simply a Rust type that implements (derives) the `NativeScript` trait:
97
96
@@ -128,7 +127,7 @@ impl HelloWorld {
128
127
}
129
128
```
130
129
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.
132
131
133
132
## Creating the NativeScript resource
134
133
@@ -175,10 +174,10 @@ Now, re-compile the crate using `cargo build` and copy the resulting binary to t
175
174
176
175
## Wrapping it up
177
176
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!
179
178
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).
181
180
182
181
## Work-in-progress
183
182
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)!
Copy file name to clipboardExpand all lines: src/getting-started/setup.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,15 @@ Before we can start creating a hello-world project using godot-rust, we'll need
6
6
7
7
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`.
8
8
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/).
10
10
11
11
> ### Using another build of the engine
12
12
>
13
13
> 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.
14
14
15
15
## Rust
16
16
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.
18
18
19
19
After installation of rustup and the `stable` toolchain, check that they were installed properly:
20
20
@@ -33,11 +33,11 @@ When working on Windows, it's also necessary to install the [Visual Studio Build
33
33
34
34
## LLVM
35
35
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/).
37
37
38
38
After installation, check that LLVM was installed properly:
39
39
40
40
```bash
41
-
# Check if CLang is installed and registered in PATH
41
+
# Check if Clang is installed and registered in PATH
0 commit comments