[+] Safe write util function
This commit is contained in:
+7
-1
@@ -1,5 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
mod generator;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
@@ -11,12 +13,16 @@ use serde::{Deserialize, Serialize};
|
|||||||
use path_clean::{clean};
|
use path_clean::{clean};
|
||||||
use macros::StringExt;
|
use macros::StringExt;
|
||||||
use crate::macros::PathExt;
|
use crate::macros::PathExt;
|
||||||
|
use generator::*;
|
||||||
|
|
||||||
|
extern crate pretty_env_logger;
|
||||||
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3029));
|
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
|
// A `Service` is needed for every connection, so this
|
||||||
// creates one from our `hello_world` function.
|
// creates one from our `hello_world` function.
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user