Skip to content

Instantly share code, notes, and snippets.

@gusdelact
Created January 25, 2024 07:53
Show Gist options
  • Save gusdelact/a4dfae95ec74c3fbb6dda443126f2d98 to your computer and use it in GitHub Desktop.
Save gusdelact/a4dfae95ec74c3fbb6dda443126f2d98 to your computer and use it in GitHub Desktop.
#[derive(Debug,Clone)]
struct Estr01
{
a : i32,
b : char,
s: String
}
#[derive(Debug,Clone)]
struct Estr02<'a>
{
a: &'a i32,
c: &'a char
}
#[derive(Debug,Clone)]
struct Estr03<'b> {
e01: &'b Estr01
}
fn f1(mut x:i32)
{
x = x +1;
}
fn f2(mut s: String)
{
let c='a';
s.push(c);
println!("{}", s);
}
fn f3( s:&mut String)
{
let c='z';
s.push(c);
println!("{}", s);
}
fn f4(e:Estr01)
{
println!("{:?}",e);
}
fn f5(mut e:Estr01)
{
e.s = String::from("f5");
f4(e);
}
fn f6(e: &mut Estr01)
{
e.s = String::from("f6");
}
fn main()
{
let mut x =2;
f1(x);
println!("{}",x);
x=x-1;
let cadena = String::from("hola cadena");
f2(cadena.clone());
println!("{}",cadena);
let mut cadena2 = String::from("hola cadena");
f3(&mut cadena2);
println!("{}",cadena2);
let mut e1 = Estr01{a:2,b:'x',s:String::from("hola cadena")};
println!("{:?}",e1);
e1.s = String::from("hola cadena2");
println!("{:?}",e1);
f4(e1);
let mut e2 = Estr01{a:2,b:'x',s:String::from("hola cadena")};
f5(e2.clone());
println!("{:?}",e2);
let mut e3 = Estr01{a:2,b:'x',s:String::from("hola cadena")};
f6(&mut e3);
e3.a = 3;
println!("{:?}",e3);
let mut x0=1;
let ch0='b';
let mut e4 = Estr02{ a:&x0,c: &ch0};
println!("{:?}",e4);
println!("{:?}",e4.a+1);
let mut e5 = Estr01{a:100,b:'d',s:String::from("una cadena")};
let mut e6 = Estr03{e01:&e5};
println!("{:?}",e6);
let mut e5_1 =e5.clone();
e5_1.a = e5.a+1;
e5_1.b='m';
e6.e01 = &e5_1;
println!("{:?}",e6);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment