I've converted a Python script into Rust, and it is working the same, but wonder if this is a proper way to splice and check strings?
The 2 "if" statements is the code in question.
Python Code:
if k[:3] == "'''" and doc_switch == False or k[:3] == '"""' and doc_switch == False:
if "'''" in k[3:] or '"""' in k[3:]:
not_code_lines += 1
only_comments += 1
continue
else:
doc_switch = True
Converted to Rust code:
if k.get(..3) == Some("'''") && doc_switch == false || k.get(..3) == Some("\"\"\"") &&
doc_switch == false {
if k.get(3..).unwrap().to_string().contains("'''") ||
k.get(3..).unwrap().to_string().contains("\"\"\"") {
not_code_lines += 1;
only_comments += 1;
continue;
}
else {
doc_switch = true;
}
}
If you would like to see the full scripts their on my repository: https://github.com/Bren3232/Count-Lines