refactor: remove &Option<T> where used
This commit is contained in:
parent
293f0d1ca3
commit
dc5ec1cf53
3 changed files with 25 additions and 25 deletions
|
|
@ -12,7 +12,7 @@ use tiny_http::{Header, Response, Server};
|
|||
macro_rules! optional_resource {
|
||||
($name: tt, $path: tt) => {
|
||||
#[cfg(TREE_SITTER_EMBED_WASM_BINDING)]
|
||||
fn $name(tree_sitter_dir: &Option<PathBuf>) -> Cow<'static, [u8]> {
|
||||
fn $name(tree_sitter_dir: Option<&PathBuf>) -> Cow<'static, [u8]> {
|
||||
if let Some(tree_sitter_dir) = tree_sitter_dir {
|
||||
Cow::Owned(fs::read(tree_sitter_dir.join($path)).unwrap())
|
||||
} else {
|
||||
|
|
@ -21,7 +21,7 @@ macro_rules! optional_resource {
|
|||
}
|
||||
|
||||
#[cfg(not(TREE_SITTER_EMBED_WASM_BINDING))]
|
||||
fn $name(tree_sitter_dir: &Option<PathBuf>) -> Cow<'static, [u8]> {
|
||||
fn $name(tree_sitter_dir: Option<&PathBuf>) -> Cow<'static, [u8]> {
|
||||
if let Some(tree_sitter_dir) = tree_sitter_dir {
|
||||
Cow::Owned(fs::read(tree_sitter_dir.join($path)).unwrap())
|
||||
} else {
|
||||
|
|
@ -35,7 +35,7 @@ optional_resource!(get_playground_js, "docs/assets/js/playground.js");
|
|||
optional_resource!(get_lib_js, "lib/binding_web/tree-sitter.js");
|
||||
optional_resource!(get_lib_wasm, "lib/binding_web/tree-sitter.wasm");
|
||||
|
||||
fn get_main_html(tree_sitter_dir: &Option<PathBuf>) -> Cow<'static, [u8]> {
|
||||
fn get_main_html(tree_sitter_dir: Option<&PathBuf>) -> Cow<'static, [u8]> {
|
||||
if let Some(tree_sitter_dir) = tree_sitter_dir {
|
||||
Cow::Owned(fs::read(tree_sitter_dir.join("cli/src/playground.html")).unwrap())
|
||||
} else {
|
||||
|
|
@ -63,13 +63,13 @@ pub fn serve(grammar_path: &Path, open_in_browser: bool) -> Result<()> {
|
|||
}
|
||||
|
||||
let tree_sitter_dir = env::var("TREE_SITTER_BASE_DIR").map(PathBuf::from).ok();
|
||||
let main_html = str::from_utf8(&get_main_html(&tree_sitter_dir))
|
||||
let main_html = str::from_utf8(&get_main_html(tree_sitter_dir.as_ref()))
|
||||
.unwrap()
|
||||
.replace("THE_LANGUAGE_NAME", &grammar_name)
|
||||
.into_bytes();
|
||||
let playground_js = get_playground_js(&tree_sitter_dir);
|
||||
let lib_js = get_lib_js(&tree_sitter_dir);
|
||||
let lib_wasm = get_lib_wasm(&tree_sitter_dir);
|
||||
let playground_js = get_playground_js(tree_sitter_dir.as_ref());
|
||||
let lib_js = get_lib_js(tree_sitter_dir.as_ref());
|
||||
let lib_wasm = get_lib_wasm(tree_sitter_dir.as_ref());
|
||||
|
||||
let html_header = Header::from_str("Content-Type: text/html").unwrap();
|
||||
let js_header = Header::from_str("Content-Type: application/javascript").unwrap();
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ pub fn get_test_language(name: &str, parser_code: &str, path: Option<&Path>) ->
|
|||
}
|
||||
});
|
||||
TEST_LOADER
|
||||
.load_language_from_sources(name, &HEADER_DIR, &parser_c_path, &scanner_path)
|
||||
.load_language_from_sources(name, &HEADER_DIR, &parser_c_path, scanner_path.as_deref())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue