feat: restart
fix: error handling build: optimization and forbid unsafe
This commit is contained in:
parent
390e600060
commit
04f22c2763
2 changed files with 162 additions and 81 deletions
|
@ -8,6 +8,11 @@ strip = "symbols"
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
overflow-checks = true
|
overflow-checks = true
|
||||||
lto = true
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
unsafe_code = "forbid"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
96
src/main.rs
96
src/main.rs
|
@ -6,23 +6,75 @@ const RESOURCE_COUNT:usize = 3;
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
|
|
||||||
|
let mut restart:bool = true;
|
||||||
|
while restart
|
||||||
|
{
|
||||||
println!("Max A Resource");
|
println!("Max A Resource");
|
||||||
let mut a:String = String::new();
|
let a:u8;
|
||||||
io::stdin().read_line(&mut a).unwrap();
|
let b:u8;
|
||||||
let a:u8 = a.trim().parse().unwrap();
|
let c:u8;
|
||||||
|
let mut resource_input:String = String::new();
|
||||||
|
if let Err(err_val) = io::stdin().read_line(&mut resource_input)
|
||||||
|
{
|
||||||
|
println!("Failed to Read: {}", err_val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
match resource_input.trim().parse::<u8>()
|
||||||
|
{
|
||||||
|
Ok(value) =>
|
||||||
|
{
|
||||||
|
a = value;
|
||||||
|
}
|
||||||
|
Err(err_val) =>
|
||||||
|
{
|
||||||
|
println!("Failed to Convert: {}", err_val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Max B Resource");
|
println!("Max B Resource");
|
||||||
let mut b:String = String::new();
|
let mut resource_input:String = String::new();
|
||||||
io::stdin().read_line(&mut b).unwrap();
|
if let Err(err_val) = io::stdin().read_line(&mut resource_input)
|
||||||
let b:u8 = b.trim().parse().unwrap();
|
{
|
||||||
|
println!("Failed to Read: {}", err_val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
match resource_input.trim().parse::<u8>()
|
||||||
|
{
|
||||||
|
Ok(value) =>
|
||||||
|
{
|
||||||
|
b = value;
|
||||||
|
}
|
||||||
|
Err(err_val) =>
|
||||||
|
{
|
||||||
|
println!("Failed to Convert: {}", err_val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Max C Resource");
|
println!("Max C Resource");
|
||||||
let mut c:String = String::new();
|
let mut resource_input:String = String::new();
|
||||||
io::stdin().read_line(&mut c).unwrap();
|
if let Err(err_val) = io::stdin().read_line(&mut resource_input)
|
||||||
let c:u8 = c.trim().parse().unwrap();
|
{
|
||||||
|
println!("Failed to Read: {}", err_val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
match resource_input.trim().parse::<u8>()
|
||||||
|
{
|
||||||
|
Ok(value) =>
|
||||||
|
{
|
||||||
|
c = value;
|
||||||
|
}
|
||||||
|
Err(err_val) =>
|
||||||
|
{
|
||||||
|
println!("Failed to Convert: {}", err_val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
println!("\n\tA = {}\n\tB = {}\n\tC = {}", a,b,c);
|
println!("\n\tA = {}\n\tB = {}\n\tC = {}", a,b,c);
|
||||||
if a <= 0 || b <= 0 || c <= 0
|
if a == 0 || b == 0 || c == 0
|
||||||
{
|
{
|
||||||
println!("Exit: Zero as a Input Invalid");
|
println!("Exit: Zero as a Input Invalid");
|
||||||
return;
|
return;
|
||||||
|
@ -108,6 +160,30 @@ fn main() {
|
||||||
{
|
{
|
||||||
println!("P{}", info.1[i]);
|
println!("P{}", info.1[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let mut resource_input:String = String::new();
|
||||||
|
println!("Press 'r' to Restart");
|
||||||
|
if let Err(err_val) = io::stdin().read_line(&mut resource_input)
|
||||||
|
{
|
||||||
|
println!("Failed to Read: {}", err_val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resource_input = resource_input.trim().to_string();
|
||||||
|
match resource_input.as_str()
|
||||||
|
{
|
||||||
|
"r" =>
|
||||||
|
{
|
||||||
|
restart = true;
|
||||||
|
println!("-------------------------------");
|
||||||
|
}
|
||||||
|
_ =>
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_matrix(matrix:[[u8;RESOURCE_COUNT];PROCESS_COUNT])
|
fn print_matrix(matrix:[[u8;RESOURCE_COUNT];PROCESS_COUNT])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue