Skip to content

Commit b390d36

Browse files
committed
Initiated a io samples
1 parent 7800391 commit b390d36

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[workspace]
2-
members = ["Lesson_00", "Lesson_01", "Lesson_02", "Lesson_03", "Lesson_04", "Lesson_05", "Lesson_06", "Lesson_07", "Lesson_08", "collector", "drone-lab", "mocking", "sysco", "sysco2"]
2+
members = ["Lesson_00", "Lesson_01", "Lesson_02", "Lesson_03", "Lesson_04", "Lesson_05", "Lesson_06", "Lesson_07", "Lesson_08", "collector", "drone-lab", "fops", "mocking", "sysco", "sysco2"]
33

44
resolver = "2"

fops/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "fops"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]

fops/src/game.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[derive(Debug)]
2+
pub struct Game {
3+
title: String,
4+
release_year: u16,
5+
genre: String,
6+
}

fops/src/io_ops.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::io;
2+
use std::io::{Write, stdout};
3+
/*
4+
Bu fonksiyon stdin yardımıyla bilgi okur.
5+
Örneğin terminalden oyun bilgisi girilebilir.
6+
Metot geriye io modülünde yer alan Result türünden bir değer döndürür.
7+
*/
8+
pub fn read_game_from_stdin() -> io::Result<String> {
9+
let mut input = String::new();
10+
println!("Sevdiğin bilgisayar oyunlarından birisinin adını girer misin?");
11+
io::stdin().read_line(&mut input)?;
12+
Ok(input.trim().to_string())
13+
}
14+
15+
/*
16+
Bu fonksiyon parametre olarak gelen String array'in içeriği
17+
stdout'a aktarır. Örnekte bu println ile ekrana yazdırmaktır.
18+
*/
19+
pub fn print_games_to_stdout(games: &[String]) {
20+
println!("--- En Sevdiğin Oyunlar ---");
21+
22+
stdout().write_all(games.join("\n").as_bytes()).unwrap();
23+
}

fops/src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::io_ops::*;
2+
3+
mod game;
4+
mod io_ops;
5+
6+
fn main() -> std::io::Result<()> {
7+
let mut classic_games = vec![
8+
"Pac-Man (1980)".to_string(),
9+
"Galaga (1981)".to_string(),
10+
"Donkey Kong (1981)".to_string(),
11+
"Tetris (1984)".to_string(),
12+
];
13+
14+
let new_game = read_game_from_stdin()?;
15+
classic_games.push(new_game);
16+
print_games_to_stdout(&classic_games);
17+
18+
Ok(())
19+
}

0 commit comments

Comments
 (0)