Giter Club home page Giter Club logo

owned-chars's Introduction

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
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.