Skip to content

Commit

Permalink
bump wasm-bindgen & use immutable ref for map (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn authored Oct 15, 2024
1 parent 9d66b36 commit 886dfd7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
21 changes: 11 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ js-sys = "0.3.69"
rosu-mods = { version = "0.1.0", default-features = false, features = ["serde"] }
rosu-pp = "1.1.0"
serde = { version = "1.0.197", features = ["derive"] }
wasm-bindgen = "0.2.84"
wasm-bindgen = "0.2.95"

[dev-dependencies]
wasm-bindgen-test = "0.3.34"
Expand Down
8 changes: 4 additions & 4 deletions src/args/beatmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::{Formatter, Result as FmtResult};
use rosu_mods::GameMods;
use rosu_pp::model::beatmap::BeatmapAttributesBuilder;
use serde::de;
use wasm_bindgen::{__rt::RefMut, prelude::wasm_bindgen};
use wasm_bindgen::{__rt::RcRef, prelude::wasm_bindgen};

use crate::{beatmap::JsBeatmap, mode::JsGameMode, util};

Expand Down Expand Up @@ -100,7 +100,7 @@ pub struct BeatmapAttributesArgs {
#[serde(default)]
pub is_convert: bool,
#[serde(default, deserialize_with = "deser_maybe_map")]
pub map: Option<RefMut<'static, JsBeatmap>>,
pub map: Option<RcRef<JsBeatmap>>,
}

impl BeatmapAttributesArgs {
Expand Down Expand Up @@ -144,11 +144,11 @@ impl BeatmapAttributesArgs {

fn deser_maybe_map<'de, D: de::Deserializer<'de>>(
d: D,
) -> Result<Option<RefMut<'static, JsBeatmap>>, D::Error> {
) -> Result<Option<RcRef<JsBeatmap>>, D::Error> {
struct MaybeMapVisitor;

impl<'de> de::Visitor<'de> for MaybeMapVisitor {
type Value = Option<RefMut<'static, JsBeatmap>>;
type Value = Option<RcRef<JsBeatmap>>;

fn expecting(&self, f: &mut Formatter) -> FmtResult {
f.write_str("an optional Beatmap")
Expand Down
4 changes: 2 additions & 2 deletions src/args/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rosu_pp::{
Performance,
};
use serde::de;
use wasm_bindgen::{__rt::RefMut, prelude::wasm_bindgen, JsValue};
use wasm_bindgen::{__rt::RcRef, prelude::wasm_bindgen, JsValue};

use crate::{
attributes::{difficulty::JsDifficultyAttributes, performance::JsPerformanceAttributes},
Expand Down Expand Up @@ -202,7 +202,7 @@ const _: &'static str = r#"/**
export type MapOrAttributes = DifficultyAttributes | PerformanceAttributes | Beatmap;"#;

pub enum MapOrAttrs {
Map(RefMut<'static, JsBeatmap>),
Map(RcRef<JsBeatmap>),
Attrs(DifficultyAttributes),
}

Expand Down
10 changes: 4 additions & 6 deletions src/beatmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rosu_pp::{
Beatmap,
};
use serde::de;
use wasm_bindgen::{__rt::RefMut, convert::RefMutFromWasmAbi, prelude::wasm_bindgen};
use wasm_bindgen::{__rt::RcRef, convert::RefFromWasmAbi, prelude::wasm_bindgen};

use crate::{
args::beatmap::{BeatmapContent, JsBeatmapContent},
Expand Down Expand Up @@ -127,9 +127,7 @@ impl JsBeatmap {
}

impl JsBeatmap {
pub fn deserialize<'de, D: de::Deserializer<'de>>(
d: D,
) -> Result<RefMut<'static, Self>, D::Error> {
pub fn deserialize<'de, D: de::Deserializer<'de>>(d: D) -> Result<RcRef<Self>, D::Error> {
struct BeatmapField;

impl BeatmapField {
Expand All @@ -146,7 +144,7 @@ impl JsBeatmap {
struct BeatmapVisitor;

impl<'de> de::Visitor<'de> for BeatmapVisitor {
type Value = RefMut<'static, JsBeatmap>;
type Value = RcRef<JsBeatmap>;

fn expecting(&self, f: &mut Formatter) -> FmtResult {
f.write_str("a Beatmap")
Expand All @@ -156,7 +154,7 @@ impl JsBeatmap {
map.next_key::<BeatmapField>()?;

let ptr_u32 = map.next_value::<u32>()?;
let instance_ref = unsafe { JsBeatmap::ref_mut_from_abi(ptr_u32) };
let instance_ref = unsafe { JsBeatmap::ref_from_abi(ptr_u32) };

Ok(instance_ref)
}
Expand Down

0 comments on commit 886dfd7

Please sign in to comment.