From 18eced7305cda1d340691580dedd817175f0425d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Thu, 25 Nov 2021 03:29:30 +0000 Subject: [PATCH] add static assertions to bytestring --- bytestring/Cargo.toml | 5 ++--- bytestring/src/lib.rs | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bytestring/Cargo.toml b/bytestring/Cargo.toml index 34237ce9..d58af564 100644 --- a/bytestring/Cargo.toml +++ b/bytestring/Cargo.toml @@ -10,7 +10,6 @@ keywords = ["string", "bytes", "utf8", "web", "actix"] categories = ["no-std", "web-programming"] homepage = "https://actix.rs" repository = "https://github.com/actix/actix-net.git" -documentation = "https://docs.rs/bytestring" license = "MIT OR Apache-2.0" edition = "2018" @@ -23,6 +22,6 @@ bytes = "1" serde = { version = "1.0", optional = true } [dev-dependencies] +ahash = { version = "0.7.6", default-features = false } serde_json = "1.0" -# TODO: remove when ahash MSRV is restored -ahash = { version = "=0.7.4", default-features = false } +static_assertions = "1.1" diff --git a/bytestring/src/lib.rs b/bytestring/src/lib.rs index 63ba92ed..d831c792 100644 --- a/bytestring/src/lib.rs +++ b/bytestring/src/lib.rs @@ -2,6 +2,7 @@ #![no_std] #![deny(rust_2018_idioms, nonstandard_style)] +#![warn(missing_docs)] #![doc(html_logo_url = "https://actix.rs/img/logo.png")] #![doc(html_favicon_url = "https://actix.rs/favicon.ico")] @@ -217,17 +218,36 @@ mod serde { String::deserialize(deserializer).map(ByteString::from) } } + + #[cfg(test)] + mod serde_impl_tests { + use super::*; + + use serde::de::DeserializeOwned; + use static_assertions::assert_impl_all; + + assert_impl_all!(ByteString: Serialize, DeserializeOwned); + } } #[cfg(test)] mod test { use alloc::borrow::ToOwned; - use core::hash::{Hash, Hasher}; + use core::{ + hash::{Hash, Hasher}, + panic::{RefUnwindSafe, UnwindSafe}, + }; use ahash::AHasher; + use static_assertions::assert_impl_all; use super::*; + assert_impl_all!(ByteString: Send, Sync, Unpin, Sized); + assert_impl_all!(ByteString: UnwindSafe, RefUnwindSafe); + assert_impl_all!(ByteString: Clone, Default, Eq, PartialOrd, Ord); + assert_impl_all!(ByteString: fmt::Debug, fmt::Display); + #[test] fn test_partial_eq() { let s: ByteString = ByteString::from_static("test");