Witaj świecie!
Przejdźmy do najprostszego możliwego programu Rust, klasycznego Hello World program:
fn main() {
println!("Hello 🌍!");
}
Co widać:
- Funkcje są wprowadzane za pomocą
fn. - Bloki są oddzielone nawiasami klamrowymi, jak w C i C++.
- Funkcja
mainjest punktem wejścia programu. - Rust ma higieniczne makra,
println!jest tego przykładem. - Łańcuchy znaków w Ruście są zakodowane w UTF-8 i mogą zawierać dowolne znaki Unicode.
This slide tries to make the students comfortable with Rust code. They will see a ton of it over the next four days so we start small with something familiar.
Kluczowe punkty:
-
Rust is very much like other languages in the C/C++/Java tradition. It is imperative and it doesn’t try to reinvent things unless absolutely necessary.
-
Rust jest nowoczesny, ma pełne wsparcie dla rzeczy takich jak Unicode.
-
Rust uses macros for situations where you want to have a variable number of arguments (no function overloading).
-
Macros being ‘hygienic’ means they don’t accidentally capture identifiers from the scope they are used in. Rust macros are actually only partially hygienic.
-
Rust is multi-paradigm. For example, it has powerful object-oriented programming features, and, while it is not a functional language, it includes a range of functional concepts.