Skip to content

Commit

Permalink
Update simd-json to make serenity compile again
Browse files Browse the repository at this point in the history
And fix an unsoundness (lol)
  • Loading branch information
kangalio committed Sep 12, 2023
1 parent 1503d53 commit 430eae7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ version = "1.0.7"
optional = true

[dependencies.simd-json]
version = "0.4.14"
version = "0.10.3"
optional = true

[dependencies.tracing]
Expand Down
15 changes: 8 additions & 7 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use std::collections::HashMap;
use std::hash::{BuildHasher, Hash};

#[cfg(feature = "gateway")]
use serde::de::Deserialize;
use serde::de::DeserializeOwned;
use serde::ser::Serialize;

Expand Down Expand Up @@ -62,19 +60,22 @@ where
}

#[cfg(all(feature = "gateway", not(feature = "simd-json")))]
pub(crate) fn from_str<'a, T>(s: &'a mut str) -> Result<T>
pub(crate) fn from_str<T>(s: &str) -> Result<T>
where
T: Deserialize<'a>,
T: DeserializeOwned,
{
Ok(serde_json::from_str(s)?)
}

#[cfg(all(feature = "gateway", feature = "simd-json"))]
pub(crate) fn from_str<'a, T>(s: &'a mut str) -> Result<T>
pub(crate) fn from_str<T>(s: &str) -> Result<T>
where
T: Deserialize<'a>,
T: DeserializeOwned,
{
Ok(simd_json::from_str(s)?)
// Have to clone the argument because simd_json mutates the argument
// And we can't just take &mut str either because simd_json mutates the string such that it may
// not be UTF-8 afterwards, which is unsound
Ok(simd_json::from_slice(&mut s.as_bytes().to_vec())?)
}

#[cfg(not(feature = "simd-json"))]
Expand Down

0 comments on commit 430eae7

Please sign in to comment.