Skip to content

Commit

Permalink
Add const keywords to some functions (#132)
Browse files Browse the repository at this point in the history
* Add const keywords to some functions

* Update web_sys to 0.3.70
  • Loading branch information
vbkaisetsu authored Sep 23, 2024
1 parent 281b47f commit ccde8ba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ vaporetto = { path = "../../vaporetto", default-features = false, features = ["s
vaporetto_rules = { path = "../../vaporetto_rules" } # MIT or Apache-2.0
wasm-bindgen = "0.2.92" # MIT or Apache-2.0
wasm-bindgen-futures = "0.4.42" # MIT or Apache-2.0
web-sys = { version = "0.3.69", features = ["Clipboard", "Event", "EventTarget", "InputEvent"] } # MIT or Apache-2.0
web-sys = { version = "0.3.70", features = ["Clipboard", "Event", "EventTarget", "InputEvent"] } # MIT or Apache-2.0
yew = { version = "0.21", features = ["csr"] } # MIT or Apache-2.0

[profile.release]
Expand Down
37 changes: 18 additions & 19 deletions examples/wasm/src/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,27 @@ impl Component for TextInput {
let button_ref = self.button_ref.clone();
let clipboard_click = Callback::from(move |_| {
let input = input_ref.cast::<HtmlInputElement>().unwrap();
if let Some(clipboard) = web_sys::window().unwrap().navigator().clipboard() {
let loc = web_sys::window().unwrap().location();
let content = format!(
"{}{}?text={}",
loc.origin().unwrap(),
loc.pathname().unwrap(),
js_sys::encode_uri_component(&input.value())
);
let promise = clipboard.write_text(&content);
let clipboard = web_sys::window().unwrap().navigator().clipboard();
let loc = web_sys::window().unwrap().location();
let content = format!(
"{}{}?text={}",
loc.origin().unwrap(),
loc.pathname().unwrap(),
js_sys::encode_uri_component(&input.value())
);
let promise = clipboard.write_text(&content);
let button_ref = button_ref.clone();
spawn_local(async move {
JsFuture::from(promise).await.unwrap();
let button = button_ref.cast::<HtmlInputElement>().unwrap();
button.set_class_name("copied");
let button_ref = button_ref.clone();
spawn_local(async move {
JsFuture::from(promise).await.unwrap();
let timeout = Timeout::new(1000, move || {
let button = button_ref.cast::<HtmlInputElement>().unwrap();
button.set_class_name("copied");
let button_ref = button_ref.clone();
let timeout = Timeout::new(1000, move || {
let button = button_ref.cast::<HtmlInputElement>().unwrap();
button.set_class_name("");
});
timeout.forget();
button.set_class_name("");
});
}
timeout.forget();
});
});
if let Some(value) = value.as_ref() {
html! {
Expand Down
2 changes: 1 addition & 1 deletion vaporetto/src/dict_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl WordWeightRecord {
pub struct DictModel(pub(crate) Vec<WordWeightRecord>);

impl DictModel {
pub fn new(dict: Vec<WordWeightRecord>) -> Self {
pub const fn new(dict: Vec<WordWeightRecord>) -> Self {
Self(dict)
}

Expand Down
2 changes: 1 addition & 1 deletion vaporetto/src/predictor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub struct PositionalWeight<W> {
}

impl PositionalWeight<Vec<i32>> {
pub fn new(offset: i16, weight: Vec<i32>) -> Self {
pub const fn new(offset: i16, weight: Vec<i32>) -> Self {
Self { offset, weight }
}
}
Expand Down

0 comments on commit ccde8ba

Please sign in to comment.