Skip to content

Instantly share code, notes, and snippets.

extern crate reqwest;
use serde::{Deserialize};
#[derive(Debug)]
#[derive(Deserialize)]
struct Information {
city: String,
country: String
}
{
"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",
#[derive(Debug)]
struct User {
username: String,
email: String,
active: bool,
}
fn main() {
let user = build_user(
struct NormalStruct {
a: i32,
b: i32,
}
fn main() {
let ns = NormalStruct { a: 1, b: 2 };
// Destructure
let NormalStruct { a, b } = ns;
struct Tuplestruct(i32, i32);
fn main() {
let number = Tuplestruct(10, 20);
// Destructure
let Tuplestruct(x, y) = number;
println!("x: {}, y: {}", x, y);
}
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
fn main() {
let mut pesquisar = String::from("google");
modifica(&mut pesquisar);
print!("Pesquisa: {}", pesquisar);
}
fn modifica(texto: &mut String) {
fn main() {
let texto = String::from("google");
calcula_tamanho(&texto);
}
fn calcula_tamanho(texto: &String) {
texto.push_str(" vou pesquisar");
}
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()
fn main() {
let x1 = retorna_string();
let x2 = x1.clone();
println!("x1: {}, x2: {}", x1, x2);
}
fn retorna_string() -> String {
return String::from("olá");
}