-
Notifications
You must be signed in to change notification settings - Fork 244
Add optional support for extern_item_impls
#786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bushrat011899
wants to merge
8
commits into
rust-random:master
Choose a base branch
from
bushrat011899:nightly_eii
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−11
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
557c77a
Add optional support for extern_item_impls
bushrat011899 3db99c1
Formatting and Typos
bushrat011899 8b445e8
Prevent feature-gate breaking rustdoc
bushrat011899 5688a01
Prevent feature-gate breaking rustdoc
bushrat011899 c04e035
Merge branch 'nightly_eii' of https://github.com/bushrat011899/getran…
bushrat011899 c0cd373
Refactor EII as a self-contained backend
bushrat011899 3a2c4a0
Merge remote-tracking branch 'upstream/master' into nightly_eii
bushrat011899 d09a652
Update README.md
bushrat011899 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,19 @@ | ||
| //! An implementation which calls out to an externally defined function. | ||
| use crate::Error; | ||
| use core::mem::MaybeUninit; | ||
|
|
||
| /// Declares this function as an external implementation of [`fill_uninit`](crate::fill_uninit). | ||
| #[cfg_attr(getrandom_backend = "extern_item_impls", eii(fill_uninit))] | ||
| pub(crate) fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error>; | ||
|
|
||
| /// Declares this function as an external implementation of [`u32`](crate::u32). | ||
| #[cfg_attr(getrandom_backend = "extern_item_impls", eii(u32))] | ||
| pub(crate) fn inner_u32() -> Result<u32, crate::Error> { | ||
| crate::util::inner_u32() | ||
| } | ||
|
|
||
| /// Declares this function as an external implementation of [`u64`](crate::u64). | ||
| #[cfg_attr(getrandom_backend = "extern_item_impls", eii(u64))] | ||
| pub(crate) fn inner_u64() -> Result<u64, crate::Error> { | ||
| crate::util::inner_u64() | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #![doc = include_str!("../README.md")] | ||
| #![cfg_attr(docsrs, feature(doc_cfg))] | ||
| #![cfg_attr(getrandom_backend = "efi_rng", feature(uefi_std))] | ||
| #![cfg_attr(getrandom_backend = "extern_item_impls", feature(extern_item_impls))] | ||
|
|
||
| #[macro_use] | ||
| extern crate cfg_if; | ||
|
|
@@ -34,6 +35,33 @@ pub use sys_rng::SysRng; | |
|
|
||
| pub use crate::error::{Error, RawOsError}; | ||
|
|
||
| #[cfg(getrandom_backend = "extern_item_impls")] | ||
| pub mod implementation { | ||
| //! Provides Externally Implementable Interfaces for the core functionality of this crate. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to use |
||
| //! This allows `getrandom` to provide a default implementation and a common interface | ||
| //! for all crates to use, while giving users a safe way to override that default where required. | ||
| //! | ||
| //! Must be enabled via the `extern_item_impls` opt-in backend, as this functionality | ||
| //! is currently limited to nightly. | ||
| //! | ||
| //! # Examples | ||
| //! | ||
| //! ```rust | ||
| //! # use core::mem::MaybeUninit; | ||
| //! # #[cfg(getrandom_backend = "extern_item_impls")] | ||
| //! #[getrandom::implementation::fill_uninit] | ||
| //! fn my_fill_uninit_implementation( | ||
| //! dest: &mut [MaybeUninit<u8>] | ||
| //! ) -> Result<(), getrandom::Error> { | ||
| //! // ... | ||
| //! # let _ = dest; | ||
| //! # Err(Error::UNSUPPORTED) | ||
| //! } | ||
| //! ``` | ||
|
|
||
| pub use crate::backends::extern_item_impls::{fill_uninit, u32, u64}; | ||
| } | ||
|
|
||
| /// Fill `dest` with random bytes from the system's preferred random number source. | ||
| /// | ||
| /// This function returns an error on any failure, including partial reads. We | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
cfg_attris not needed since the module is already gated.