Skip to content

Commit cb84d97

Browse files
committed
wildcard is now no_std.
1 parent 13b1a6a commit cb84d97

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repository = "https://github.com/cloudflare/wildcard"
1212
documentation = "https://docs.rs/wildcard"
1313
readme = "README.md"
1414

15-
keywords = ["wildcard", "matching"]
15+
keywords = ["wildcard", "matching", "no_std"]
1616

1717
categories = ["text-processing", "algorithms"]
1818

@@ -30,7 +30,7 @@ include = [
3030
]
3131

3232
[dependencies]
33-
thiserror = "2.0.3"
33+
thiserror = { version = "2.0.3", default-features = false }
3434

3535
[dev-dependencies]
3636
criterion = "0.5.1"

src/lib.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#![no_std]
1516
#![cfg_attr(feature = "fatal-warnings", deny(warnings))]
1617
// Note: If you change this remember to update `README.md`. To do so run `cargo rdme`.
1718
//! `wildcard` is a rust crate for wildcard matching.
@@ -72,10 +73,12 @@
7273
//! 3. Support for escaping can be disabled.
7374
//! 4. Support for case-insensitive matching.
7475
75-
use std::borrow::Cow;
76-
use std::fmt::Debug;
77-
use std::ops::Range;
78-
// TODO maybe not use thiserror so we can make the crate nostd?
76+
extern crate alloc;
77+
78+
use alloc::borrow::Cow;
79+
use alloc::vec::Vec;
80+
use core::fmt::Debug;
81+
use core::ops::Range;
7982
use thiserror::Error;
8083

8184
/// Error representing an invalid [`Wildcard`] creation.
@@ -426,7 +429,7 @@ where
426429
pub fn parsed(&self) -> impl Iterator<Item = WildcardToken<S>> + '_ {
427430
let mut i = 0;
428431

429-
std::iter::from_fn(move || {
432+
core::iter::from_fn(move || {
430433
if i >= self.pattern.len() {
431434
None
432435
} else {
@@ -741,6 +744,9 @@ where
741744
#[cfg(test)]
742745
mod tests {
743746
use crate::{Wildcard, WildcardBuilder, WildcardError, WildcardToken};
747+
use alloc::string::String;
748+
use alloc::vec::Vec;
749+
use alloc::{format, vec};
744750
use quickcheck::{Arbitrary, Gen};
745751
use quickcheck_macros::quickcheck;
746752

@@ -750,6 +756,9 @@ mod tests {
750756

751757
pub mod engine_regex_bytes {
752758
use crate::{Wildcard, WildcardToken};
759+
use alloc::borrow::ToOwned;
760+
use alloc::string::String;
761+
use alloc::vec::Vec;
753762
use regex::bytes::{Regex, RegexBuilder};
754763

755764
fn make_regex(pattern: &str, case_insensitive: bool) -> Regex {
@@ -766,7 +775,7 @@ mod tests {
766775
}
767776
WildcardToken::Symbol(s) => {
768777
let slice = &[s];
769-
let s = std::str::from_utf8(slice).expect("invalid utf-8 symbol");
778+
let s = core::str::from_utf8(slice).expect("invalid utf-8 symbol");
770779
regex_pattern.push_str(&regex::escape(s));
771780
}
772781
}
@@ -1392,7 +1401,7 @@ mod tests {
13921401
WildcardToken::MetasymbolAny | WildcardToken::MetasymbolOne => {
13931402
let fill = captures.next().expect("must be present");
13941403

1395-
pattern_filled_in.push_str(std::str::from_utf8(fill).expect("invalid utf-8"));
1404+
pattern_filled_in.push_str(core::str::from_utf8(fill).expect("invalid utf-8"));
13961405
}
13971406
WildcardToken::Symbol(b) => pattern_filled_in.push(char::from(b)),
13981407
}

0 commit comments

Comments
 (0)