Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 8eff640

Browse files
committed
Bit more work on the FAQ
1 parent c181d15 commit 8eff640

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

it-IT/faq.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -798,73 +798,78 @@ Sono basati su una serie di articoli accademici che possono essere trovati nel [
798798
Perché la sintassi dei campi di esistenza é fatta cosí?
799799
</a></h3>
800800

801-
The `'a` syntax comes from the ML family of programming languages, where `'a` is used to indicate a generic type parameter. For Rust, the syntax had to be something that was unambiguous, noticeable, and fit nicely in a type declaration right alongside traits and references. Alternative syntaxes have been discussed, but no alternative syntax has been demonstrated to be clearly better.
801+
La sintassi `'a` proviene dalla famiglia ML di linguaggi di programmazione, dove `'a` viene utilizzato per indicare un parametro di tipo generico.
802+
In Rust, la sintassi doveva rappresentare qualcosa di univoco, chiaramente visibile e integrato con le altre dichiarazioni dei tipi insieme ai vari tratti e riferimenti.
803+
Sono state prese in considerazione anche altre scelte ma nessuna sintassi alternativa si é dimostrata chiaramente migliore.
802804

803805
<h3><a href="#how-do-i-return-a-borrow-to-something-i-created-from-a-function" name="how-do-i-return-a-borrow-to-something-i-created-from-a-function">
804806
Come posso ritornare un prestito a qualcosa che ho creato in una funzione?
805807
</a></h3>
806808

807-
You need to ensure that the borrowed item will outlive the function. This can be done by binding the output lifetime to some input lifetime like so:
809+
Devi assicurarti che il campo di esistenza del valore prestato sia piú lungo di quello della funzione.
810+
Puoi ottenere questo effetto puoi assegnare il campo di esistenza dell'uscita a quello di un parametro di ingresso come qui:
808811

809812
```rust
810-
type Pool = TypedArena<Thing>;
813+
type Gruppo = TypedArena<Cosa>;
811814

812-
// (the lifetime below is only written explicitly for
813-
// expository purposes; it can be omitted via the
814-
// elision rules described in a later FAQ entry)
815-
fn create_borrowed<'a>(pool: &'a Pool,
815+
// (Il campo di esistenza sotto é esplicitato esclusivamente
816+
/// per facilitarne la comprensione; esso puó essere omesso
817+
// tramite le regole di elisione consultabili in un'altra
818+
// risposta presente in questa pagina)
819+
820+
fn crea_prestato<'a>(gruppo: &'a Gruppo,
816821
x: i32,
817-
y: i32) -> &'a Thing {
818-
pool.alloc(Thing { x: x, y: y })
822+
y: i32) -> &'a Cosa {
823+
gruppo.alloc(Cosa { x: x, y: y })
819824
}
820825
```
821826

822-
An alternative is to eliminate the references entirely by returning an owning type like [`String`][String]:
827+
Un'alternativa é eliminare interamente il riferimento ritornando un valore posseduto come [`String`][String]:
823828

824829
```rust
825-
fn happy_birthday(name: &str, age: i64) -> String {
826-
format!("Hello {}! You're {} years old!", name, age)
830+
fn buon_compleanno(nome: &str, eta: i64) -> String {
831+
format!("Ciao {}! Hai {} anni!", nome, eta)
827832
}
828833
```
829834

830-
This approach is simpler, but often results in unnecessary allocations.
835+
Questo approccio é piú semplice ma spesso genera allocazioni in memoria non necessarie.
831836

832837
<h3><a href="#when-are-lifetimes-required-to-be-explicit" name="when-are-lifetimes-required-to-be-explicit">
833838
Perché alcuni riferimenti hanno un campo di esistenza, come <code>&amp;'a T</code> e altri no, tipo <code>&amp;T</code>?
834839
</a></h3>
835840

836-
In fact, *all* reference types have a lifetime, but most of the time you do not have to write
837-
it explicitly. The rules are as follows:
841+
In realtá, *tutti* i riferimenti hanno un campo di esistenza ma nella maggior parte dei casi non
842+
ti devi preoccupare di gestirlo esplicitamente. Le regole sono le seguenti:
838843

839-
1. Within a function body, you never have to write a lifetime explicitly; the correct value
840-
should always be inferred.
841-
2. Within a function *signature* (for example, in the types of its
842-
arguments, or its return type), you *may* have to write a lifetime
843-
explicitly. Lifetimes there use a simple defaulting scheme called
844-
["lifetime elision"](https://doc.rust-lang.org/book/lifetimes.html#lifetime-elision),
845-
which consists of the following three rules:
846-
- Each elided lifetime in a function’s arguments becomes a distinct lifetime parameter.
847-
- If there is exactly one input lifetime, elided or not, that
848-
lifetime is assigned to all elided lifetimes in the return values
849-
of that function.
850-
- If there are multiple input lifetimes, but one of them is &self
851-
or &mut self, the lifetime of self is assigned to all elided
852-
output lifetimes.
853-
3. Finally, in a `struct` or `enum` definition, all lifetimes must be explicitly declared.
844+
1. Nel corpo di una funzione non devi mai specificare un campo di esistenza esplicitamente;
845+
il valore corretto dovrebbe essere sempre dedotto correttamente.
846+
2. Nella *dichiarazione* di una funzione (ad esempio, nei tipi dei suoi parametri
847+
o il suo tipo di ritorno), *potresti* dover specificare un campo di esistenza manualmente.
848+
I campi di esistenza in questo contesto utilizzano un semplice metodo chiamato
849+
["elisione del campo di esistenza"](https://doc.rust-lang.org/book/lifetimes.html#lifetime-elision),
850+
che a sua volta consiste in queste tre regole:
851+
- Ciascun campo di esistenza eliso nei parametri di una funzione diviene un campo di esistenza distinto.
852+
- Se vi é esattamente un singolo campo di esistenza in ingresso, eliso o no, quel campo di esistenza
853+
viene assegnato a tutti i campi di esistenza elisi utilizzati per i valori di ritorno di quella funzione.
854+
- Se ci sono piú campi di esistenza in ingresso ma uno di quelli é un `&self` o un `&mut self`, il campo di esistenza
855+
di `self` viene assegnato a tutti i campi di esistenza di uscita.
856+
3. Se si sta definendo una `struct` o `enum` i campi di esistenza sono da dichiarare espressamente.
854857

855-
If these rules result in compilation errors, the Rust compiler will provide an error message indicating the error caused, and suggesting a potential solution based on which step of the inference process caused the error.
858+
Se queste regole danno origine a un errore di compilazione, il compilatore di Rust fornirá un messaggio di errore indicante l'errore e anche una potenziale soluzione basata sugli algoritmi di deduzione.
856859

857860
<h3><a href="#how-can-rust-guarantee-no-null-pointers" name="how-can-rust-guarantee-no-null-pointers">
858861
Come puó Rust garantire l'assenza di "puntatori nulli" e "puntatori sospesi"?
859862
</a></h3>
860863

861-
The only way to construct a value of type `&Foo` or `&mut Foo` is to specify an existing value of type `Foo` that the reference points to. The reference "borrows" the original value for a given region of code (the lifetime of the reference), and the value being borrowed from cannot be moved or destroyed for the duration of the borrow.
864+
L'unico modo di creare un valore `&Cosa` or `&mut Cosa` é di specificare un valore preesistente di tipo `Coso` a cui la referenza deve fare riferimento.
865+
Il riferimento in questo modo ottiene in prestito il valore originale per un determinato blocco di codice(il campo di esistenza del riferimento) e il valore prestato non puó essere spostato o distrutto per tutta la durata del prestito.
862866

863867
<h3><a href="#how-do-i-express-the-absense-of-a-value-without-null" name="how-do-i-express-the-absense-of-a-value-without-null">
864868
Come faccio a indicare l'assenza di un valore senza utilizzare <code>null</code>?
865869
</a></h3>
866870

867-
You can do that with the [`Option`][Option] type, which can either be `Some(T)` or `None`. `Some(T)` indicates that a value of type `T` is contained within, while `None` indicates the absence of a value.
871+
Puoi fare ció con il tipo [`Option`][Option] che puó alternativamente essere `Some(T)` o `None`.
872+
`Some(T)` indica che un valore di tipo `T` é contenuto all'interno, mentre `None` ne indica l'assenza.
868873

869874
<h2 id="generics">Generici</h2>
870875

0 commit comments

Comments
 (0)