Sha256: 6705cb3025ca782190e15089689d8cd248b02941bb43fcf4cbf3555c5b5a6e8f
Contents?: true
Size: 844 Bytes
Versions: 3
Compression:
Stored size: 844 Bytes
Contents
use crate::{Arbitrary, Result, Unstructured}; impl<'a> Arbitrary<'a> for char { fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { // The highest unicode code point is 0x11_FFFF const CHAR_END: u32 = 0x11_0000; // The size of the surrogate blocks const SURROGATES_START: u32 = 0xD800; let mut c = <u32 as Arbitrary<'a>>::arbitrary(u)? % CHAR_END; if let Some(c) = char::from_u32(c) { Ok(c) } else { // We found a surrogate, wrap and try again c -= SURROGATES_START; Ok(char::from_u32(c) .expect("Generated character should be valid! This is a bug in arbitrary-rs")) } } #[inline] fn size_hint(depth: usize) -> (usize, Option<usize>) { <u32 as Arbitrary<'a>>::size_hint(depth) } }
Version data entries
3 entries across 3 versions & 1 rubygems