From 14263ef989dc4af336aae58766de304143bc06e2 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 10 Aug 2020 12:21:12 +0200 Subject: [PATCH] assert that Username does not impl PartialEq Signed-off-by: Wolfgang Bumiller --- src/api2/types/userid.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/api2/types/userid.rs b/src/api2/types/userid.rs index a81559af..31a6a4a4 100644 --- a/src/api2/types/userid.rs +++ b/src/api2/types/userid.rs @@ -76,6 +76,12 @@ pub const PROXMOX_AUTH_REALM_SCHEMA: Schema = PROXMOX_AUTH_REALM_STRING_SCHEMA.s /// This alone does NOT uniquely identify the user and therefore does not implement `Eq`. In order /// to compare user names directly, they need to be explicitly compared as strings by calling /// `.as_str()`. +/// +/// ```compile_fail +/// fn test(a: Username, b: Username) -> bool { +/// a == b // illegal and does not compile +/// } +/// ``` #[derive(Clone, Debug, Hash, Deserialize, Serialize)] pub struct Username(String); @@ -85,6 +91,26 @@ pub struct Username(String); #[derive(Debug, Hash)] pub struct UsernameRef(str); +#[doc(hidden)] +/// ```compile_fail +/// let a: Username = unsafe { std::mem::zeroed() }; +/// let b: Username = unsafe { std::mem::zeroed() }; +/// let _ = ::eq(&a, &b); +/// ``` +/// +/// ```compile_fail +/// let a: &UsernameRef = unsafe { std::mem::zeroed() }; +/// let b: &UsernameRef = unsafe { std::mem::zeroed() }; +/// let _ = <&UsernameRef as PartialEq>::eq(a, b); +/// ``` +/// +/// ```compile_fail +/// let a: &UsernameRef = unsafe { std::mem::zeroed() }; +/// let b: &UsernameRef = unsafe { std::mem::zeroed() }; +/// let _ = <&UsernameRef as PartialEq>::eq(&a, &b); +/// ``` +struct _AssertNoEqImpl; + impl UsernameRef { fn new(s: &str) -> &Self { unsafe { &*(s as *const str as *const UsernameRef) }