Skip to content

Commit 873aa80

Browse files
committed
Add documentation to explain generate_ascii
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 9d37c86 commit 873aa80

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

rosidl_runtime_rs/src/string.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,15 @@ mod tests {
522522
}
523523
}
524524

525+
/// If we use char::arbitrary(g) then we can get back characters which are
526+
/// outside the ASCII range. Since the length calculated by [`String`] is
527+
/// based on the utf-8 length of the string (not based on the number of bytes
528+
/// in the string), putting non-ASCII characters into it can skew the length
529+
/// calculation in strange ways.
530+
///
531+
/// This function generates only ASCII characters by cutting their values
532+
/// off at 127. This does not give an even distribution of ASCII characters,
533+
/// but that fact is not important for this smoke test.
525534
fn generate_ascii(g: &mut Gen) -> char {
526535
let c = u8::min(u8::arbitrary(g), 127);
527536
c as char

0 commit comments

Comments
 (0)