This file contains hidden or 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
extern crate reqwest; | |
use serde::{Deserialize}; | |
#[derive(Debug)] | |
#[derive(Deserialize)] | |
struct Information { | |
city: String, | |
country: String | |
} |
This file contains hidden or 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
{ | |
"as": "AS28126 BRISANET SERVICOS DE TELECOMUNICACOES LTDA", | |
"city": "Jaguaribe", | |
"country": "Brazil", | |
"countryCode": "BR", | |
"isp": "Brisanet Servicos De Telecomunicacoes Ltda", | |
"lat": -6.05537, | |
"lon": -38.506, | |
"org": "Brisanet Servicos De Telecomunicacoes Ltda", | |
"query": "187.19.230.194", |
This file contains hidden or 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)] | |
struct User { | |
username: String, | |
email: String, | |
active: bool, | |
} | |
fn main() { | |
let user = build_user( |
This file contains hidden or 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
struct NormalStruct { | |
a: i32, | |
b: i32, | |
} | |
fn main() { | |
let ns = NormalStruct { a: 1, b: 2 }; | |
// Destructure | |
let NormalStruct { a, b } = ns; |
This file contains hidden or 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
struct Tuplestruct(i32, i32); | |
fn main() { | |
let number = Tuplestruct(10, 20); | |
// Destructure | |
let Tuplestruct(x, y) = number; | |
println!("x: {}, y: {}", x, y); | |
} |
This file contains hidden or 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 texto = String::from("texto"); | |
let texto_2 = &mut texto; | |
let texto_3 = &mut texto; | |
} | |
/* | |
error[E0499]: cannot borrow `texto` as mutable more than once at a time | |
--> main.rs:4:22 |
This file contains hidden or 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 pesquisar = String::from("google"); | |
modifica(&mut pesquisar); | |
print!("Pesquisa: {}", pesquisar); | |
} | |
fn modifica(texto: &mut String) { |
This file contains hidden or 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 texto = String::from("google"); | |
calcula_tamanho(&texto); | |
} | |
fn calcula_tamanho(texto: &String) { | |
texto.push_str(" vou pesquisar"); | |
} |
This file contains hidden or 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 texto = String::from("google"); | |
let tamanho = calcula_tamanho(&texto); | |
println!("O texto é: '{}' de tamanho {}.", texto, tamanho); | |
} | |
fn calcular(texto: &String) -> usize { | |
texto.len() |
This file contains hidden or 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 x1 = retorna_string(); | |
let x2 = x1.clone(); | |
println!("x1: {}, x2: {}", x1, x2); | |
} | |
fn retorna_string() -> String { | |
return String::from("olá"); | |
} |