Skip to the content ForoHackers
Log inJoin

Rust E0382: borrow of moved value. ¿Qué se ha llevado el bucle?

DebuggingRustToolchains and linkers
#16039 · · Quote · Report

Rust me regaña con E0382, borrow of moved value. let nombres = vec![String::from("Lola"), String::from("Pili")]; Luego for n in nombres { println!("{n}"); } y después println!("{}", nombres.len());. ¿A quién se le han mudado dos señoras por decir sus nombres en voz alta?

#16179 · · Quote · Report

cloná todo, che. por dos Lolas no nos vamos a poner a revisar la Constitución.

#16180 · · Quote · Report

The loop asks for an iterator over nombres by value. The Vec is consumed and yields owned Strings. Later you're asking the old binding for its length. Do you need the loop to OWN a name in order to print it?

#16182 · · Quote · Report

Pues no. for n in &nombres compila y después dice 2. He ahí a mis dos señoras, vivas y con su misma ortografía.

#16183 · · Quote · Report

y si mañana viene mi jefa y dice que hay que sacar los nombres EN MAYÚSCULA, ¿reabrimos el comité de copiado de señoras?

#16184 · · Quote · Report

Para mostrarlos en mayúscula puedo formar el texto de salida sin que dejen de llamarse así en la lista. Otra cosa es que me pidas editar la lista que ya existe. ¿Qué pidió tu jefa de verdad?

#16185 · · Quote · Report

me lo acabo de inventar, po. pero la jefa es real y a ti eso te pasa por contestar a los requisitos.

#16187 · · Quote · Report

If the next step's purpose is to take ownership and build another collection, consuming the original can be exactly right. Cloning just to silence this compiler error buys a second set of strings nobody asked to feed.

#16188 · · Quote · Report

retiro la moción de clonar por pereza. me quedo la de clonar por si Lola quiere irse de vacaciones mientras el otro ejemplar curra.

#16197 · · Quote · Report

Al final otro módulo SÍ consume la lista para repartir los nombres. Dejé el informe con préstamo antes, el reparto con propiedad después. No hacen falta cuatro señoras para mandarle una carta a dos.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply