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
use std::fmt; | |
#[derive(Debug)] | |
struct Dato { | |
campo : u32 | |
} | |
#[derive(Debug)] | |
struct Estructura { | |
cadena : String, |
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 llenar(dato : &mut u8) { | |
*dato = 0x20; | |
} | |
fn recorrer(arr: &[u8]) { | |
let mut i=0; | |
while i < arr.len() { | |
print!(" {} ", arr[i]); | |
i = i + 1; |
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 f01(par01: (String, bool)) -> (bool,String) { | |
println!("{:p}",&par01); | |
(par01.1, par01.0) | |
} | |
fn main() { | |
let ntuple = (1,3.1459,"gustavo", 1E6, 1E-6 , 'a',true,0.51); | |
let btuple = ("gus".to_string(), true); | |
println!("{:p}",&btuple); |
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
#![allow(dead_code)] | |
use crate::Lista::*; | |
use std::fmt; | |
enum Lista { | |
Nodo(u32, Box<Lista>), | |
Nil, | |
} | |
impl Lista { |
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 main() { | |
let mut i=0; | |
loop { | |
i = i + 1; | |
if i>100 { | |
break; | |
} | |
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 main() { | |
//uso de referencias y apuntadores | |
let mut valor = 4; | |
let ref mut referencia = valor; | |
println!("{} {:p} {}",referencia,referencia,*referencia); | |
//println!("{}", referencia == ptr); | |
*referencia = 6; | |
println!("{} {:p} {}",referencia,referencia,*referencia); |
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; |
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
#[derive(Debug)] | |
enum Expr { | |
Const(f64), | |
Sum(f64, f64), | |
Product(f64, f64), | |
Quotient(f64, f64) | |
} | |
fn interpretar(expresion: Expr) -> f64 { | |
match expresion { | |
Expr::Const(valor) => valor, |
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
#[derive(Debug)] | |
enum Lista<'a> { | |
Cons { dato: u32, siguiente : &'a Lista<'a> } , | |
Nil | |
} | |
impl<'a> Lista<'a> { | |
fn new() -> Lista<'a> { |
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
//En Rust, si hay una diferencia entre declarar una estructura | |
//que implementa los trait Copy y Clone | |
//este ejemplo usarlo sin quitar comentarios o poniendo comentarios | |
struct Estructura { | |
campo01 : u32, | |
campo02 : f64, | |
} |
OlderNewer