start rust

This commit is contained in:
death916 2026-03-04 04:04:27 -08:00
parent 3ca4b2bd25
commit c3923a984e
3 changed files with 4248 additions and 0 deletions

4147
rust/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

8
rust/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2024"
[dependencies]
chrono = "0.4.44"
iced = "0.14.0"

93
rust/src/main.rs Normal file
View file

@ -0,0 +1,93 @@
use iced;
fn main() {
struct State {
current_time: chrono::DateTime<chrono::Utc>,
next_alarm: Option<chrono::DateTime<chrono::Utc>>,
news: Vec<String>,
weather: String,
location: String,
scores: Vec<Scores>,
}
#[derive(Debug)]
enum League {
NBA(NbaScores),
NFL(Vec<String>),
MLB(Vec<String>),
}
#[derive(Debug)]
struct Scores {
nba: League,
nfl: League,
mlb: League,
}
#[derive(Debug)]
struct NbaScores {
teams: Vec<String>,
team1: String,
team2: String,
score1: String,
score2: String,
}
impl Scores {
fn new() -> Self {
Scores {
nba: League::NBA(NbaScores {
teams: Vec::new(),
team1: String::new(),
team2: String::new(),
score1: String::new(),
score2: String::new(),
}),
nfl: League::NFL(Vec::new()),
mlb: League::MLB(Vec::new()),
}
}
}
let mut scores = Scores::new();
let state = State {
current_time: chrono::Utc::now(),
next_alarm: None,
news: Vec::new(),
weather: String::new(),
location: String::new(),
scores: Vec::new(),
};
let mut state = state;
state.current_time = chrono::Utc::now();
state.next_alarm = Some(chrono::Utc::now() + chrono::Duration::hours(1));
state.news.push("Breaking news!".to_string());
state.weather = "Sunny".to_string();
state.location = "Sacramento".to_string();
scores.nba = League::NBA(NbaScores {
teams: vec![
"Team A vs Team B".to_string(),
"Team C vs Team D".to_string(),
],
team1: "Team A".to_string(),
team2: "Team B".to_string(),
score1: "100".to_string(),
score2: "95".to_string(),
});
state.scores.push(scores);
println!("{:?}", state.current_time);
println!("{:?}", state.scores);
println!("{:?}", state.scores[0].nba);
}