Skip to content

Commit d15ada7

Browse files
authored
fix(settings wasm): fix compilation errors / match store_fs fn signatures (#23779)
# Objective - Unblock #23719 - The PR revealed that wasm builds are currently broken for `bevy_settings` when trying to merge to main. - On main, if you try to build an example that requires `bevy_settings` for wasm targets, it fails with the same compilation error (i.e. `cargo build --release --example persisting_preferences --target wasm32-unknown-unknown --features=“bevy_settings”`) ## Solution - Fix up `store_wasm.rs`. The function signatures should match those in `store_fs.rs`, and remove any references that do not exist. ## Testing - With the `Cargo.toml` change from #23719, was able to build the wasm target described in Objective successfully. Then, prepared the wasm target and served it locally following the examples/README.md directions. The example works as expected for web interactions.
1 parent 6356a7d commit d15ada7

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

crates/bevy_settings/src/store_wasm.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::prefs_file::serialize_table;
2-
use crate::{prefs::PreferencesStore, PreferencesFile, PreferencesFileContent};
31
use bevy_log::error;
42
use bevy_tasks::IoTaskPool;
53
use web_sys::window;
@@ -31,9 +29,9 @@ impl PreferencesStore {
3129
/// # Arguments
3230
/// * `filename` - the name of the file to be saved
3331
/// * `contents` - the contents of the file
34-
pub(crate) fn save(&self, filename: &str, contents: &PreferencesFile) {
32+
pub(crate) fn save(&self, filename: &str, contents: toml::Table) {
3533
if let Ok(Some(storage)) = window().unwrap().local_storage() {
36-
let toml_str = serialize_table(&contents.table);
34+
let toml_str = contents.to_string();
3735
storage
3836
.set_item(&self.storage_key(filename).as_str(), &toml_str)
3937
.unwrap();
@@ -45,11 +43,11 @@ impl PreferencesStore {
4543
/// # Arguments
4644
/// * `filename` - the name of the file to be saved
4745
/// * `contents` - the contents of the file
48-
pub(crate) fn save_async(&self, filename: &str, contents: PreferencesFileContent) {
46+
pub(crate) fn save_async(&self, filename: &str, contents: toml::Table) {
4947
IoTaskPool::get().scope(|scope| {
5048
scope.spawn(async {
5149
if let Ok(Some(storage)) = window().unwrap().local_storage() {
52-
let toml_str = serialize_table(&contents.0);
50+
let toml_str = contents.to_string();
5351
storage
5452
.set_item(&self.storage_key(filename).as_str(), &toml_str)
5553
.unwrap();
@@ -63,7 +61,7 @@ impl PreferencesStore {
6361
///
6462
/// # Arguments
6563
/// * `filename` - The name of the preferences file, without the file extension.
66-
pub(crate) fn load(&mut self, filename: &str) -> Option<PreferencesFile> {
64+
pub(crate) fn load(&self, filename: &str) -> Option<toml::Table> {
6765
if let Ok(Some(storage)) = window().unwrap().local_storage() {
6866
let storage_key = self.storage_key(filename);
6967
let Ok(Some(toml_str)) = storage.get_item(&storage_key) else {
@@ -79,7 +77,7 @@ impl PreferencesStore {
7977
};
8078

8179
match table_value {
82-
toml::Value::Table(table) => Some(PreferencesFile::from_table(table)),
80+
toml::Value::Table(table) => Some(table),
8381
_ => {
8482
error!("Preferences file must be a table");
8583
None

0 commit comments

Comments
 (0)