Skip to content
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

Any shim rand_core 4.3 crate around rand_core 0.5? #865

Closed
burdges opened this issue Aug 11, 2019 · 3 comments
Closed

Any shim rand_core 4.3 crate around rand_core 0.5? #865

burdges opened this issue Aug 11, 2019 · 3 comments

Comments

@burdges
Copy link
Contributor

burdges commented Aug 11, 2019

Is there going to be a shim rand_core 4.3 crate around rand_core 0.5?

It's only the Error type that broke in https://github.com/rust-random/rand/pull/800/files#diff-52e6ceb949d7fa383058092b498596b0R21 so doing a shim is non-trivial, and might break other things, right?

@burdges
Copy link
Contributor Author

burdges commented Aug 11, 2019

I'd missed that kind and msg are marked pub in the old error, so the only viable shim would be a wrapper type, which itself could appear elsewhere.

pub struct RngCore5As4<R: NewRngCore>(pub  R);

impl <R: NewRngCore> OldRngCore for RngCore5As4<R> {
    fn next_u32(&mut self) -> u32 { self.0.next_u32() }
    fn next_u64(&mut self) -> u64  { self.0.next_u64() }
    fn fill_bytes(&mut self, dest: &mut [u8])  { self.0.fill_bytes(dest) }
    fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), OldError> {
        self.0.try_fill_bytes(dest),map_err(map_error)
    }
}

fn map_error(err: NewErrorNew) -> OldError {
    let kind = ErrorKind::Unavailable;
    let msg = "Unknown error from another rand_core version";
    #[cfg(not(feature="std"))]
    OldError::new(kind,msg)
    #[cfg(feature="std")]
    OldError::with_casue(kind,msg,err.take_inner())
 }

Anyone running on nightly could do this themselves with rust-lang/cargo#4953 and stable users need two crates for the reexport trick.

@dhardy
Copy link
Member

dhardy commented Aug 11, 2019

No. See #819.

@dhardy dhardy closed this as completed Aug 11, 2019
@burdges
Copy link
Contributor Author

burdges commented Aug 11, 2019

Right I figured out the Error types break. :) Individual crates could however use RngCore5As4 be rand_code 0.5 themselves while using rand_core 0.4 dependencies. I do not suggest including RngCore5As4 in rand_core of course, more some one off hack for anyone who needs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants