-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up library with
is_non_null
(#1528)
Adds `PointerExt::is_non_null` and cleans up some library code. This route was chosen because expressions like the following: ```rust if !(*(*some_ptr).field.another_ptr_field).something_else.is_null() { ``` make it easy to lose track of the `!` by the time you arrive at `is_null`, thus making it very easy to confuse the usage of negation. `null_mut` is odd anyways, easily confusable from the "C view" with some sort of `void*`, and Postgres has many `bool* nulls`, too.
- Loading branch information
1 parent
395c975
commit 0e01d93
Showing
5 changed files
with
27 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ pub use once_cell; | |
|
||
/// Not ready for public exposure. | ||
mod layout; | ||
mod ptr; | ||
mod slice; | ||
mod toast; | ||
|
||
|
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,15 @@ | ||
pub(crate) trait PointerExt { | ||
fn is_non_null(&self) -> bool; | ||
} | ||
|
||
impl<T> PointerExt for *mut T { | ||
fn is_non_null(&self) -> bool { | ||
!self.is_null() | ||
} | ||
} | ||
|
||
impl<T> PointerExt for *const T { | ||
fn is_non_null(&self) -> bool { | ||
!self.is_null() | ||
} | ||
} |