Skip to content

Commit

Permalink
feat: bump bevy to v0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
umut-sahin committed Jul 5, 2024
1 parent 48355a7 commit f07bf63
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ authors = [
]

[dependencies]
bevy = { version = "0.13", default-features = false }
bevy = { version = "0.14", default-features = false }
bincode = { version = "1.3", optional = true }
ron = { version = "0.8", optional = true }
serde = { version = "1.0" }
Expand All @@ -32,7 +32,7 @@ gloo-storage = { version = "0.3" }
[dev-dependencies]
anyhow = { version = "1.0" }
dirs = { version = "5.0" }
bevy = { version = "0.13", features = ["serialize"] }
bevy = { version = "0.14", features = ["serialize"] }

[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
tempfile = { version = "3.4" }
Expand Down
2 changes: 1 addition & 1 deletion examples/alternating-crouch-key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ fn show_final_key_bindings(key_bindings: Res<Persistent<KeyBindings>>) {
}

fn exit(mut exit: EventWriter<AppExit>) {
exit.send(AppExit);
exit.send(AppExit::Success);
}
19 changes: 8 additions & 11 deletions src/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ impl<R: Resource + Serialize + DeserializeOwned> Persistent<R> {
// this is because cloning can have special semantics
// e.g., cloning Persistent<Arc<RwLock<R>>> and changing it
// would change the default object, which is not desired
let serialized = format.serialize(&name, &default).map_err(|error| {
let serialized = format.serialize(&name, &default).inspect_err(|_| {
log::error!("failed to clone default {} due to a serialization error", name);
error
})?;
let reconstructed = format.deserialize(&name, &serialized).map_err(|error| {
let reconstructed = format.deserialize(&name, &serialized).inspect_err(|_| {
log::error!("failed to clone default {} due to a deserialization error", name);
error
})?;

Some(reconstructed)
Expand Down Expand Up @@ -292,12 +290,11 @@ impl<R: Resource + Serialize + DeserializeOwned> Persistent<R> {
/// Panics if the resource is unloaded.
pub fn unload(&mut self) -> Result<(), PersistenceError> {
if self.resource.is_some() {
self.persist().map_err(|error| {
self.persist().inspect_err(|_| {
log::error!(
"failed to unload {} due to not being able to persist it before unloading",
self.name,
);
error
})?;
self.resource = None;
log::info!("unloaded {}", self.name);
Expand Down Expand Up @@ -408,20 +405,20 @@ impl<R: Resource + Serialize + DeserializeOwned> Persistent<R> {
// this is because cloning can have special semantics
// e.g., cloning Persistent<Arc<RwLock<R>>> and changing it
// would change the default object, which is not desired
let serialized =
self.format.serialize(&self.name, self.default.as_ref().unwrap()).map_err(|error| {
let serialized = self
.format
.serialize(&self.name, self.default.as_ref().unwrap())
.inspect_err(|_| {
log::error!(
"failed to revert {} to default in memory due to a serialization error",
self.name,
);
error
})?;
let reconstructed = self.format.deserialize(&self.name, &serialized).map_err(|error| {
let reconstructed = self.format.deserialize(&self.name, &serialized).inspect_err(|_| {
log::error!(
"failed to revert {} to default in memory due to a deserialization error",
self.name,
);
error
})?;

self.resource = Some(reconstructed);
Expand Down
36 changes: 12 additions & 24 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,35 @@ impl Storage {

#[cfg(feature = "json")]
if format == StorageFormat::Json {
return Ok(LocalStorage::get::<R>(key).map_err(|error| {
return Ok(LocalStorage::get::<R>(key).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to parse {} as JSON\n\n{}", name, error);
}
error
})?);
}
#[cfg(all(feature = "json", feature = "pretty"))]
if format == StorageFormat::JsonPretty {
return Ok(LocalStorage::get::<R>(key).map_err(|error| {
return Ok(LocalStorage::get::<R>(key).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to parse {} as pretty JSON\n\n{}", name, error);
}
error
})?);
}

#[cfg(feature = "bincode")]
if format == StorageFormat::Bincode {
let bytes = LocalStorage::get::<Vec<u8>>(key).map_err(|error| {
let bytes = LocalStorage::get::<Vec<u8>>(key).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to get {} as a byte array\n\n{}", name, error);
}
error
})?;
return format.deserialize::<R>(name, &bytes);
}

let content = LocalStorage::get::<String>(key).map_err(|error| {
let content = LocalStorage::get::<String>(key).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to get {} as a string\n\n{}", name, error);
}
error
})?;
format.deserialize::<R>(name, content.as_bytes())
},
Expand All @@ -123,39 +119,35 @@ impl Storage {

#[cfg(feature = "json")]
if format == StorageFormat::Json {
return Ok(SessionStorage::get::<R>(key).map_err(|error| {
return Ok(SessionStorage::get::<R>(key).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to parse {} as JSON\n\n{}", name, error);
}
error
})?);
}
#[cfg(all(feature = "json", feature = "pretty"))]
if format == StorageFormat::JsonPretty {
return Ok(SessionStorage::get::<R>(key).map_err(|error| {
return Ok(SessionStorage::get::<R>(key).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to parse {} as pretty JSON\n\n{}", name, error);
}
error
})?);
}

#[cfg(feature = "bincode")]
if format == StorageFormat::Bincode {
let bytes = SessionStorage::get::<Vec<u8>>(key).map_err(|error| {
let bytes = SessionStorage::get::<Vec<u8>>(key).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to get {} as a byte array\n\n{}", name, error);
}
error
})?;
return format.deserialize::<R>(name, &bytes);
}

let content = SessionStorage::get::<String>(key).map_err(|error| {
let content = SessionStorage::get::<String>(key).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to get {} as a string\n\n{}", name, error);
}
error
})?;
format.deserialize::<R>(name, content.as_bytes())
},
Expand Down Expand Up @@ -192,21 +184,19 @@ impl Storage {

#[cfg(feature = "json")]
if format == StorageFormat::Json {
LocalStorage::set::<&R>(key, resource).map_err(|error| {
LocalStorage::set::<&R>(key, resource).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to serialize {} to JSON\n\n{}", name, error);
}
error
})?;
return Ok(());
}
#[cfg(all(feature = "json", feature = "pretty"))]
if format == StorageFormat::JsonPretty {
LocalStorage::set::<&R>(key, resource).map_err(|error| {
LocalStorage::set::<&R>(key, resource).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to serialize {} to pretty JSON\n\n{}", name, error);
}
error
})?;
return Ok(());
}
Expand Down Expand Up @@ -236,21 +226,19 @@ impl Storage {

#[cfg(feature = "json")]
if format == StorageFormat::Json {
SessionStorage::set::<&R>(key, resource).map_err(|error| {
SessionStorage::set::<&R>(key, resource).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to serialize {} to JSON\n\n{}", name, error);
}
error
})?;
return Ok(());
}
#[cfg(all(feature = "json", feature = "pretty"))]
if format == StorageFormat::JsonPretty {
SessionStorage::set::<&R>(key, resource).map_err(|error| {
SessionStorage::set::<&R>(key, resource).inspect_err(|error| {
if let StorageError::SerdeError(error) = &error {
log::error!("failed to serialize {} to pretty JSON\n\n{}", name, error);
}
error
})?;
return Ok(());
}
Expand Down

0 comments on commit f07bf63

Please sign in to comment.