Crates.io | sorted-insert |
lib.rs | sorted-insert |
version | 0.2.3 |
source | src |
created_at | 2020-08-09 04:11:58.281038 |
updated_at | 2022-03-19 05:16:34.210196 |
description | This crate provides traits to insert elements to a sorted collection and keep the order. |
homepage | https://magiclen.org/sorted-insert |
repository | https://github.com/magiclen/sorted-insert |
max_upload_size | |
id | 274529 |
size | 11,785 |
This crate provides traits to insert elements to a sorted collection and keep the order.
use sorted_insert::SortedInsert;
let mut v = vec![1, 5];
v.sorted_insert_asc(2);
assert_eq!([1, 2, 5], v.as_slice());
use sorted_insert::SortedInsertBinary;
let mut v = vec![5, 1];
v.sorted_insert_desc_binary(2);
assert_eq!([5, 2, 1], v.as_slice());
use sorted_insert::SortedInsertByKey;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct A(i32, i32);
let mut v = vec![A(1, 10), A(2, 20)];
v.sorted_insert_asc_by_key(A(1, 15), |e| &e.1);
assert_eq!([A(1, 10), A(1, 15), A(2, 20)], v.as_slice());
Disable the default features to compile this crate without std.
[dependencies.sorted-insert]
version = "*"
default-features = false
https://crates.io/crates/sorted-insert