#iterator #string #chars #owned

owned_chars

Owned iterators with the same output as Chars and CharIndices

7 releases

Uses old Rust 2015

0.3.2 Dec 20, 2020
0.3.1 Mar 15, 2020
0.3.0 May 22, 2018
0.2.1 Jan 20, 2017
0.1.0 Dec 18, 2015

#715 in Text processing

Download history 65/week @ 2024-01-05 154/week @ 2024-01-12 68/week @ 2024-01-19 33/week @ 2024-01-26 48/week @ 2024-02-02 65/week @ 2024-02-09 70/week @ 2024-02-16 141/week @ 2024-02-23 85/week @ 2024-03-01 76/week @ 2024-03-08 67/week @ 2024-03-15 57/week @ 2024-03-22 98/week @ 2024-03-29 64/week @ 2024-04-05 60/week @ 2024-04-12 46/week @ 2024-04-19

278 downloads per month
Used in 12 crates (5 directly)

MIT/Apache

8KB
91 lines

owned-chars

Travis CI

This crate provides an extension trait for String with two methods, into_chars and into_char_indices. These methods parallel String::chars and String::char_indices, but the iterators they create consume the String instead of borrowing it.

Release notes

  • 0.3.0
    • Rewrite to use delegate crate
    • Fix/breaking change: OwnedChars::as_str works the same way as std::Chars::as_str

Example

use owned_chars::OwnedChars;

fn main() {
    let mut chars = OwnedChars::from_string("0123456789ABCDEF".to_owned());
    let next_is_digit = |chars: &mut OwnedChars| chars.next().map_or(false, |c| c.is_numeric());

    assert!(next_is_digit(&mut chars)); // 0
    assert!(next_is_digit(&mut chars)); // 1
    assert!(next_is_digit(&mut chars)); // 2
    assert!(next_is_digit(&mut chars)); // 3
    assert!(next_is_digit(&mut chars)); // 4
    assert!(next_is_digit(&mut chars)); // 5
    assert!(next_is_digit(&mut chars)); // 6
    assert!(next_is_digit(&mut chars)); // 7
    assert!(next_is_digit(&mut chars)); // 8
    assert!(next_is_digit(&mut chars)); // 9

    assert!(!next_is_digit(&mut chars)); // A
    assert!(!next_is_digit(&mut chars)); // B
    assert!(!next_is_digit(&mut chars)); // C
    assert!(!next_is_digit(&mut chars)); // D
    assert!(!next_is_digit(&mut chars)); // E
    assert!(!next_is_digit(&mut chars)); // F
}

Dependencies

~1.5MB
~34K SLoC