@jack https://github.com/1wErt3r/billy Billy: Your Bitcoin Node Assistant ๐งโโ๏ธ
shymeander
npub1xj5h...5s8g
// src/main.rs
use derive_builder::Builder;
#[derive(Builder)]
struct BigBoss {
name: String,
rank: String,
alias: Option<String>,
birth_date: String,
}
fn main() {
let mister_rabbit = BigBoss::builder()
.name("Big Boss".into())
// Big Boss is a Commander in the military
.rank("Commander".into())
// Big Boss has an alternate name "Mister Rabbit"
.alias(Some("Mister Rabbit".into()))
.birth_date("1970-05-05".into())
.build()
.unwrap();
println!("{:?}", mister_rabbit);
}
```rust
fn main() {
// Variables (immutable by default)
let x = 5;
let mut y = 1; // mutable
// Types
let i: i32 = 42; // integers
let f: f64 = 3.14; // float
let b: bool = true;
let s: String = String::from("hello");
let slice: &str = "world";
// Vec (dynamic array)
let mut v: Vec<i32> = vec![1, 2, 3];
v.push(4);
// Ownership & Borrowing
let s1 = String::from("mine");
let s2 = &s1; // borrow (reference)
println!("{} {}", s1, s2);
// Pattern Matching
match x {
1 => println!("one"),
2..=5 => println!("2-5"),
_ => println!("other"),
}
// Option & Result for safety
let opt: Option<i32> = Some(42);
if let Some(n) = opt {
println!("{}", n);
}
// Structs & Impl
struct Point { x: i32, y: i32 }
impl Point {
fn new(x: i32, y: i32) -> Self {
Point { x, y }
}
}
// Traits (interfaces)
trait Shape {
fn area(&self) -> f64;
}
// Closures
let add = |a, b| a + b;
// Iterators
let sum: i32 = (1..=5).sum();
}
```
https://github.com/1wErt3r/hyper-uppercut Building this bot to learn rust and #nostr
https://github.com/1wErt3r/nostrsss I'm learning Rust with nostr. Is ENV heavy config like this annoying?
Hello nostr.