diff --git a/lessons/ar/chapter_10.yaml b/lessons/ar/chapter_11.yaml similarity index 93% rename from lessons/ar/chapter_10.yaml rename to lessons/ar/chapter_11.yaml index 2fe21fac2..89c960742 100644 --- a/lessons/ar/chapter_10.yaml +++ b/lessons/ar/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: الفصل 10 - النهاية +- title: الفصل 11 - النهاية content_markdown: > لقد كان من دواعي سروري أن نكون معك في دورة تعلم رست (Rust). فيريس (Ferris) وفريق دورة تعلم رست (the Tour of Rust team) يأملون جدا بأن تستمتع برحلتك المقبلة في تعلم رست (Rust)! إذا شعرت بالإرتياح لما تعلمت حتى الآن، فإننا نوصيك بالتعمق أكثر في اللغة من خلال هذه الموارد: diff --git a/lessons/de/chapter_10.yaml b/lessons/de/chapter_11.yaml similarity index 91% rename from lessons/de/chapter_10.yaml rename to lessons/de/chapter_11.yaml index 0cf051637..60688a2f3 100644 --- a/lessons/de/chapter_10.yaml +++ b/lessons/de/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Kapitel 10 - Das Ende +- title: Kapitel 11 - Das Ende content_markdown: > Es war eine Freude, dich bei der Tour durch Rust dabei gehabt zu haben. Ferris und das ,,Tour of Rust"-Team hoffen, dass es dir gefallen hat! diff --git a/lessons/en/chapter_10.yaml b/lessons/en/chapter_10.yaml index aa170fcf4..e57b4a08e 100644 --- a/lessons/en/chapter_10.yaml +++ b/lessons/en/chapter_10.yaml @@ -1,10 +1,149 @@ -- title: Chapter 10 - The End +- title: Chapter 10 - I/O content_markdown: > - It's been a joy to have you on the Tour of Rust. Ferris and the Tour of Rust - team sincerely hope you enjoy the journey ahead! If you + In computing, `I/O` is an abbreviation for `Input/Output` operation. + + The `input` is what the computer and the algorithm receive and + the `output` represents the result generated based on the `input`. + + Thing about `I/O` as a stream of information + + A compute system without output is nearly useless. + + It will always run the same code on the same data and, thus, produce the same result. - have felt comfortable this far, we strongly recommend diving deeper with - these resources: +- title: Do it locally + content_markdown: > + In this chapter, the Playground will be just a code support for you :(. + + Since most of the `I/O` programs are designed to compile on a local machine + (yours :) ), consider setting up a Rust environment on your personal computer and + familiarise yourself with the terminal. + + Also, consider using an `IDE`, such as `VS Code` or `RustRover` + and familiarise yourself with the [terminal](https://www.youtube.com/watch?v=lZ7Kix9bjPI). + +- title: Standard Input (stdin) + content_markdown: > + `Standard Input` refers to the data provided by the user for the algorithm to process. + + + Thus, the `input` represents what a program is being given. + Mostly, in terms of `input`, you'll work with `String` and `files`. + + + The Rust library `std::io` has the necessary components to interact with `I/O` + channels, such as the keyboard or any other input source. + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aio%3B%0A%0Afn+main%28%29+%7B%0A++++let+mut+input+%3D+String%3A%3Anew%28%29%3B%0A%0A++++%2F%2F+the+read+will+be+stopped+by+%60%5Cn%60+character%0A++++if+let+Ok%28_%29+%3D+io%3A%3Astdin%28%29.read_line%28%26mut+input%29+%7B%0A++++++++println%21%28%22Input+text+%3A+%7B%7D%22%2C+input%29%3B%0A++++%7D%0A%7D%0A + +- title: Standard Output (stdout) + content_markdown: > + Remember the first lesson? Can you notice something relevant to `I/O`? + + Of course that what `println!` does is an output operation, + in fact it directs (outputs) text to `stdout` (stdout) + and it will be displayed on the screen. + + If you don't want to print a new line character `\n` for you, use `print!` + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aio%3B%0A%0Afn+main%28%29+%7B%0A++++let+mut+input+%3D+String%3A%3Anew%28%29%3B%0A%0A++++%2F%2F+the+read+will+be+stopped+by+%60%5Cn%60+character%0A++++if+let+Ok%28_%29+%3D+io%3A%3Astdin%28%29.read_line%28%26mut+input%29+%7B%0A++++++++println%21%28%22Input+text+%3A+%7B%7D%22%2C+input%29%3B%0A++++%7D%0A%7D%0A + +- title: Standard Error (stdout) + content_markdown: > + In order to separate error reporting from common printing, you can use the `eprint!` and + `eprintln!` macros that will display text in the standard error (`stderr`) channel, + instead of `stdout`. Use this macro with an informative message. + + In UNIX-like systems, such as macOS or LINUX, you can separate the two types of + output by using redirections: + - `./main > output.txt` + - `./main >> output.txt` + - `./main 2> output.txt` + - `./main 2>> output.txt` + + + > The commands with `2` will copy only the errors generated by the program, and the ones without `2` will discards all errors. + + > The command with `>>` will add text at the end of the file, while the operator `>` will override the file. + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aio%3B%0A%0Afn+main%28%29+%7B%0A++++let+mut+input+%3D+String%3A%3Anew%28%29%3B%0A%0A++++%2F%2F+the+read+will+be+stopped+by+%60%5Cn%60+character%0A++++if+let+Ok%28_%29+%3D+io%3A%3Astdin%28%29.read_line%28%26mut+input%29+%7B%0A++++++++println%21%28%22Input+text+%3A+%7B%7D%22%2C+input%29%3B%0A++++%7D%0A%7D%0A + +- title: File Descriptors + content_markdown: > + Now that we know what are the basic `I/O` operations, we dive even deeper. + + You've already seen before: `stdin` (standard input), `stdout` (standard output) and `stderr` (standard error). + For each of them it is associated a positive integer number, a unique identifier + for an `I/O` channel (example: file), known as a `file descriptor (fd)`. - * [The Official Rust Programming - Book](https://doc.rust-lang.org/stable/book/) + Therefore: + - `stdin`: 0 + - `stdout`: 1 + - `stderr`: 2 + - files + + [![file descriptors](https://cs-pub-ro.github.io/operating-systems/assets/images/file-descriptors-d19424f0a417ecd1c032f98a1969ad75.svg) + + + Working with files plays an important role in the `I/O` operations. + + You've already learned to open a text file and read its content. + + But how about writing data in it, as an `I/O` channel. + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Afs%3A%3A%7Bself%2C+File%7D%3B++++++%2F%2F+file+system%0Ause+std%3A%3Aio%3A%3A%7Bself%2C+Write%7D%3B+++++%2F%2F+input+output%0A%0Afn+main%28%29+-%3E+io%3A%3AResult%3C%28%29%3E+%7B%0A++++let+file_name+%3D+%22output.txt%22%3B%0A%0A++++%2F%2F+creates+the+file+if+it+doesn%27t+already+exists%0A++++let+mut+file+%3D+File%3A%3Acreate%28file_name%29%3F%3B%0A%0A++++let+text_to_write+%3D+%22Hello%2C+World%21%5Cn%5C%0A++++++++++++++++++++++++++++This+is+a+line+of+text.%5Cn%22%3B%0A++++file.write_all%28text_to_write.as_bytes%28%29%29%3F%3B%0A%0A++++let+absolute_path+%3D+fs%3A%3Acanonicalize%28file_name%29%3F%3B%0A++++println%21%28%22Text+has+been+written+to%3A+%7B%3A%3F%7D%22%2C+absolute_path%29%3B%0A%0A++++return+Ok%28%28%29%29%3B%0A%7D%0A + +- title: System Arguments + content_markdown: > + A Rust program is able to receive `input` from the in-line arguments. + + In order to do so, open a [terminal](https://www.youtube.com/watch?v=lZ7Kix9bjPI), compile it and pass the arguments to the executable in the command promt. + + These arguments might be relevant files, flags and so on. + The developer must document their purpose. + + If you are using LINUX or macOS, bear in mind these commands: + ```bash + $ touch main.rs + $ rustc main.rs + $ ./main.rs 2 3 4 5 + ``` + + Otherwise, for Windows environment, on a PowerShell and paste them + ```PowerShell + > echo. > main.rs + > rustc main.rs + > .\main.exe 2 3 4 5 + ``` + + + > Notice that the first argument is the executable itself + + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aenv%3B+++++++%2F%2F+env+stands+for+environment%0A%0Afn+main%28%29+%7B%0A++++let+args%3A+Vec%3CString%3E+%3D+env%3A%3Aargs%28%29.collect%28%29%3B%0A++++println%21%28%22number+of+arguments+%3D+%7B%7D%22%2C+args.len%28%29%29%3B%0A++++println%21%28%22the+inline+arguments+are+%3A+%7B%3A%3F%7D%22%2C+args%29%3B%0A%7D%0A + +- title: Environment Variables + content_markdown: > + You've seen that the Rust standard library grants access to the system. + + Using the `std::env` module, you can do in Rust some task that might require + a UNIX terminal, such as: + - command line arguments + - printing the current working directory + - current executable path + - working with environmental variables + - working with files and directories + + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aenv%3B+++%2F%2F+for+interacting+with+the+system%27s+environment%0A%0Afn+main%28%29+%7B%0A%0A++++if+let+Ok%28current_dir%29+%3D+env%3A%3Acurrent_dir%28%29+%7B%0A++++++++if+let+Some%28pwd%29+%3D+current_dir.to_str%28%29+%7B%0A++++++++++++println%21%28%22The+current+working+directory+%3D+%7B%7D%22%2C+pwd%29%3B%0A++++++++%7D%0A++++%7D%0A%0A++++%2F%2F+%24+echo+%24PWD++++++%23+environment+variable%0A++++%2F%2F+if+you+don%27t+want+to+see+Seme%28...%29%2C+you+have+to+pattern+match+on+Ok%28%29%0A++++println%21%28%22The+current+working+directory+%3D+%7B%3A%3F%7D%22%2C+env%3A%3Avar%28%22PWD%22%29.ok%28%29%29%3B%0A%0A++++%2F%2F+%24+echo+%24PWD++++++%23+environment+variable%0A++++if+let+Ok%28pwd%29+%3D+env%3A%3Avar%28%22PWD%22%29+%7B%0A++++++++println%21%28%22The+current+working+directory+%3D+%7B%7D%22%2C+pwd%29%3B%0A++++%7D%0A%0A++++%2F%2F+%24+echo+%24USER+++++%23+environment+variable%0A++++if+let+Ok%28user%29+%3D+env%3A%3Avar%28%22USER%22%29+%7B%0A++++++++println%21%28%22The+current+user+is%3A+%7B%7D%22%2C+user%29%3B%0A++++%7D%0A%0A%0A++++%2F%2F+%24+echo+%24IDK++++++%23+I+suppose+you+didn%27t+set+this+variable+%3A%29%0A++++if+let+Err%28err%29+%3D+env%3A%3Avar%28%22IDK%22%29+%7B%0A++++++++eprintln%21%28%22IDK+%3A+%7B%7D%22%2C+err%29%3B%0A++++++++env%3A%3Aset_var%28%22IDK%22%2C+%22%3D+I+don%27t+know%22%29%3B%0A++++++++println%21%28%22IDK+%3D+%7B%3A%3F%7D%22%2C+env%3A%3Avar%28%22IDK%22%29.ok%28%29%29%3B%0A++++++++env%3A%3Aremove_var%28%22IDK%22%29%3B%0A++++%7D%0A%7D%0A +- title: Chapter 10 - Conclusion + content_markdown: > + Now that you know the basic of Input/Output operations, you used just two + Rust libraries along the way, and they are standard, by the way: `std::env` and `std::fs`. + + Now, you can build your own file managing system, Web App or even API. + + Checkout these resources: + - [Environment Variables](https://youtu.be/npsMN-tZNVs) + - [Rust API](https://youtu.be/_ccDqRTx-JU) + diff --git a/lessons/en/chapter_11.yaml b/lessons/en/chapter_11.yaml new file mode 100644 index 000000000..e7e14fe68 --- /dev/null +++ b/lessons/en/chapter_11.yaml @@ -0,0 +1,9 @@ +- title: Chapter 11 - The End + content_markdown: > + It's been a joy to have you on the Tour of Rust. Ferris and the Tour of Rust + team sincerely hope you enjoy the journey ahead! If you + + have felt comfortable this far, we strongly recommend diving deeper with + these resources: + + * [The Official Rust Programming Book](https://doc.rust-lang.org/stable/book/) diff --git a/lessons/en/chapter_4.yaml b/lessons/en/chapter_4.yaml index f55c2bf47..1a69c5fc2 100644 --- a/lessons/en/chapter_4.yaml +++ b/lessons/en/chapter_4.yaml @@ -132,7 +132,7 @@ function called `unwrap` that can be useful for getting a value in a quick and dirty manner. `unwrap` will: - + 1. Get the value inside Option/Result 2. If the enum is of type None/Err, `panic!` diff --git a/lessons/en/chapter_9.yaml b/lessons/en/chapter_9.yaml index ee8cb9e16..cf35f4574 100644 --- a/lessons/en/chapter_9.yaml +++ b/lessons/en/chapter_9.yaml @@ -111,7 +111,7 @@ content_markdown: > Rust has several keywords you can use in your `use` path to quickly get ahold of the module you want: - + * `crate` - the root module of your crate * `super` - the parent module of your current module diff --git a/lessons/es/chapter_10.yaml b/lessons/es/chapter_11.yaml similarity index 83% rename from lessons/es/chapter_10.yaml rename to lessons/es/chapter_11.yaml index f50317dfd..ad8ce700e 100644 --- a/lessons/es/chapter_10.yaml +++ b/lessons/es/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Capítulo 10 - Fin +- title: Capítulo 11 - Fin content_markdown: > Esto es todo por ahora, pero aún quedan más capítulos, así que ¡muy atento! Esperamos que disfrutes del viaje. diff --git a/lessons/fa/chapter_10.yaml b/lessons/fa/chapter_11.yaml similarity index 92% rename from lessons/fa/chapter_10.yaml rename to lessons/fa/chapter_11.yaml index aa170fcf4..3b72c2374 100644 --- a/lessons/fa/chapter_10.yaml +++ b/lessons/fa/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Chapter 10 - The End +- title: Chapter 11 - The End content_markdown: > It's been a joy to have you on the Tour of Rust. Ferris and the Tour of Rust team sincerely hope you enjoy the journey ahead! If you diff --git a/lessons/fr/chapter_10.yaml b/lessons/fr/chapter_11.yaml similarity index 94% rename from lessons/fr/chapter_10.yaml rename to lessons/fr/chapter_11.yaml index 58709d0f5..9d00e013f 100644 --- a/lessons/fr/chapter_10.yaml +++ b/lessons/fr/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Chapitre 10 - Fin +- title: Chapitre 11 - Fin content_markdown: > Ce fut une joie de t'avoir sur le Tour de Rust. Ferris et l'équipe du diff --git a/lessons/gr/chapter_10.yaml b/lessons/gr/chapter_11.yaml similarity index 92% rename from lessons/gr/chapter_10.yaml rename to lessons/gr/chapter_11.yaml index 33963a22b..cd361922d 100644 --- a/lessons/gr/chapter_10.yaml +++ b/lessons/gr/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Κεφάλαιο 10 - Το Τέλος +- title: Κεφάλαιο 11 - Το Τέλος content_markdown: > Μεγάλη μας χαρά που σας είχαμε στην Ξενάγηση στη Rust. Ο Ferris και η ομάδα της Ξενάγησης ελπίζουμε ειλικρινά να απολαύσετε το ταξίδι που σας περιμένει! Αν αισθάνεστε άνετα ως τώρα, προτείνουμε ανεπιφύλακτα να διεισδύσετε πιο βαθιά με τα εξής βοηθήματα: diff --git a/lessons/hu/chapter_10.yaml b/lessons/hu/chapter_11.yaml similarity index 92% rename from lessons/hu/chapter_10.yaml rename to lessons/hu/chapter_11.yaml index 6d582a90e..efe927ee4 100644 --- a/lessons/hu/chapter_10.yaml +++ b/lessons/hu/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: 10. Fejezet - Vége +- title: 11. Fejezet - Vége content_markdown: | Örülök, hogy velem tartottál a Rust-túrán! Ferris és a Rust-túra csapata őszintén reméli, hogy tetszeni fog, ami utad során rád vár! Ha az eddigieket kényelmesnek találtad, melegen ajánljuk diff --git a/lessons/ie/chapter_10.yaml b/lessons/ie/chapter_11.yaml similarity index 82% rename from lessons/ie/chapter_10.yaml rename to lessons/ie/chapter_11.yaml index b90c08494..f88b80808 100644 --- a/lessons/ie/chapter_10.yaml +++ b/lessons/ie/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Capitul 10 - Fine +- title: Capitul 11 - Fine content_markdown: > To es omnicos por nu. Plu tard va venir nov contenete. Yo espera que tu va juir li viage a sequer! diff --git a/lessons/ja/chapter_10.yaml b/lessons/ja/chapter_11.yaml similarity index 92% rename from lessons/ja/chapter_10.yaml rename to lessons/ja/chapter_11.yaml index 3ba6f67a6..b3906acea 100644 --- a/lessons/ja/chapter_10.yaml +++ b/lessons/ja/chapter_11.yaml @@ -1,2 +1,2 @@ -- title: 第 10 章 - 終わりに +- title: 第 11 章 - 終わりに content_markdown: "Rustツアーに参加していただきありがとうございました。フェリスとRustツアーチームは皆さんが今後も楽しんでくれるよう願っています。\t\nここまで楽しんでいただけたなら、以下の資料を通してより深く学ぶのを推奨します。\t\n* [The Official Rust Programming Book](https://doc.rust-lang.org/stable/book/)\n" diff --git a/lessons/ko/chapter_10.yaml b/lessons/ko/chapter_11.yaml similarity index 95% rename from lessons/ko/chapter_10.yaml rename to lessons/ko/chapter_11.yaml index 981fd809d..dadb8a808 100644 --- a/lessons/ko/chapter_10.yaml +++ b/lessons/ko/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: 10장 - 끝 +- title: 11장 - 끝 content_markdown: > Tour of Rust를 함께 해서 즐거웠습니다. Ferris와 Tour of Rust 팀은 여러분이 앞에 놓인 여정을 즐기시길 진심으로 바랍니다! diff --git a/lessons/pl/chapter_10.yaml b/lessons/pl/chapter_11.yaml similarity index 94% rename from lessons/pl/chapter_10.yaml rename to lessons/pl/chapter_11.yaml index e20269b7c..e9cee258b 100644 --- a/lessons/pl/chapter_10.yaml +++ b/lessons/pl/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Rozdział 10 - Koniec +- title: Rozdział 11 - Koniec content_markdown: > Było mi niezmiernie przyjemnie mieć możliwość oprowadzenia Cię po zakamarkach języka Rust. Ferris i cała załoga Przewodnika po Języku Rust życzy Ci wszystkiego najlepszego diff --git a/lessons/pt-br/chapter_10.yaml b/lessons/pt-br/chapter_11.yaml similarity index 81% rename from lessons/pt-br/chapter_10.yaml rename to lessons/pt-br/chapter_11.yaml index b2eba57df..7e9d58ece 100644 --- a/lessons/pt-br/chapter_10.yaml +++ b/lessons/pt-br/chapter_11.yaml @@ -1,3 +1,3 @@ -- title: Capítulo 10 - Fim +- title: Capítulo 11 - Fim content_markdown: | Isso é tudo por enquanto. Fique ligado para novos conteúdos. Espero que se divirta nesta jornada! diff --git a/lessons/ro/chapter_10.yaml b/lessons/ro/chapter_10.yaml index 99a993fd6..2d125a8d7 100644 --- a/lessons/ro/chapter_10.yaml +++ b/lessons/ro/chapter_10.yaml @@ -1,9 +1,147 @@ -- title: Chapter 10 - Sfârșit +- title: Capitolul 10 - I/o content_markdown: > - A fost o plăcere să te avem alături în Turul limbajului Rust. Ferris și echipa - Turului limbajului Rust speră din suflet că te vei bucura de ce îți rezervă viitorul! Dacă + În informatică, `I/O` este o abreviere pentru operația de `Input/Output`. - ți-a plăcut acest tur, îți recomandăm să continui cu resursele: + `Input-ul` reprezintă datele primite de calculator sau de algoritm, + iar `output-ul` reprezintă rezultatul generat pe baza `input-ului`. + + Gândește-te la `I/O` ca la un flux de informații. + + Un sistem de calcul fără output este aproape inutil. + Va rula întotdeauna același cod pe aceleași date și, astfel, va produce același rezultat. + +- title: Rulează local + content_markdown: > + În acest capitol, Playground-ul va fi doar un suport de cod pentru tine :(. + + Deoarece majoritatea programelor `I/O` sunt proiectate pentru a compila pe o mașină locală + (calculatorul tău :) ), ia în considerare configurarea unui mediu Rust pe computerul personal și + familiarizează-te cu terminalul. + + De asemenea, consideră utilizarea unui `IDE`, cum ar fi `VS Code` sau `RustRover` + și familiarizează-te cu [terminalul](https://www.youtube.com/watch?v=lZ7Kix9bjPI). + +- title: Intrarea Standard (stdin) + content_markdown: > + `Intrarea Standard` se referă la datele furnizate de utilizator pentru a fi procesate de algoritm. + + Astfel, `input-ul` reprezintă ceea ce un program primește. + În mare parte, în ceea ce privește `input-ul`, vei lucra cu String și fișiere. + + Biblioteca Rust `std::io` are componentele necesare pentru a interacționa cu canalele de `I/O`, + cum ar fi tastatura sau orice altă sursă de intrare. + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aio%3B%0A%0Afn+main%28%29+%7B%0A++++let+mut+input+%3D+String%3A%3Anew%28%29%3B%0A%0A++++%2F%2F+citirea+va+fi+oprita+la+apri%C8%9Bia+caracterului+%60%5Cn%60%0A++++if+let+Ok%28_%29+%3D+io%3A%3Astdin%28%29.read_line%28%26mut+input%29+%7B%0A++++++++println%21%28%22Textul+de+intrare+%3A+%7B%7D%22%2C+input%29%3B%0A++++%7D%0A%7D%0A + +- title: Ieșirea Standard (stdout) + content_markdown: > + Îți amintești de prima lecție? Poți observa ceva relevant legat de `I/O`? + + Desigur, ceea ce face `println!` este o operațiune de output, + de fapt, direcționează (afișează) textul către `stdout` + și acesta va fi afișat pe ecran. + + Dacă nu dorești să afișezi caracter de linie nouă `\n`, folosește `print!`. + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aio%3B%0A%0Afn+main%28%29+%7B%0A++++let+mut+input+%3D+String%3A%3Anew%28%29%3B%0A%0A++++%2F%2F+citirea+va+fi+oprita+la+apri%C8%9Bia+caracterului+%60%5Cn%60%0A++++if+let+Ok%28_%29+%3D+io%3A%3Astdin%28%29.read_line%28%26mut+input%29+%7B%0A++++++++println%21%28%22Textul+de+intrare+%3A+%7B%7D%22%2C+input%29%3B%0A++++%7D%0A%7D%0A + +- title: Eroarea Standard (stdout) + content_markdown: > + Pentru a separa raportarea erorilor de tipărirea obișnuită, + poți utiliza macro-urile `eprint!` și `eprintln!` care vor + afișa text pe canalul de eroare standard (`stderr`), + în loc de `stdout`. + Utilizați acest macro cu un mesaj informativ. + + În sisteme asemănătoare UNIX, cum ar fi macOS sau LINUX, + poți separa cele două tipuri de ieșire prin utilizarea redirecționărilor: + - `./main > output.txt` + - `./main >> output.txt` + - `./main 2> output.txt` + - `./main 2>> output.txt` + + > Comenzile cu `2` vor copia doar erorile generate de program, iar cele fără `2` vor elimina toate erorile. + + > Comanda cu `>>` va adăuga text la sfârșitul fișierului, în timp ce operatorul `>` va suprascrie fișierul. + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aio%3B%0A%0Afn+main%28%29+%7B%0A++++let+mut+input+%3D+String%3A%3Anew%28%29%3B%0A%0A++++%2F%2F+citirea+va+fi+oprita+la+apri%C8%9Bia+caracterului+%60%5Cn%60%0A++++if+let+Ok%28_%29+%3D+io%3A%3Astdin%28%29.read_line%28%26mut+input%29+%7B%0A++++++++println%21%28%22Textul+de+intrare+%3A+%7B%7D%22%2C+input%29%3B%0A++++%7D%0A%7D%0A + +- tile: Descriptori de Fișiere + content_markdown: > + Acum că știm care sunt operațiunile de bază `I/O`, hai să intrăm mai în detaliu. + + Ai văzut deja: `stdin` (intrare standard), `stdout` (ieșire standard) și `stderr` (eroare standard). + + Fiecare dintre ele are asociat un număr întreg pozitiv, un identificator unic + pentru un canal `I/O` (de exemplu: fișier), cunoscut sub numele de `descriptor de fișier (fd)`. + + Prin urmare: + - `stdin`: 0 + - `stdout`: 1 + - `stderr`: 2 + - fișiere + + [![file descriptors](https://cs-pub-ro.github.io/operating-systems/assets/images/file-descriptors-d19424f0a417ecd1c032f98a1969ad75.svg) + + Lucrul cu fișiere joacă un rol important în operațiunile `I/O`. + + Ați învățat deja să deschideți un fișier text și să citiți conținutul acestuia. + + Dar ce zici de a scrie date în el, folosindu-l pe post de canal `I/O`? + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Afs%3A%3A%7Bself%2C+File%7D%3B++++++%2F%2F+sistemul+de+fi%C5%9Fiere%0Ause+std%3A%3Aio%3A%3A%7Bself%2C+Write%7D%3B+++++%2F%2F+input+output%0A%0Afn+main%28%29+-%3E+io%3A%3AResult%3C%28%29%3E+%7B%0A++++let+nume_fi%C5%9Fier+%3D+%22output.txt%22%3B%0A%0A++++%2F%2F+creaz%C4%83+un+fi%C5%9Fier+dac%C4%83+nu+exist%C4%83+deja%0A++++let+mut+fi%C5%9Fier+%3D+File%3A%3Acreate%28nume_fi%C5%9Fier%29%3F%3B%0A%0A++++let+text_to_write+%3D+%22Buna%2C+lume%21%5Cn%5C%0A++++++++++++++++++++++++++++Aceasta+este+o+linie+de+text.%5Cn%22%3B%0A++++fi%C5%9Fier.write_all%28text_to_write.as_bytes%28%29%29%3F%3B%0A%0A++++let+absolute_path+%3D+fs%3A%3Acanonicalize%28nume_fi%C5%9Fier%29%3F%3B%0A++++println%21%28%22Textul+a+fost+scris+%C3%AE+fi%C5%9Fierul%3A+%7B%3A%3F%7D%22%2C+absolute_path%29%3B%0A%0A++++return+Ok%28%28%29%29%3B%0A%7D%0A +- title: Argumentele din Linia de Comandă + content_markdown: > + Un program Rust este capabil să primească informații de intrare din argumentele furnizate în linia de comandă. + + Pentru a face acest lucru, deschideți un [terminal](https://www.youtube.com/watch?v=lZ7Kix9bjPI), + compilați programul și transmiteți argumentele executabilului din promptul de comandă. + + Aceste argumente pot fi fișiere relevante, steaguri și așa mai departe. + Dezvoltatorul trebuie să documenteze scopul lor. + + Dacă utilizezi un sistem de operare LINUX sau macOS, ține minte aceste comenzi: + ```bash + $ touch main.rs + $ rustc main.rs + $ ./main.rs 2 3 4 5 + ``` + + Altfel, pentru Windows, copiază următoarele comenzi într-un PowerShell + ```PowerShell + > echo. > main.rs + > rustc main.rs + > .\main.exe 2 3 4 5 + ``` + + > Observi că primul argument este numele executabilului? + + -code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aenv%3B+++++++%2F%2F+env+stands+for+environment%0A%0Afn+main%28%29+%7B%0A++++let+args%3A+Vec%3CString%3E+%3D+env%3A%3Aargs%28%29.collect%28%29%3B%0A++++println%21%28%22Num%C4%83rul+de+argumente+din+linia+de+comand%C4%83+%3D+%7B%7D%22%2C+args.len%28%29%29%3B%0A++++println%21%28%22Argumentele+din+lini%C4%83+de+comanda+%3A+%7B%3A%3F%7D%22%2C+args%29%3B%0A%7D%0A + +- title: Variabilele de Mediu + content_markdown: > + Ai remarcat că biblioteca standard Rust oferă acces la sistem. + + Folosind modulul `std::env`, poți face în Rust unele sarcini + care ar putea necesita un terminal UNIX, cum ar fi: + - argumentele liniei de comandă + - imprimarea directorului de lucru curent + - calea executabilă curentă + - lucrul cu variabile de mediu + - lucrul cu fișiere și directoare + + code: >- + https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=use+std%3A%3Aenv%3B+++%2F%2F+pentru+a+interactiona+cu+sistemul+%C5%9Fi+variabilele+de+mediu%0A%0Afn+main%28%29+%7B%0A%0A++++if+let+Ok%28director_curent%29+%3D+env%3A%3Acurrent_dir%28%29+%7B%0A++++++++if+let+Some%28pwd%29+%3D+director_curent.to_str%28%29+%7B%0A++++++++++++println%21%28%22Directorul+curent+este+%3D+%7B%7D%22%2C+pwd%29%3B%0A++++++++%7D%0A++++%7D%0A%0A++++%2F%2F+%24+echo+%24PWD++++++%23+variabila+de+mediu%0A++++%2F%2F+dac%C4%83+nu+folose%C5%9Fti+Some%28...%29%2C+trebuie+s%C4%83+faci+pattern-match-ing+pe+Ok%28%29%0A++++println%21%28%22Directorul+curent+este+%3D+%7B%3A%3F%7D%22%2C+env%3A%3Avar%28%22PWD%22%29.ok%28%29%29%3B%0A%0A++++%2F%2F+%24+echo+%24PWD++++++%23+variabila+de+mediu%0A++++if+let+Ok%28pwd%29+%3D+env%3A%3Avar%28%22PWD%22%29+%7B%0A++++++++println%21%28%22Directorul+curent+este+%3D+%7B%7D%22%2C+pwd%29%3B%0A++++%7D%0A%0A++++%2F%2F+%24+echo+%24USER+++++%23+variabila+de+mediu%0A++++if+let+Ok%28user%29+%3D+env%3A%3Avar%28%22USER%22%29+%7B%0A++++++++println%21%28%22Directorul+curent+este+%3A+%7B%7D%22%2C+user%29%3B%0A++++%7D%0A%0A%0A++++%2F%2F+%24+echo+%24IDK++++++%23+presupun+c%C4%83+nu+ai+setat+aceast%C4%83+variabila%C4%83%3A%29%0A++++if+let+Err%28err%29+%3D+env%3A%3Avar%28%22IDK%22%29+%7B%0A++++++++eprintln%21%28%22IDK+%3A+%7B%7D%22%2C+err%29%3B%0A++++++++env%3A%3Aset_var%28%22IDK%22%2C+%22%3D+Nu+%C5%9Ftiu%22%29%3B%0A++++++++println%21%28%22IDK+%3D+%7B%3A%3F%7D%22%2C+env%3A%3Avar%28%22IDK%22%29.ok%28%29%29%3B%0A++++++++env%3A%3Aremove_var%28%22IDK%22%29%3B%0A++++%7D%0A%7D%0A + +- title: Capitolul 10 - Concluzii + content_markdown: > + Acum că știi elementele de bază ale operațiunilor de Intrare/Ieșire, ai folosit doar două + module de Rust pe parcurs și acestea fac parte din cutia standard, apropo: `std::env` și `std::fs`. + + Acum, poți construi propriul sistem de gestionare a fișierelor, aplicație web sau chiar API. + + Aruncă un ochi peste aceste resurse. + - [Environment Variables](https://youtu.be/npsMN-tZNVs) + - [Rust API](https://youtu.be/_ccDqRTx-JU) - * [The Official Rust Programming - Book](https://doc.rust-lang.org/stable/book/) diff --git a/lessons/ro/chapter_11.yaml b/lessons/ro/chapter_11.yaml new file mode 100644 index 000000000..907fc2bb7 --- /dev/null +++ b/lessons/ro/chapter_11.yaml @@ -0,0 +1,8 @@ +- title: Capitolul 11 - Finalul + content_markdown: > + A fost o bucurie să te avem în Tour of Rust. + Ferris și echipa Tour of Rust speră din suflet că te vei bucura de călătoria care urmează! + + Daca te-ai simțit confortabil până acum, iți recomandăm cu drag următoarele resurse: + + * [ The Official Rust Programming Book ](https://doc.rust-lang.org/stable/book/) diff --git a/lessons/ru/chapter_10.yaml b/lessons/ru/chapter_11.yaml similarity index 95% rename from lessons/ru/chapter_10.yaml rename to lessons/ru/chapter_11.yaml index 65028f307..8c9d53ccf 100644 --- a/lessons/ru/chapter_10.yaml +++ b/lessons/ru/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Глава 10 - Конец +- title: Глава 11 - Конец content_markdown: > Было приятно видеть тебя в туре по Rust. Феррис и команда Tour of Rust искренне надеются, что вам понравится путешествие! diff --git a/lessons/th/chapter_10.yaml b/lessons/th/chapter_11.yaml similarity index 93% rename from lessons/th/chapter_10.yaml rename to lessons/th/chapter_11.yaml index 632dd661a..ce040682b 100644 --- a/lessons/th/chapter_10.yaml +++ b/lessons/th/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: บทที่ 10 - ตอนจบ +- title: บทที่ 11 - ตอนจบ content_markdown: > มีความสุขมากที่คุณเข้ามาใน Tour of Rust Ferris และทีม Tour of Rust หวังเป็นอย่างยิ่งว่าคุณจะสนุกกับการเดินทางข้างหน้า! diff --git a/lessons/tr/chapter_10.yaml b/lessons/tr/chapter_11.yaml similarity index 95% rename from lessons/tr/chapter_10.yaml rename to lessons/tr/chapter_11.yaml index 326e67bd0..c98cde235 100644 --- a/lessons/tr/chapter_10.yaml +++ b/lessons/tr/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Bölüm 10 - Bitti +- title: Bölüm 11 - Bitti content_markdown: > Rust Turu'nda sizi görmek benim için büyük bir zevkti. Ben Ferris ve Rust Turundaki ekip arkadaşlarım, Rust öğreniminize devam edebilmeniz için aşağıdaki kaynakları incelemenizi tavsiye ederken, önünüzdeki yolculuktan keyif almanızı içtenlikle umuyor ve başarılar diliyoruz. diff --git a/lessons/ua/chapter_10.yaml b/lessons/ua/chapter_11.yaml similarity index 91% rename from lessons/ua/chapter_10.yaml rename to lessons/ua/chapter_11.yaml index a2470ed5f..d68e1d5e1 100644 --- a/lessons/ua/chapter_10.yaml +++ b/lessons/ua/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Розділ 10 - Заключне слово +- title: Розділ 11 - Заключне слово content_markdown: > Нам було приємно бачити вас на Тур по Rust. Ферріс і команда Тур по Rust щиро сподіваються, що вам сподобається подальша подорож! Якщо ви diff --git a/lessons/vi/chapter_10.yaml b/lessons/vi/chapter_11.yaml similarity index 92% rename from lessons/vi/chapter_10.yaml rename to lessons/vi/chapter_11.yaml index 8c4c6ad9a..fd0bf5541 100644 --- a/lessons/vi/chapter_10.yaml +++ b/lessons/vi/chapter_11.yaml @@ -1,4 +1,4 @@ -- title: Chương 10 - Kết thúc +- title: Chương 11 - Kết thúc content_markdown: > Thật vui khi có bạn tham gia Tour of Rust. Ferris cùng với the Tour of Rust diff --git a/lessons/zh-cn/chapter_10.yaml b/lessons/zh-cn/chapter_11.yaml similarity index 100% rename from lessons/zh-cn/chapter_10.yaml rename to lessons/zh-cn/chapter_11.yaml