[+] Safe write util function

This commit is contained in:
Azalea Gui
2023-02-23 11:50:56 -05:00
parent d4388a94e3
commit 732b289ca2
2 changed files with 18 additions and 1 deletions
+7 -1
View File
@@ -1,5 +1,7 @@
#[macro_use]
mod macros;
mod generator;
mod utils;
use std::convert::Infallible;
use std::{env, fs};
@@ -11,12 +13,16 @@ use serde::{Deserialize, Serialize};
use path_clean::{clean};
use macros::StringExt;
use crate::macros::PathExt;
use generator::*;
extern crate pretty_env_logger;
#[macro_use] extern crate log;
#[tokio::main]
async fn main() {
let cwd = env::current_dir().unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 3029));
println!("Serving {} started on http://127.0.0.1:3029", cwd.display());
info!("Serving {} started on http://127.0.0.1:3029", cwd.display());
// A `Service` is needed for every connection, so this
// creates one from our `hello_world` function.
+11
View File
@@ -0,0 +1,11 @@
use std::{fs, io};
use std::path::{PathBuf};
pub fn write_sf<C: AsRef<[u8]>>(path: &PathBuf, contents: C) -> io::Result<()> {
// Create parent if it has parent
if let Some(p) = path.parent() {
fs::create_dir_all(p)?
}
fs::write(path, contents)
}