Skip to content

Commit

Permalink
Replace uses of simd-json feature with simd_json
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Oct 16, 2023
1 parent 1a03dfb commit e0e90cd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: no cache
features: builder client framework gateway model http standard_framework utils rustls_backend
- name: simd-json
features: default_no_backend rustls_backend simd-json
features: default_no_backend rustls_backend simd_json
- name: no gateway
features: model http rustls_backend
- name: time
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum Error {
Io(IoError),
/// An error from the [`serde_json`] crate.
Json(JsonError),
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
/// An error from the `simd_json` crate.
SimdJson(simd_json::Error),
/// An error from the [`model`] module.
Expand Down Expand Up @@ -101,7 +101,7 @@ pub enum Error {
Tungstenite(TungsteniteError),
}

#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
impl From<simd_json::Error> for Error {
fn from(e: simd_json::Error) -> Self {
Error::SimdJson(e)
Expand Down Expand Up @@ -178,7 +178,7 @@ impl fmt::Display for Error {
Self::Json(inner) => fmt::Display::fmt(&inner, f),
Self::Model(inner) => fmt::Display::fmt(&inner, f),
Self::Url(msg) => f.write_str(msg),
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
Error::SimdJson(inner) => fmt::Display::fmt(&inner, f),
#[cfg(feature = "client")]
Self::Client(inner) => fmt::Display::fmt(&inner, f),
Expand Down
2 changes: 1 addition & 1 deletion src/internal/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pub use std::result::Result as StdResult;

#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub use simd_json::{Mutable, Value as ValueTrait, ValueAccess};

#[cfg(feature = "client")]
Expand Down
46 changes: 23 additions & 23 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ use serde::ser::Serialize;

use crate::Result;

#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
pub type Value = serde_json::Value;
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub type Value = simd_json::OwnedValue;

#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
pub use serde_json::json;
#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
pub use serde_json::Error as JsonError;
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub use simd_json::json;
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub use simd_json::Error as JsonError;

#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
pub type JsonMap = serde_json::Map<String, Value>;
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub type JsonMap = simd_json::owned::Object;

#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
pub const NULL: Value = Value::Null;
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub const NULL: Value = Value::Static(simd_json::StaticNode::Null);

/// Converts a HashMap into a final [`JsonMap`] representation.
Expand All @@ -45,63 +45,63 @@ where
map.into_iter().map(|(k, v)| (k.to_string(), v)).collect()
}

#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
pub(crate) fn to_string<T>(v: &T) -> Result<String>
where
T: Serialize,
{
Ok(serde_json::to_string(v)?)
}

#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub(crate) fn to_string<T>(v: &T) -> Result<String>
where
T: Serialize,
{
Ok(simd_json::to_string(v)?)
}

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

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

#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
pub(crate) fn from_value<T>(v: Value) -> Result<T>
where
T: DeserializeOwned,
{
Ok(serde_json::from_value(v)?)
}

#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub(crate) fn from_value<T>(v: Value) -> Result<T>
where
T: DeserializeOwned,
{
Ok(simd_json::serde::from_owned_value(v)?)
}

#[cfg(all(any(feature = "builder", feature = "http"), not(feature = "simd-json")))]
#[cfg(all(any(feature = "builder", feature = "http"), not(feature = "simd_json")))]
pub(crate) fn to_value<T>(value: T) -> Result<Value>
where
T: Serialize,
{
Ok(serde_json::to_value(value)?)
}

#[cfg(all(any(feature = "builder", feature = "http"), feature = "simd-json"))]
#[cfg(all(any(feature = "builder", feature = "http"), feature = "simd_json"))]
pub(crate) fn to_value<T>(value: T) -> Result<Value>
where
T: Serialize,
Expand All @@ -113,14 +113,14 @@ pub trait ToNumber {
fn to_number(self) -> Value;
}

#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
impl<T: Into<serde_json::Number>> ToNumber for T {
fn to_number(self) -> Value {
Value::Number(self.into())
}
}

#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
impl<T: Into<Value>> ToNumber for T {
fn to_number(self) -> Value {
self.into()
Expand All @@ -132,7 +132,7 @@ pub(crate) fn from_number(n: impl ToNumber) -> Value {
}

pub mod prelude {
#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
pub use serde_json::{
from_reader,
from_slice,
Expand All @@ -144,7 +144,7 @@ pub mod prelude {
to_vec,
to_vec_pretty,
};
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub use simd_json::{
from_reader,
from_slice,
Expand All @@ -156,7 +156,7 @@ pub mod prelude {
to_vec,
to_vec_pretty,
};
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
pub use simd_json::{Builder, Mutable, StaticNode, Value as ValueTrait, ValueAccess};

pub use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/audit_log/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum EntityType {

#[derive(Debug, PartialEq)]
// serde_json's Value impls Eq, simd-json's Value doesn't
#[cfg_attr(not(feature = "simd-json"), derive(Eq))]
#[cfg_attr(not(feature = "simd_json"), derive(Eq))]
#[non_exhaustive]
pub enum Change {
Actions {
Expand Down
4 changes: 2 additions & 2 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2831,9 +2831,9 @@ impl<'de> Deserialize<'de> for Guild {
None => PremiumTier::default(),
};
let premium_subscription_count = match map.remove("premium_subscription_count") {
#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
Some(Value::Null) | None => 0,
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
Some(Value::Static(StaticNode::Null)) | None => 0,
Some(v) => u64::deserialize(v).map_err(DeError::custom)?,
};
Expand Down
4 changes: 2 additions & 2 deletions src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1734,9 +1734,9 @@ impl<'de> Deserialize<'de> for PartialGuild {
None => PremiumTier::default(),
};
let premium_subscription_count = match map.remove("premium_subscription_count") {
#[cfg(not(feature = "simd-json"))]
#[cfg(not(feature = "simd_json"))]
Some(Value::Null) | None => 0,
#[cfg(feature = "simd-json")]
#[cfg(feature = "simd_json")]
Some(Value::Static(StaticNode::Null)) | None => 0,
Some(v) => u64::deserialize(v).map_err(DeError::custom)?,
};
Expand Down

0 comments on commit e0e90cd

Please sign in to comment.