Rust Examples

Page 6 of 8

Browse Rust examples

rustSnippet

Sort Floats With total_cmp

Sort floating-point data with f64::total_cmp, the IEEE-754 total order that gives NaN a deterministic position instead of panicking on incomparable values.

rustSnippet

Stdin Read Line With Parse Retry

Read stdin in a loop with read_line, clear and reuse one buffer, treat EOF as zero bytes, and match the parse Result so bad input retries instead of panicking.

rustSnippet

Arrays Versus Vec Fixed Sizes

Fixed-size arrays carry their length in the type, so a signature can force wrong lengths out at compile time, while Vec grows and both borrow as one slice.

rustSnippet

Match Io ErrorKind For Recovery

Classify io failures by ErrorKind instead of string matching: fall back to defaults on NotFound, refuse on PermissionDenied, and surface anything else loudly.