use crate::error::SmoothError;
use crate::util;
use std::fs;
use std::include_str;
use std::io::prelude::*;
pub struct Example;
impl<'a> Example {
pub fn as_string() -> Result<&'a str, SmoothError<'a>> {
Ok(Self::content())
}
pub fn save_to_file<S: Into<String>>(path: S) -> Result<(), SmoothError<'a>> {
let norm_path = util::normalize_path(path, None)?;
let mut file = match fs::File::create(&norm_path) {
Ok(x) => x,
Err(e) => return Err(SmoothError::FileCreateFailed(norm_path, e)),
};
let content = String::from(Self::content());
match file.write_all(content.as_bytes()) {
Ok(_) => Ok(()),
Err(e) => Err(SmoothError::WriteFailed(norm_path, e)),
}
}
fn content() -> &'static str {
include_str!("example.md")
}
}