Skip to content

Commit

Permalink
Hide MustBeBool from public API
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
  • Loading branch information
Gelbpunkt committed Sep 4, 2024
1 parent df1008d commit 5192b81
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions twilight-model/src/gateway/payload/incoming/guild_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ impl GuildCreate {
mod tests {
use serde_test::Token;

use crate::{guild::UnavailableGuild, id::Id, util::mustbe::MustBeBool};
use crate::{guild::UnavailableGuild, id::Id};

use super::GuildCreate;

#[test]
fn unavailable_guild() {
let expected = GuildCreate::Unavailable(UnavailableGuild {
id: Id::new(1234),
unavailable: MustBeBool,
unavailable: true,
});

// Note: serde(untagged) makes the enum transparent which is
Expand Down
5 changes: 2 additions & 3 deletions twilight-model/src/gateway/payload/incoming/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ mod tests {
id::Id,
oauth::{ApplicationFlags, PartialApplication},
user::CurrentUser,
util::mustbe::MustBeBool,
};
use serde_test::Token;

Expand All @@ -35,11 +34,11 @@ mod tests {
let guilds = vec![
UnavailableGuild {
id: Id::new(1),
unavailable: MustBeBool,
unavailable: true,
},
UnavailableGuild {
id: Id::new(2),
unavailable: MustBeBool,
unavailable: true,
},
];

Expand Down
29 changes: 25 additions & 4 deletions twilight-model/src/guild/unavailable_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,44 @@ use crate::{
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)]
pub struct UnavailableGuild {
pub id: Id<GuildMarker>,
pub unavailable: MustBeBool<true>,
pub unavailable: bool,
}

impl<'de> Deserialize<'de> for UnavailableGuild {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(rename = "UnavailableGuild")] // Tests expect this struct name
struct UnavailableGuildIntermediate {
id: Id<GuildMarker>,
unavailable: MustBeBool<true>,
}

let intermediate = UnavailableGuildIntermediate::deserialize(deserializer)?;

Ok(Self {
id: intermediate.id,
unavailable: intermediate.unavailable.get(),
})
}
}

#[cfg(test)]
mod tests {
use super::UnavailableGuild;
use crate::{id::Id, util::mustbe::MustBeBool};
use crate::id::Id;
use serde_test::Token;

#[test]
fn unavailable_guild() {
let value = UnavailableGuild {
id: Id::new(1),
unavailable: MustBeBool,
unavailable: true,
};

serde_test::assert_tokens(
Expand Down
2 changes: 1 addition & 1 deletion twilight-model/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pub mod datetime;
pub mod hex_color;
pub mod image_hash;
pub mod mustbe;
pub(crate) mod mustbe;

pub use self::{datetime::Timestamp, hex_color::HexColor, image_hash::ImageHash};

Expand Down

0 comments on commit 5192b81

Please sign in to comment.