Installing and Using Legion

Hands-on Rust — by Herbert Wolverson (53 / 120)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Composing Entities | TOC | Composing the Player 👉

Legion is included in Rust’s crates system, so installing it is very similar to installing bracket-lib. Open Cargo.toml in your dungeoncrawl project, and add Legion to the dependency list:

​ ​[dependencies]​
​ bracket-lib = ​"~0.8.1"​
​ legion = ​"=0.3.1"​

Note that you’re using an exact version number for Legion with the equals (=) sign. Legion is rapidly improving, which guarantees that your code will work with that published version.

Pin Your Dependencies

TIP

When you’re working on a project, it’s a good idea to pin your dependencies with the equals (=) sign once you progress beyond initial planning. This guarantees that your project won’t break because a library upgraded and changed part of its API.

Add Legion to Your Prelude

You’ll be using Legion a lot throughout your program. Rather than type use legion::* everywhere you can re-export it in your prelude, much as you did with bracket-lib. Open main.rs in your project, and add Legion to your prelude:

​ ​mod​ prelude {
​ ​pub​ ​use​ ​bracket_lib​::​prelude​::*;
​ ​pub​ ​use​ ​legion​::*;
​ ​pub​ ​use​ ​legion​::​world​::SubWorld;
​ ​pub​ ​use​ ​legion​::​systems​::CommandBuffer;
​ ...
​ }

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.