Follow clippy warnings

This commit is contained in:
Kitaiti Makoto 2021-11-28 08:36:27 +09:00
parent 20c17be124
commit 4bef91f08b
2 changed files with 23 additions and 17 deletions

View File

@ -54,11 +54,6 @@ pub enum EditorError {
DOMError, DOMError,
} }
impl From<std::option::NoneError> for EditorError {
fn from(_: std::option::NoneError) -> Self {
EditorError::NoneError
}
}
const AUTOSAVE_DEBOUNCE_TIME: i32 = 5000; const AUTOSAVE_DEBOUNCE_TIME: i32 = 5000;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct AutosaveInformation { struct AutosaveInformation {
@ -198,7 +193,7 @@ fn clear_autosave() {
.unwrap() .unwrap()
.remove_item(&get_autosave_id()) .remove_item(&get_autosave_id())
.unwrap(); .unwrap();
console::log_1(&&format!("Saved to {}", &get_autosave_id()).into()); console::log_1(&format!("Saved to {}", &get_autosave_id()).into());
} }
type TimeoutHandle = i32; type TimeoutHandle = i32;
lazy_static! { lazy_static! {
@ -366,7 +361,9 @@ fn init_editor() -> Result<(), EditorError> {
return Ok(()); return Ok(());
} }
let old_ed = old_ed.unwrap(); let old_ed = old_ed.unwrap();
let old_title = document().get_element_by_id("plume-editor-title")?; let old_title = document()
.get_element_by_id("plume-editor-title")
.ok_or(EditorError::NoneError)?;
old_ed old_ed
.dyn_ref::<HtmlElement>() .dyn_ref::<HtmlElement>()
.unwrap() .unwrap()
@ -434,7 +431,8 @@ fn init_editor() -> Result<(), EditorError> {
bg.class_list().add_1("show").unwrap(); bg.class_list().add_1("show").unwrap();
})) as Box<dyn FnMut(MouseEvent)>); })) as Box<dyn FnMut(MouseEvent)>);
document() document()
.get_element_by_id("publish")? .get_element_by_id("publish")
.ok_or(EditorError::NoneError)?
.add_event_listener_with_callback("click", show_popup.as_ref().unchecked_ref()) .add_event_listener_with_callback("click", show_popup.as_ref().unchecked_ref())
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
show_popup.forget(); show_popup.forget();
@ -528,8 +526,14 @@ fn init_popup(
cover_label cover_label
.set_attribute("for", "cover") .set_attribute("for", "cover")
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
let cover = document.get_element_by_id("cover")?; let cover = document
cover.parent_element()?.remove_child(&cover).ok(); .get_element_by_id("cover")
.ok_or(EditorError::NoneError)?;
cover
.parent_element()
.ok_or(EditorError::NoneError)?
.remove_child(&cover)
.ok();
popup popup
.append_child(&cover_label) .append_child(&cover_label)
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
@ -554,7 +558,7 @@ fn init_popup(
draft.set_checked(draft_checkbox.checked()); draft.set_checked(draft_checkbox.checked());
draft_label draft_label
.append_child(&draft) .append_child(draft)
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
draft_label draft_label
.append_child(&document.create_text_node(&i18n!(CATALOG, "This is a draft"))) .append_child(&document.create_text_node(&i18n!(CATALOG, "This is a draft")))
@ -620,11 +624,12 @@ fn init_popup(
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
callback.forget(); callback.forget();
popup popup
.append_child(&button) .append_child(button)
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
document document
.body()? .body()
.ok_or(EditorError::NoneError)?
.append_child(&popup) .append_child(&popup)
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
Ok(popup) Ok(popup)
@ -641,7 +646,8 @@ fn init_popup_bg() -> Result<Element, EditorError> {
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
document() document()
.body()? .body()
.ok_or(EditorError::NoneError)?
.append_child(&bg) .append_child(&bg)
.map_err(|_| EditorError::DOMError)?; .map_err(|_| EditorError::DOMError)?;
let callback = Closure::wrap(Box::new(|_| close_popup()) as Box<dyn FnMut(MouseEvent)>); let callback = Closure::wrap(Box::new(|_| close_popup()) as Box<dyn FnMut(MouseEvent)>);

View File

@ -1,5 +1,5 @@
#![recursion_limit = "128"] #![recursion_limit = "128"]
#![feature(decl_macro, proc_macro_hygiene, try_trait)] #![feature(decl_macro, proc_macro_hygiene)]
#[macro_use] #[macro_use]
extern crate gettext_macros; extern crate gettext_macros;
@ -61,7 +61,7 @@ lazy_static! {
static ref CATALOG: gettext::Catalog = { static ref CATALOG: gettext::Catalog = {
let catalogs = include_i18n!(); let catalogs = include_i18n!();
let lang = window().unwrap().navigator().language().unwrap(); let lang = window().unwrap().navigator().language().unwrap();
let lang = lang.splitn(2, '-').next().unwrap_or("en"); let lang = lang.split_once('-').map_or("en", |x| x.0);
let english_position = catalogs let english_position = catalogs
.iter() .iter()
@ -85,7 +85,7 @@ pub fn main() -> Result<(), JsValue> {
menu(); menu();
search(); search();
editor::init() editor::init()
.map_err(|e| console::error_1(&&format!("Editor error: {:?}", e).into())) .map_err(|e| console::error_1(&format!("Editor error: {:?}", e).into()))
.ok(); .ok();
Ok(()) Ok(())
} }