-
-
Save rust-play/0b3f3a80dd2f69e2d5ac65dcb153f8a1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
| #![allow(unexpected_cfgs)] | |
| #![allow(deprecated)] | |
| // --- SECTION 1: NIGHTLY (no_std + Allocator) --- | |
| #[cfg(nightly)] | |
| mod nightly_impl { | |
| #![feature(alloc_error_handler)] | |
| #![no_std] | |
| #![no_main] | |
| extern crate alloc; | |
| use core::panic::PanicInfo; | |
| // Versioned RNGs | |
| use rand_0_8_5::{SeedableRng as SeedableRngL, Rng as RngL}; | |
| use rand_0_8_5::rngs::SmallRng as SmallRngL; | |
| use rand_0_9_2::{SeedableRng as SeedableRngLatest, Rng as RngLatest}; | |
| use rand_0_9_2::rngs::SmallRng as SmallRngLatest; | |
| #[no_mangle] | |
| pub extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 { | |
| let seed = [0u8; 32]; | |
| let mut rng8 = SmallRngL::from_seed(seed); | |
| let mut rng9 = SmallRngLatest::from_seed(seed); | |
| // r#gen escapes the 'gen' keyword reserved in Edition 2024 | |
| let v8: u64 = rng8.r#gen(); | |
| let v9: u64 = rng9.r#gen(); | |
| if v8 == v9 { 0 } else { 1 } | |
| } | |
| #[panic_handler] | |
| fn panic(_info: &PanicInfo) -> ! { loop {} } | |
| #[alloc_error_handler] | |
| fn alloc_error_handler(_layout: core::alloc::Layout) -> ! { loop {} } | |
| } | |
| // --- SECTION 2: STABLE/BETA (Standard std) --- | |
| #[cfg(not(nightly))] | |
| mod stable_impl { | |
| use rand_0_8_5::{thread_rng as rng_v8, Rng as RngL}; | |
| use rand_0_9_2::{thread_rng as rng_v9, Rng as RngLatest}; | |
| pub fn main() { | |
| let mut v8 = rng_v8(); | |
| let mut v9 = rng_v9(); | |
| println!("--- Stable Channel Report ---"); | |
| println!("Legacy (v0.8.5) u64: {}", v8.r#gen::<u64>()); | |
| println!("Latest (v0.9.2) u64: {}", v9.r#gen::<u64>()); | |
| } | |
| } | |
| // Entry point redirector | |
| #[cfg(not(nightly))] | |
| fn main() { | |
| stable_impl::main(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment