Last active
October 13, 2019 08:37
-
-
Save gusdelact/aa2d1a1a96656e468d6158b92fb9114b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn fn01<'a>(par01: &'a str, par02: &'a str) -> &'a str { | |
if par01.len() > par02.len() { | |
par01 | |
} else { | |
par02 | |
} | |
} | |
fn fn02<'a> (par01: &'a mut u32,par02: &'a u32) -> (&'a u32, &'a u32) { | |
let var01 = *par01 + 5u32; | |
*par01= var01 + *par02; | |
(par01,par02) | |
} | |
struct Nodo(i32); | |
impl Nodo { | |
fn add_one(& mut self) { self.0 += 1; } | |
fn print(& self) { | |
println!("`print`: {}", self.0); | |
} | |
} | |
#[derive(Debug)] | |
struct Apuntadores<'a> { | |
x: &'a u32, | |
y: &'a u32, | |
} | |
impl<'a> Default for Apuntadores<'a> { | |
fn default() ->Self { | |
Self { | |
x : &0, | |
y : &0, | |
} | |
} | |
} | |
#[derive(Debug)] | |
struct ReferenciaEntera<'a> (&'a i32); | |
#[derive(Debug)] | |
struct ReferenciaGenerica<'a,T: 'a> (&'a T); | |
fn main() { | |
let r: & i32; | |
let y = 10; | |
r = &y; | |
let s = { | |
let x = r; | |
*x | |
}; | |
println!("{}", s); | |
println!("{}", r); | |
let _cadena = fn01("hola", "adios"); | |
let mut z:u32=10; | |
let w:u32=20; | |
let u=fn02(&mut z,&w); | |
println!("{} {}",u.0,u.1); | |
let mut nodito = Nodo(5); | |
nodito.add_one(); | |
nodito.print(); | |
println!("{:?}" ,Apuntadores{x:&z,y:&w} ); | |
let apuntas:Apuntadores = Default::default(); | |
println!("{:?}" ,apuntas ); | |
let d:i32= 15; | |
let re=ReferenciaEntera(&d); | |
println!("{:?}" ,re ); | |
let cadena02= "hola".to_string(); | |
let rege=ReferenciaGenerica(&cadena02); | |
println!("{:?}" ,rege ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment