Skip to content

Commit

Permalink
Merge pull request #66 from monoald/main
Browse files Browse the repository at this point in the history
Complete sentence and translate code comments in chapter 4
  • Loading branch information
Phosphorus-M authored May 10, 2024
2 parents 2b0787a + 055b20a commit bcba4d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ fn first_word(s: &String) -> usize {
fn main() {
let mut s = String::from("hello world");

let word = first_word(&s); // word will get the value 5
let word = first_word(&s); // word obtendrá el valor 5

s.clear(); // this empties the String, making it equal to ""
s.clear(); // esto "vacía" el String, dejando s igual a ""

// word still has the value 5 here, but there's no more string that
// we could meaningfully use the value 5 with. word is now totally invalid!
// word aún tiene el valor 5 aquí, pero ya no hay un string para que
// usar el valor 5 tenga sentido, ¡word es totalmente invalida!
}
// ANCHOR_END: here
12 changes: 6 additions & 6 deletions listings/ch04-understanding-ownership/listing-04-09/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ fn first_word(s: &str) -> &str {
fn main() {
let my_string = String::from("hello world");

// `first_word` works on slices of `String`s, whether partial or whole
// `first_word` funciona con slices de un string, sean parciales o completos.
let word = first_word(&my_string[0..6]);
let word = first_word(&my_string[..]);
// `first_word` also works on references to `String`s, which are equivalent
// to whole slices of `String`s
// `first_word` también funciona con referencias de un string, que son equivalentes
// a un slice completo de un String
let word = first_word(&my_string);

let my_string_literal = "hello world";

// `first_word` works on slices of string literals, whether partial or whole
// `first_word` funciona con slices de string literales, sean parciales o completos
let word = first_word(&my_string_literal[0..6]);
let word = first_word(&my_string_literal[..]);

// Because string literals *are* string slices already,
// this works too, without the slice syntax!
// Por que los strings literales son slices de strings,esto también funciona,
// sin necesidad de usar la sintaxis de slices.
let word = first_word(my_string_literal);
}
// ANCHOR_END: usage
4 changes: 2 additions & 2 deletions src/ch04-02-references-and-borrowing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ puntero, una referencia garantiza que apunte a un valor válido de un tipo
particular para la vida de esa referencia.

Aquí está cómo definirías y usarías una función `calcular_longitud` que tiene
una referencia a un objeto como parámetro en lugar de tomar la propiedad del
una referencia a un objeto como parámetro en lugar de tomar la propiedad del valor.

<span class="filename">Nombre de archivo: src/main.rs</span>

Expand Down Expand Up @@ -49,7 +49,7 @@ La sintaxis `&s1` nos permite crear una referencia que *se refiere* al valor de
descartará cuando la referencia deje de usarse.

Del mismo modo, la firma de la función usa `&` para indicar que el tipo del
parámetro `s` es una referencia. Vamos a agregar algunas anotaciones
parámetro `s` es una referencia. Vamos a agregar algunas anotaciones:

```rust
{{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs:here}}
Expand Down

0 comments on commit bcba4d4

Please sign in to comment.