mirror of
https://github.com/openharmony/third_party_rust_rust-std-candidates.git
synced 2026-07-01 20:44:02 -04:00
8c641e7d88b1cb40cb466e7ddb097f070ec8b5b0
These are candidates for addition to the Rust standard library. Each crate is published separately on crate.io
The matches! macro
A macro to evaluate, as a boolean, whether an expression matches a pattern.
#![feature(phase)]
#[phase(plugin)] extern crate matches;
fn is_slash(input: &str, pos: uint) -> bool {
matches!(input.char_at(pos), '/' | '\\')
}
#![feature(phase)]
#[phase(plugin)] extern crate matches;
extern crate serialize;
use serialize::json::Json;
fn object_has_key(json: &Json, key: &str) -> bool {
matches!(json, &Json::Object(ref obj) if obj.contains_key(key))
}
The zip_longest iterator adaptor
The standard library has an iterator.zip(other_iterator) method
that returns a new iterator that yields pairs,
and stops when one of the input iterators does.
zip_longest is similar,
but instead continues until both iterators are exhausted.
Instead of a pair of values (A, B),
it yield pairs of optional values (Option<A>, Option<B>),
where None indicates that one of the input iterator was exhausted before the other.
((None, None) never occurs.)
extern crate "zip-longest" as zip_longest;
use zip_longest::ZipLongestIteratorExt;
fn iter_eq<I, J, T>(i: I, j: J) -> bool
where I: Iterator<T>, J: Iterator<T>, T: Eq {
i.zip_longest(j).all(|(a, b)| a == b)
}
Languages
Rust
97.4%
Makefile
2.6%