Skip to content

Commit 0bdcfaf

Browse files
committed
build: gate regex API on 'std' feature
This commit adds a new 'std' feature and enables it by default. This permits us to one day add support for building regex without 'std' (but with 'alloc', probably) by avoiding the introduction of incompatibilities. Namely, this setup ensures that all of today's uses of '--no-default-features' won't compile without also adding the 'std' feature. Closes #457
1 parent 202c054 commit 0bdcfaf

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ quickcheck = { version = "0.6", default-features = false }
4343
rand = "0.4"
4444

4545
[features]
46-
# We don't enable any features by default currently, but if the compiler
47-
# supports a specific type of feature, then regex's build.rs might enable
48-
# some default features.
49-
default = []
46+
default = ["std"]
47+
# The 'std' feature permits the regex crate to use the standard library.
48+
# This is intended to support future use cases where the regex crate may be
49+
# able to compile without std, and instead just rely on 'core' and 'alloc'
50+
# (for example). Currently, this isn't supported, and removing the 'std'
51+
# feature will prevent regex from compiling.
52+
std = []
5053
# A blanket feature that governs whether unstable features are enabled or not.
5154
# Unstable features are disabled by default, and typically rely on unstable
5255
# features in rustc itself.

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let version = String::from_utf8(output).unwrap();
1313

1414
// If we're using nightly Rust, then we can enable vector optimizations.
15-
// Note that these aren't actually activated unless the `nightly` feature
15+
// Note that these aren't actually activated unless the `unstable` feature
1616
// is enabled.
1717
//
1818
// We also don't activate these if we've explicitly disabled auto

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,17 @@ extern crate quickcheck;
530530
extern crate regex_syntax as syntax;
531531
extern crate utf8_ranges;
532532

533+
#[cfg(feature = "std")]
533534
pub use error::Error;
535+
#[cfg(feature = "std")]
534536
pub use re_builder::unicode::*;
537+
#[cfg(feature = "std")]
535538
pub use re_builder::set_unicode::*;
539+
#[cfg(feature = "std")]
536540
pub use re_set::unicode::*;
541+
#[cfg(feature = "std")]
537542
pub use re_trait::Locations;
543+
#[cfg(feature = "std")]
538544
pub use re_unicode::{
539545
Regex, Match, Captures,
540546
CaptureNames, Matches, CaptureMatches, SubCaptureMatches,
@@ -629,6 +635,7 @@ When the `s` flag is enabled, `.` matches any byte.
629635
In general, one should expect performance on `&[u8]` to be roughly similar to
630636
performance on `&str`.
631637
*/
638+
#[cfg(feature = "std")]
632639
pub mod bytes {
633640
pub use re_builder::bytes::*;
634641
pub use re_builder::set_bytes::*;
@@ -664,6 +671,7 @@ mod vector;
664671
/// testing different matching engines and supporting the `regex-debug` CLI
665672
/// utility.
666673
#[doc(hidden)]
674+
#[cfg(feature = "std")]
667675
pub mod internal {
668676
pub use compile::Compiler;
669677
pub use exec::{Exec, ExecBuilder};

0 commit comments

Comments
 (0)