forked from richardanaya/tour_of_rust
-
Notifications
You must be signed in to change notification settings - Fork 17
Translated chapters 1-4 of the Rust tour in Romanian 🇷🇴 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RaresCon
wants to merge
6
commits into
UPB-CS-OpenSourceUpstream:master
Choose a base branch
from
RaresCon:ro_translation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
323f5ba
Translated the second chapter of the Rust tour
RaresCon 64a0be5
Translated the third chapter of the Rust tour
RaresCon 5f21f42
Translated the fourth chapter of the Rust tour
RaresCon 4b93214
Translated the fifth chapter of the Rust tour
RaresCon 0b68570
Fixed addressing mistakes and translated Rust Playground snippets
RaresCon 0ab3abf
Translated some terms and expressions again.
RaresCon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| - title: Capitolul 1 - The Basics | ||
| content_markdown: > | ||
| În acest prim capitol vom explora ideile și conceptele de bază despre | ||
| funcții, variabile și tipurile primitive de date. Ne bucurăm că | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ne sunteți alături! | ||
|
|
||
|
|
||
| De asemenea, în cazul în care vă întrebați cine este crabul adorabil care | ||
| vă vorbește, mă numesc **Ferris**, | ||
| mascota neoficială a limbajului Rust. Încântat de cunoștință! | ||
|
|
||
|
|
||
| Odată ce vă veți familiariza cu Rust, puteți să vă declarați un **Rustaceu**. Așa | ||
| se numesc toți oamenii care folosesc, contribuie sau sunt interesați de Rust. | ||
| - title: The Rust Playground | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20println!(%22Bun%20venit%20în%20locul%20de%20joacă!%20Puteți%20modifica%20codul%20aici.%22)%3B%0A%7D%0A | ||
| content_markdown: > | ||
| În acest curs veți folosi un utilitar interactiv pentru scrierea codului [Rust | ||
| Playground](https://play.rust-lang.org). | ||
|
|
||
|
|
||
| E o modalitate bună de a vă juca cu Rust și a arăta altora | ||
| creativitatea și provocările dumneavoastră! | ||
| - title: Variabile | ||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20%2F%2F%20rust%20infers%20the%20type%20of%20x%0A%20%20%20%20let%20x%20%3D%2013%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%0A%20%20%20%20%2F%2F%20rust%20can%20also%20be%20explicit%20about%20the%20type%0A%20%20%20%20let%20x%3A%20f64%20%3D%203.14159%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%0A%20%20%20%20%2F%2F%20rust%20can%20also%20declare%20and%20initialize%20later%2C%20but%20this%20is%20rarely%20done%0A%20%20%20%20let%20x%3B%0A%20%20%20%20x%20%3D%200%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| content_markdown: > | ||
| Variabilele sunt declarate folosind cuvântul cheie **let**. | ||
|
|
||
|
|
||
| Atunci când dai unei variabile o valoare, Rust este capabil să deducă tipul acesteia | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| în 99% | ||
|
|
||
| din cazuri. Dacă acesta nu poate, puteți adăuga tipul de date la declararea variabilei. | ||
|
|
||
|
|
||
| Observați cum putem să dăm valori aceluiași nume de variabilă de mai multe ori. Acest | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fenomen se numește variable | ||
|
|
||
| shadowing (punere în umbră) și tipul de date se poate schimba pentru referințe ulterioare | ||
| la acel nume de variabilă. | ||
|
|
||
|
|
||
| Numele de variabile sunt mereu scrise sub formă `snake_case` (ex: my_first_variable). | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - title: Modificarea variabilelor | ||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20mut%20x%20%3D%2042%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%20%20%20%20x%20%3D%2013%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A | ||
| content_markdown: > | ||
| Limbajul Rust ține foarte mult la ce variabile pot fi modificate. Variabilele | ||
|
|
||
| fac parte din două categorii: | ||
|
|
||
|
|
||
| * **mutabile** (mutable) - compilatorul va lăsa utilizatorul să modifice șî | ||
| să citească valoarea acestui tip de variabile. | ||
|
|
||
| * **imutabile** (immutable) - compilatorul va lăsa utilizatorul doar să citească valoarea acestei variabile. | ||
|
|
||
|
|
||
| Valorile mutabile sunt declarate cu ajutorul cuvântului cheie **mut**. | ||
|
|
||
|
|
||
| O să revenim pentru a vorbi mai multe despre acest concept, dar deocamdată doar fiți | ||
| atent la acest cuvânt cheie. | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - title: Tipuri de date de bază | ||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%2012%3B%20%2F%2F%20by%20default%20this%20is%20i32%0A%20%20%20%20let%20a%20%3D%2012u8%3B%0A%20%20%20%20let%20b%20%3D%204.3%3B%20%2F%2F%20by%20default%20this%20is%20f64%0A%20%20%20%20let%20c%20%3D%204.3f32%3B%0A%20%20%20%20let%20bv%20%3D%20true%3B%0A%20%20%20%20let%20t%20%3D%20(13%2C%20false)%3B%0A%20%20%20%20let%20sentence%20%3D%20%22hello%20world!%22%3B%0A%20%20%20%20println!(%0A%20%20%20%20%20%20%20%20%22%7B%7D%20%7B%7D%20%7B%7D%20%7B%7D%20%7B%7D%20%7B%7D%20%7B%7D%20%7B%7D%22%2C%0A%20%20%20%20%20%20%20%20x%2C%20a%2C%20b%2C%20c%2C%20bv%2C%20t.0%2C%20t.1%2C%20sentence%0A%20%20%20%20)%3B%0A%7D%0A | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| content_markdown: > | ||
| Rust are o varietate de tipuri de date familiare dumneavoastră: | ||
|
|
||
|
|
||
| * booleans - `bool` pentru a reprezenta adevărat și fals | ||
|
|
||
| * unsigned integers - `u8` `u16` `u32` `u64` `u128` pentru a reprezenta | ||
| numere nenegative întregi | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| * signed integers - `i8` `i16` `i32` `i64` `i128` pentru a reprezentare numere întregi | ||
|
|
||
| * pointer sized integers - `usize` `isize` pentru a reprezenta indexi | ||
|
|
||
| și dimensiunea lucrurilor în memorie | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| * floating point - `f32` `f64` pentru a reprezenta numere reale | ||
|
|
||
| * tuple (tuplu) - `(value, value, ...)` pentru trecerea unor secvențe fixe de valori pe stivă | ||
|
|
||
| * arrays - `[value, value, ...]` o colecție cu dimensiune fixă de elemente similare | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cunoscută la momentul compilării | ||
|
|
||
| * slices - o colecție cu dimensiune cunoscută în timpul rulării de elemente similare | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| * `str`(string slice) - text de lungime cunoscută în timpul rulării | ||
|
|
||
|
|
||
| Sintaxa s-ar putea să fie mai complexă în Rust față de alte limbaje de programare cu care sunteți obișnuit; | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| având în vedere că Rust este un limbaj de programare pentru sisteme, îi pasă de probleme legate | ||
|
|
||
| de memorie cu care s-ar putea să nu fiți obișnuit. O să aprofundăm aceste lucruri mai târziu. | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| Tipurile numerice pot fi impuse prin adăugarea la finalul unui număr (ex: `13u32`, `2u8`). | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - title: Conversia tipurile de bază | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20a%20%3D%2013u8%3B%0A%20%20%20%20let%20b%20%3D%207u32%3B%0A%20%20%20%20let%20c%20%3D%20a%20as%20u32%20%2B%20b%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20c)%3B%0A%0A%20%20%20%20let%20t%20%3D%20true%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20t%20as%20u8)%3B%0A%7D%0A | ||
| content_markdown: > | ||
| Rust are nevoie de explicitate când vine vorba de tipurile numerice. Nu puteți | ||
|
|
||
| folosi un `u8` pentru un `u32` în mod neglijent fără | ||
|
|
||
| apariția unei erori. | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| Din fericire, Rust poate face conversia de la un tip numeric la altul foarte ușor | ||
| folosind cuvântul cheie **as**. | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - title: Constante | ||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=const%20PI%3A%20f32%20%3D%203.14159%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20println!(%0A%20%20%20%20%20%20%20%20%22To%20make%20an%20apple%20%7B%7D%20from%20scratch%2C%20you%20must%20first%20create%20a%20universe.%22%2C%0A%20%20%20%20%20%20%20%20PI%0A%20%20%20%20)%3B%0A%7D%0A | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| content_markdown: > | ||
| Constantele ne permit să specificăm o valoare folosită uzual de-a lungul | ||
|
|
||
| codului nostru în mod eficient. În loc să copiem valori folosind variabile | ||
|
|
||
| acolo unde sunt folosite, constantele înlocuiesc direct numele lor cu | ||
| valoarea | ||
|
|
||
| lor acolo unde sunt folosite. | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| Spre deosebire de variabile, constantele vor fi mereu declarate cu tip de date specific. | ||
|
|
||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Numele constantelor sunt mereu scrise în format `SCREAMING_SNAKE_CASE` (ex: MY_FIRST_CONSTANT). | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - title: Array-uri | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20nums%3A%20%5Bi32%3B%203%5D%20%3D%20%5B1%2C%202%2C%203%5D%3B%0A%20%20%20%20println!(%22%7B%3A%3F%7D%22%2C%20nums)%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20nums%5B1%5D)%3B%0A%7D%0A | ||
| content_markdown: > | ||
| Un *array* este o **colecție de dimensiune fixă** de elemente care conțin date de același | ||
| tip. | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| Tipul de date pentru un *array* este scris sub forma `[T;N]`, unde T reprezintă tipul elementelor, iar N | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| reprezintă dimensiunea fixă cunoscută la momentul compilării. | ||
|
|
||
|
|
||
| Elemente individuale pot fi accesate cu ajutorul operatorului `[x]`, unde *x* este un | ||
| index *usize* (începând cu 0) al elementului pe care dorești să îl accesezi. | ||
|
|
||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Colecțiile cu dimensiune dinamică, deseori numite array-uri dinamice sau variabile, vă | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| vor fi prezentate într-un capitol viitor numit **Vectori**. | ||
| - title: Funcții | ||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20add(x%3A%20i32%2C%20y%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20return%20x%20%2B%20y%3B%0A%7D%0A%0Afn%20subtract(x%3A%20i32%2C%20y%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20x%20-%20y%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20println!(%2242%20%2B%2013%20%3D%20%7B%7D%22%2C%20add(42%2C%2013))%3B%0A%20%20%20%20println!(%2242%20-%2013%20%3D%20%7B%7D%22%2C%20subtract(42%2C%2013))%3B%0A%7D%0A | ||
| content_markdown: > | ||
| O funcție admite mai multe argumente sau deloc. | ||
|
|
||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| În acest exemplu, funcția *add* admite două argumente de tip `i32` | ||
| (signed integer cu dimensiune de 32 de biți). | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| Dacă vreți să returnați o valoare sau expresie, puteți folosi cuvântul cheie `return` | ||
| și punct și virgula la final, așa cum am făcut în funcția *subtract*. | ||
|
|
||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Numele funcțiilor sunt mereu scrise în format `snake_case`. | ||
|
|
||
|
|
||
| Hint: dacă definiți o funcție, datele pe care le admite se numesc parametrii. | ||
| Dacă folosiți o funcție și îi transmiteți niște date, atunci ele se numesc argumente. | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - title: Returnarea mai multor valori | ||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20swap(x%3A%20i32%2C%20y%3A%20i32)%20-%3E%20(i32%2C%20i32)%20%7B%0A%20%20%20%20return%20(y%2C%20x)%3B%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20%2F%2F%20return%20a%20tuple%20of%20return%20values%0A%20%20%20%20let%20result%20%3D%20swap(123%2C%20321)%3B%0A%20%20%20%20println!(%22%7B%7D%20%7B%7D%22%2C%20result.0%2C%20result.1)%3B%0A%0A%20%20%20%20%2F%2F%20destructure%20the%20tuple%20into%20two%20variables%20names%0A%20%20%20%20let%20(a%2C%20b)%20%3D%20swap(result.0%2C%20result.1)%3B%0A%20%20%20%20println!(%22%7B%7D%20%7B%7D%22%2C%20a%2C%20b)%3B%0A%7D%0A | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| content_markdown: > | ||
| Funcțiile pot returna mai multe valori prin returnarea unui **tuplu** (tuple) | ||
|
|
||
| de valori. | ||
|
|
||
|
|
||
| Elementele unui tuplu pot fi accesate folosind indexul acestora. (ex: my_tuple.0) | ||
|
|
||
|
|
||
| Rust suportă diferite tipuri de destructurări pe care le vom vedea în multe contexte, | ||
| permințându-ne | ||
|
|
||
| să extragem fracțiuni ale unor structuri de date în moduri ingenioase. Fiți pe fază! | ||
| - title: Returnarea | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| content_markdown: > | ||
| Dacă pentru o funcție nu se specifică ce tip returnează, aceasta va returna un tuplu gol, | ||
| cunoscut și sub numele de *unitate* (unit). | ||
|
|
||
|
|
||
| Un tuplu gol este reprezentat de `()`. | ||
|
|
||
|
|
||
| Folosirea unui `()` nu este des întâlnită, dar va apărea de suficiente ori, deci este bine să știți | ||
| ce se întâmplă. | ||
| code: >- | ||
| https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20make_nothing()%20-%3E%20()%20%7B%0A%20%20%20%20return%20()%3B%0A%7D%0A%0A%2F%2F%20the%20return%20type%20is%20implied%20as%20()%0Afn%20make_nothing2()%20%7B%0A%20%20%20%20%2F%2F%20this%20function%20will%20return%20()%20if%20nothing%20is%20specified%20to%20return%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20a%20%3D%20make_nothing()%3B%0A%20%20%20%20let%20b%20%3D%20make_nothing2()%3B%0A%0A%20%20%20%20%2F%2F%20Printing%20a%20debug%20string%20for%20a%20and%20b%0A%20%20%20%20%2F%2F%20Because%20it's%20hard%20to%20print%20nothingness%0A%20%20%20%20println!(%22The%20value%20of%20a%3A%20%7B%3A%3F%7D%22%2C%20a)%3B%0A%20%20%20%20println!(%22The%20value%20of%20b%3A%20%7B%3A%3F%7D%22%2C%20b)%3B%0A%7D%0A | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - title: Capitolul 1 - ÃŽncheiere | ||
| content_markdown: > | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Până acu', e bine! Bazele Rust-ului nu sunt așa de rele, nu-i așa? Am | ||
|
|
||
| aruncat o privire modului în care gândește compilatorul de Rust. Fiind un limbaj de programare | ||
| pentru sisteme | ||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| acesta ține mult la dimensiunea valorilor în memorie, fie că pot fi | ||
| modificate sau nu, | ||
|
|
||
| și la corectitudinea matematicii pe care o aplicați. În cele ce urmează, ne vom | ||
| întâlni cu niște vechi prieteni: | ||
|
|
||
| teste `if` și bucle `for`. | ||
|
|
||
|
|
||
| Mai multe resurse: | ||
|
|
||
RaresCon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| * [Youtube: Rust Cast - A deeper dive on Rust's primitive number | ||
| types](https://www.youtube.com/watch?v=n5TRBkbystY) | ||
|
|
||
| * [Website: Rust Book 2018 - A deeper description on basic data | ||
| types](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch03-02-data-types.html) | ||
|
|
||
| * [Website: Rust Cheat Sheet - Data Types](https://cheats.rs/#basic-types) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.