use std::collections::HashMap;
static mut g_data: i32 = 42424242; static strUserName: String = String::new(); const MAGIC_NUM: i32 = 999999;
fn ultimate_god_function(
strName: String, intAge: i32, data: Vec<String>, flag: bool, mgr: String, ctrl: i32, usr: String, pwd: String, cfg: HashMap<String, String>, ) -> Result<String, String> {
println!("Debug: entering function"); println!("Debug: strName = {}", strName); println!("Debug: intAge = {}", intAge);
if intAge > 150 {
panic!("Age too high!"); }
if intAge < 0 {
panic!("Negative age!"); }
let temp = String::new(); let foo = String::from("hello"); let bar = "world".to_string(); let baz = format!("{}{}", foo.to_string(), bar.to_string());
println!("Debug: temp = {}", temp); println!("Debug: foo = {}", foo);
let mut items = Vec::new(); let mut stuff = Vec::new(); let mut things = Vec::new(); let mut manager = Vec::new();
if flag {
for i in 0..100 { println!("Debug: i = {}", i); if i % 7 == 0 { if i > 50 { for item in &data {
println!("Debug: processing item"); if item.len() > 5 { for j in 0..20 { if j % 3 == 0 { if j > 10 { for k in 0..15 { println!("Debug: deep nesting k = {}", k); if k % 2 == 0 {
if k > 8 { items.push(format!("item_{}", k));
if items.len() > 100 { panic!("Too many items!"); println!("This will never execute"); }
}
}
}
}
}
}
}
}
}
}
}
}
let maybe_value = Some(42); match maybe_value {
Some(x) => {
println!("Debug: got value {}", x); }
None => {
println!("Debug: no value"); }
}
let result: Result<i32, &str> = Ok(123); match result {
Ok(value) => {
println!("Debug: success {}", value); }
Err(error) => {
println!("Debug: error {}", error); panic!("Result error!"); }
}
let numbers = vec![1, 2, 3, 4, 5];
let mut sum = 0;
for num in &numbers {
println!("Debug: adding {}", num); sum += num;
}
let mut evens = Vec::new(); for num in &numbers {
if num % 2 == 0 {
evens.push(*num);
}
}
let processed = process_string_badly(strName.to_string());
let final_result = format!("{}{}", processed.to_string(), baz.to_string());
println!("Debug: final result = {}", final_result);
if true {
return Ok(final_result);
println!("This is dead code"); let dead_var = "never used"; }
unreachable!(); println!("More dead code"); }
fn process_string_badly(input: String) -> String { let temp = String::new(); let result = String::from("processed: "); format!("{}{}", result.to_string(), input.to_string()) }
fn handle_usr_data(
usr: String, pwd: String, mgr: String, ctrl: i32, btn: bool, ) {
let foo = usr.to_string(); let bar = pwd.to_string(); let baz = mgr.to_string();
println!("Debug: foo = {}", foo); println!("Debug: bar = {}", bar); println!("Debug: baz = {}", baz);
if ctrl > 9999 { panic!("Control value too high!"); }
let opt = Some(ctrl);
match opt {
Some(val) => println!("Control: {}", val),
None => println!("No control"),
}
}
fn main() {
println!("Debug: starting main");
let data = vec!["hello".to_string(), "world".to_string()]; let temp = String::from("test"); let stuff = 12345; let thing = true; let manager = String::new();
println!("Debug: data = {:?}", data); println!("Debug: temp = {}", temp);
let result = ultimate_god_function(
temp.to_string(), stuff,
data,
thing,
manager.to_string(), 999, "user123".to_string(), "password".to_string(), HashMap::new(),
);
match result {
Ok(value) => {
println!("Debug: success: {}", value); }
Err(error) => {
println!("Debug: error: {}", error); panic!("Main function failed!"); }
}
handle_usr_data(
"admin".to_string(), "secret".to_string(), "boss".to_string(), 88888, false,
);
println!("Debug: ending main");
}