### Sort by Key Extraction Function Source: https://github.com/jakubvaltar/radsort/blob/main/README.md Shows how to sort a slice of custom types (strings in this case) by extracting a sortable key using a closure. The example sorts strings by their length. ```rust let mut friends = ["Punchy", "Isabelle", "Sly", "Puddles", "Gladys"]; // sort by the length of the string in bytes radsort::sort_by_key(&mut friends, |s| s.len()); assert_eq!(friends, ["Sly", "Punchy", "Gladys", "Puddles", "Isabelle"]); ``` -------------------------------- ### radsort::unopt::sort Functionality Source: https://github.com/jakubvaltar/radsort/wiki/Benchmarks Demonstrates the usage and behavior of the `radsort::unopt::sort` function, which sorts slices by all bytes of the key. This version is considered a worst-case scenario compared to the optimized `radsort::sort`. ```rust use radsort::unopt; fn main() { let mut data = vec![5u8, 2, 8, 1, 9]; unopt::sort(&mut data); println!("{:?}", data); } ``` -------------------------------- ### Sort Scalar Types Directly Source: https://github.com/jakubvaltar/radsort/blob/main/README.md Demonstrates sorting a slice of integers directly using the `radsort::sort` function. This is the most straightforward way to sort primitive numeric types. ```rust let mut data = [2i32, -1, 1, 0, -2]; radsort::sort(&mut data); assert_eq!(data, [-2, -1, 0, 1, 2]); ``` -------------------------------- ### Sort by Multiple Keys (Tuple) Source: https://github.com/jakubvaltar/radsort/blob/main/README.md Illustrates sorting a slice of custom structs based on multiple fields. The sorting order is determined by the tuple of fields provided to `sort_by_key`, with the first element being the primary sort key. ```rust struct Height { feet: u8, inches: u8, } let mut heights = [ Height { feet: 6, inches: 1 }, Height { feet: 5, inches: 9 }, Height { feet: 6, inches: 0 }, ]; // sort by feet, if feet are equal, sort by inches radsort::sort_by_key(&mut heights, |h| (h.feet, h.inches)); assert_eq!(heights, [ Height { feet: 5, inches: 9 }, Height { feet: 6, inches: 0 }, Height { feet: 6, inches: 1 }, ]); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.