17 releases (6 stable)

2.0.2 Aug 25, 2018
2.0.1 Nov 30, 2017
2.0.0 Oct 21, 2017
1.0.2 Oct 21, 2017
0.1.3 Jun 14, 2015

#1 in Encoding

Download history 51179/week @ 2018-06-03 62752/week @ 2018-06-10 57685/week @ 2018-06-17 63102/week @ 2018-06-24 64093/week @ 2018-07-01 60114/week @ 2018-07-08 63263/week @ 2018-07-15 65307/week @ 2018-07-22 60590/week @ 2018-07-29 65202/week @ 2018-08-05 63152/week @ 2018-08-12 61104/week @ 2018-08-19 62805/week @ 2018-08-26

266,775 downloads per month
Used in 3,887 crates (63 directly)

Unlicense/MIT

118KB
2.5K SLoC

This crate provides a safe interface libc's memchr and memrchr. This crate also provides fallback implementations when either function is unavailable.

Build status Build status

Dual-licensed under MIT or the UNLICENSE.

Documentation

https://docs.rs/memchr

no_std

memchr links to the standard library by default, but you can disable the use_std feature if you want to use it in a #![no_std] crate:

[dependencies]
memchr = { version = "2", default-features = false }

Performance

On my system (Linux/amd64), memchr is about an order of magnitude faster than the more idiomatic haystack.iter().position(|&b| b == needle):

test iterator          ... bench:       5,280 ns/iter (+/- 13) = 1893 MB/s
test iterator_reversed ... bench:       5,271 ns/iter (+/- 7) = 1897 MB/s
test libc_memchr       ... bench:         202 ns/iter (+/- 0) = 49504 MB/s
test libc_memrchr      ... bench:         197 ns/iter (+/- 1) = 50761 MB/s

Dependencies

~170KB