Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 175d8e8

Browse files
committedApr 19, 2019
Implemented the Needle API (RFC 2500).
1 parent fcd71f6 commit 175d8e8

File tree

6 files changed

+2311
-0
lines changed

6 files changed

+2311
-0
lines changed
 

‎src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub mod fmt;
211211
pub mod time;
212212

213213
pub mod unicode;
214+
pub mod needle;
214215

215216
/* Async */
216217
pub mod future;

‎src/libcore/needle/ext.rs

+969
Large diffs are not rendered by default.

‎src/libcore/needle/haystack.rs

+720
Large diffs are not rendered by default.

‎src/libcore/needle/mod.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![unstable(feature = "needle", issue = "56345")]
2+
3+
//! The Needle API, support generalized searching on strings, arrays and more.
4+
//!
5+
//! This module provides traits to facilitate searching [`Needle`] in a [`Haystack`].
6+
//!
7+
//! Haystacks
8+
//! =========
9+
//!
10+
//! A *haystack* refers to any linear structure which can be split or sliced
11+
//! into smaller, non-overlapping parts. Examples are strings and vectors.
12+
//!
13+
//! ```rust
14+
//! let haystack: &str = "hello"; // a string slice (`&str`) is a haystack.
15+
//! let (a, b) = haystack.split_at(4); // it can be split into two strings.
16+
//! let c = &a[1..3]; // it can be sliced.
17+
//! ```
18+
//!
19+
//! The minimal haystack which cannot be further sliced is called a *codeword*.
20+
//! For instance, the codeword of a string would be a UTF-8 sequence. A haystack
21+
//! can therefore be viewed as a consecutive list of codewords.
22+
//!
23+
//! The boundary between codewords can be addressed using an *index*. The
24+
//! numbers 1, 3 and 4 in the snippet above are sample indices of a string. An
25+
//! index is usually a `usize`.
26+
//!
27+
//! An arbitrary number may point outside of a haystack, or in the interior of a
28+
//! codeword. These indices are invalid. A *valid index* of a certain haystack
29+
//! would only point to the boundaries.
30+
31+
mod haystack;
32+
mod needle;
33+
pub mod ext;
34+
35+
pub use self::haystack::*;
36+
pub use self::needle::*;

‎src/libcore/needle/needle.rs

+582
Large diffs are not rendered by default.

‎src/libstd/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
#![feature(link_args)]
275275
#![feature(linkage)]
276276
#![feature(maybe_uninit)]
277+
#![feature(needle)]
277278
#![feature(needs_panic_runtime)]
278279
#![feature(never_type)]
279280
#![feature(nll)]
@@ -437,6 +438,8 @@ pub use core::char;
437438
pub use core::u128;
438439
#[stable(feature = "core_hint", since = "1.27.0")]
439440
pub use core::hint;
441+
#[unstable(feature = "needle", issue = "56345")]
442+
pub use core::needle;
440443

441444
pub mod f32;
442445
pub mod f64;

0 commit comments

Comments
 (0)
Please sign in to comment.