Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
BOOL
, BOOLEAN
, and NTSTATUS
extensions rather than replace…
…ments (#1995)
- Loading branch information
Showing
16 changed files
with
258 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use super::*; | ||
|
||
pub fn gen() -> TokenStream { | ||
quote! { | ||
impl BOOLEAN { | ||
#[inline] | ||
pub fn as_bool(self) -> bool { | ||
self.0 != 0 | ||
} | ||
#[inline] | ||
pub fn ok(self) -> ::windows::core::Result<()> { | ||
if self.as_bool() { | ||
Ok(()) | ||
} else { | ||
Err(::windows::core::Error::from_win32()) | ||
} | ||
} | ||
#[inline] | ||
#[track_caller] | ||
pub fn unwrap(self) { | ||
self.ok().unwrap(); | ||
} | ||
#[inline] | ||
#[track_caller] | ||
pub fn expect(self, msg: &str) { | ||
self.ok().expect(msg); | ||
} | ||
} | ||
impl ::core::convert::From<BOOLEAN> for bool { | ||
fn from(value: BOOLEAN) -> Self { | ||
value.as_bool() | ||
} | ||
} | ||
impl ::core::convert::From<&BOOLEAN> for bool { | ||
fn from(value: &BOOLEAN) -> Self { | ||
value.as_bool() | ||
} | ||
} | ||
impl ::core::convert::From<bool> for BOOLEAN { | ||
fn from(value: bool) -> Self { | ||
if value { | ||
Self(1) | ||
} else { | ||
Self(0) | ||
} | ||
} | ||
} | ||
impl ::core::convert::From<&bool> for BOOLEAN { | ||
fn from(value: &bool) -> Self { | ||
(*value).into() | ||
} | ||
} | ||
impl ::core::cmp::PartialEq<bool> for BOOLEAN { | ||
fn eq(&self, other: &bool) -> bool { | ||
self.as_bool() == *other | ||
} | ||
} | ||
impl ::core::cmp::PartialEq<BOOLEAN> for bool { | ||
fn eq(&self, other: &BOOLEAN) -> bool { | ||
*self == other.as_bool() | ||
} | ||
} | ||
impl ::core::ops::Not for BOOLEAN { | ||
type Output = Self; | ||
fn not(self) -> Self::Output { | ||
if self.as_bool() { | ||
Self(0) | ||
} else { | ||
Self(1) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
use super::*; | ||
mod bool32; | ||
mod bstr; | ||
mod ntstatus; | ||
|
||
pub fn gen(type_name: TypeName) -> Option<TokenStream> { | ||
match type_name { | ||
TypeName::BOOL => Some(bool32::gen()), | ||
TypeName::BSTR => Some(bstr::gen()), | ||
TypeName::NTSTATUS => Some(ntstatus::gen()), | ||
_ => None, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.