@@ -20,7 +20,7 @@ A Durs module is a library crate. You must then create your crate in the `lib/`
...
@@ -20,7 +20,7 @@ A Durs module is a library crate. You must then create your crate in the `lib/`
The `lib/` directory has 4 sub-directories which correspond to 4 types of libraries:
The `lib/` directory has 4 sub-directories which correspond to 4 types of libraries:
1.`tools`: utilities, that could be useful to all crates.
1.`tools`: utilities that could be useful to all crates.
2.`modules`: libraries forming a Durs module.
2.`modules`: libraries forming a Durs module.
3.`modules-lib`: libraries dedicated to a subset of modules.
3.`modules-lib`: libraries dedicated to a subset of modules.
4.`core`: libraries structuring the architecture, linking modules between them.
4.`core`: libraries structuring the architecture, linking modules between them.
...
@@ -32,7 +32,8 @@ For example: you create a new module named "toto". You put the crate, which cont
...
@@ -32,7 +32,8 @@ For example: you create a new module named "toto". You put the crate, which cont
### How to split a module in several crates
### How to split a module in several crates
If you want to decouple your module in several crates, the directory of your main crate* must be `lib/modules/{your-module-name}/{your-module-name}`. The additional crates must be in `modules/{your-module-name}/{crate-name}`, where `crate-name` must be prefixed by `{your-module-name}`.
If you want to decouple your module in several crates, the directory of your main crate must be `lib/modules/{your-module-name}/{your-module-name}`.
The additional crates must be in `modules/{your-module-name}/{crate-name}`, where `crate-name` must be prefixed by `{your-module-name}`.
For example: you want to move some of your "toto" code into a new "tata" crate. You must move `toto` into `lib/modules/toto/toto` and create the tata module into `lib/modules/toto/toto-tata`. In addition, your new crate must declare, into its `Cargo.toml`, the name `durs-toto-tata`.
For example: you want to move some of your "toto" code into a new "tata" crate. You must move `toto` into `lib/modules/toto/toto` and create the tata module into `lib/modules/toto/toto-tata`. In addition, your new crate must declare, into its `Cargo.toml`, the name `durs-toto-tata`.
...
@@ -44,7 +45,7 @@ If you want to write a library to be used by several modules and by them only, y
...
@@ -44,7 +45,7 @@ If you want to write a library to be used by several modules and by them only, y
The `tools/` directory must only contain libraries that are also use by the core.
The `tools/` directory must only contain libraries that are also use by the core.
Summing up:
Summary:
* if a library is used by the core and maybe by some modules: into `tools/`.
* if a library is used by the core and maybe by some modules: into `tools/`.
* if it is used only by modules: into `modules-common/`.
* if it is used only by modules: into `modules-common/`.
@@ -115,7 +115,7 @@ Although this is becoming increasingly rare, some rust crates still depend on C/
...
@@ -115,7 +115,7 @@ Although this is becoming increasingly rare, some rust crates still depend on C/
cd hello-world
cd hello-world
cargo init --bin
cargo init --bin
The `--bin' option indicates that you want to create a binary, by default cargo create a library project.
The `--bin` option indicates that you want to create a binary, by default cargo create a library project.
You should have the following content in the `hello-world` folder:
You should have the following content in the `hello-world` folder:
...
@@ -128,14 +128,12 @@ You should have the following content in the `hello-world` folder:
...
@@ -128,14 +128,12 @@ You should have the following content in the `hello-world` folder:
This is the minimum content of any binary project, the source code is found in `main.rs`.
This is the minimum content of any binary project, the source code is found in `main.rs`.
Any Rust project (binary or library) must contain a file named `Cargo.toml` at the root of the project, it is somehow the equivalent of the `package.json` of npm.
Any Rust project (binary or library) must contain a file named `Cargo.toml` at the root of the project, it is somehow the equivalent of the `package.json` of npm.
The `main.rs` file already contains by default a code to perform the traditional "Hello, world !:
The `main.rs` file already contains by default a code to perform the traditional "Hello, world !":
fn main() {
fn main() {
println!("Hello, world!");
println!("Hello, world!");
}
}
Cette syntaxe doit vous rappeler furieusement le C/C++ pour ceux qui connaissent, et c'est bien normal car Rust est conçu pour être l'un des successeurs potentiel du C++. On peut toutefois déjà noter trois différences majeures avec le C/C++ :
This syntax must remind you furiously of C/C++ for those who know it, and that's normal because Rust is designed to be one of the potential successors of C++. However, three major differences can already be noted with C/C++ :
This syntax must remind you furiously of C/C++ for those who know it, and that's normal because Rust is designed to be one of the potential successors of C++. However, three major differences can already be noted with C/C++ :
1. The main() function does not take any input parameters. Command line arguments are captured in a different way using the standard library.
1. The main() function does not take any input parameters. Command line arguments are captured in a different way using the standard library.
...
@@ -148,7 +146,7 @@ Before changing the code, make sure that the default code compiles correctly :
...
@@ -148,7 +146,7 @@ Before changing the code, make sure that the default code compiles correctly :
Finished dev [unoptimized + debuginfo] target(s) in 0.91 secs
Finished dev [unoptimized + debuginfo] target(s) in 0.91 secs
Cargo is the equivalent of npm for Rust, it will look for all the dependencies of the crates (=libraries) you install. Yes in Rust we speak of crates to designate an addiction, it can be a library or a package.
Cargo is the equivalent of npm for Rust, it will look for all the dependencies of the crates (=libraries) you install. Yes in Rust we speak of crates to designate dependencies, it can be a library or a package.
If you get a `Finished dev[unoptimized + debuginfo] target(s) in x.xx secs`, congratulations you just compiled your first Rust program :)
If you get a `Finished dev[unoptimized + debuginfo] target(s) in x.xx secs`, congratulations you just compiled your first Rust program :)