#[allow(dead_code)]
pub mod archive_mod{
use std::fs::rename;
use std::io::{Read};
use std::fs::File;
use std::io::Write;
use std::path::Path;
pub fn create_archive_rs(path: &'static str) -> File{
let path_completo = Path::new(path).join(".rs");
if !path_completo.exists() || path.is_empty() || !path.ends_with(".rs"){
return File::create("src/default.rs").expect("Create archive filed!!!");
}
else{
return File::create(path_completo).expect("Create archive filed!!!");
}
}
pub fn write_code_rust(code: &'static str, mut file: File){
file.write_all(code.as_bytes()).expect("Write code failed!");
}
pub fn write_word_txt(text: &'static str, mut file: File){
file.write_all(text.as_bytes()).expect("Write failed!");
}
pub fn create_archive_txt(path: &'static str) -> File{
if path.is_empty() && !path.contains(".txt"){
return File::create("src/example.txt").expect("Create archive filed!!!");
}
else{
return File::create(path).expect("Create archive filed!!!");
}
}
pub fn read_archive(path: &'static str) -> String{
if !Path::exists(Path::new(path)){
panic!("Path invalid!");
}
else{
let mut string_read_archive = String::from(path);
let mut file = File::open(path).unwrap();
file.read_to_string(&mut string_read_archive).unwrap();
return string_read_archive;
}
}
pub fn rename_archive(path_from: &'static str, path_to: &'static str){
if !Path::exists(&Path::new(path_from)) && !Path::exists(&Path::new(path_to)){
panic!("Path inválido!!!");
}else {
rename(path_from, path_to).expect("File not found.");
}
}
}