Debian Codegraph @

src/naive.rs

raw symbols SCIP
1 /// Count up to `(2^32)-1` occurrences of a byte in a slice
2 /// of bytes, simple
3 ///
4 /// # Example
5 ///
6 /// ```
7 /// let s = b"This is yet another Text with spaces";
8 /// let number_of_spaces = bytecount::naive_count_32(s, b' ');
9 /// assert_eq!(number_of_spaces, 6);
10 /// ```
11 pub fn naive_count_32rust-analyzer cargo bytecount 0.6.9 naive/naive_count_32().(haystack: &[u8], needle: u8) -> usize {
12 haystack.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]fold().(0, |n, c| n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().needle) as u32) as usize
13 }
14
15 /// Count occurrences of a byte in a slice of bytes, simple
16 ///
17 /// # Example
18 ///
19 /// ```
20 /// let s = b"This is yet another Text with spaces";
21 /// let number_of_spaces = bytecount::naive_count(s, b' ');
22 /// assert_eq!(number_of_spaces, 6);
23 /// ```
24 pub fn naive_countrust-analyzer cargo bytecount 0.6.9 naive/naive_count().(utf8_chars: &[u8], needle: u8) -> usize {
25 utf8_chars
26 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
27 .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]fold().(0, |n, c| n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().needle) as usize)
28 }
29
30 /// Count the number of UTF-8 encoded Unicode codepoints in a slice of bytes, simple
31 ///
32 /// This function is safe to use on any byte array, valid UTF-8 or not,
33 /// but the output is only meaningful for well-formed UTF-8.
34 ///
35 /// # Example
36 ///
37 /// ```
38 /// let swordfish = "メカジキ";
39 /// let char_count = bytecount::naive_num_chars(swordfish.as_bytes());
40 /// assert_eq!(char_count, 4);
41 /// ```
42 pub fn naive_num_charsrust-analyzer cargo bytecount 0.6.9 naive/naive_num_chars().(utf8_chars: &[u8]) -> usize {
43 utf8_chars
44 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
45 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|&&byte| (byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<i32>`]shr().6) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0b10)
46 .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().()
47 }