fn main() {
    let s1 = String::from("hello");
    let s2 = s1; // Ownership of s1 is moved to s2

    println!("{}", s1); // This would cause an error because s1 is no longer valid
}
 
by

Rust Online Compiler

Write, Run & Share Rust code online using OneCompiler's Rust online compiler for free. It's one of the robust, feature-rich online compilers for Rust language. Getting started with the OneCompiler's Rust editor is easy and fast. The editor shows sample boilerplate code when you choose language as Rust and start coding.