Skip to content

Commit 7af5bd9

Browse files
committed
Make this crate no_std
This allows users such as the jid crate to actually be no_std as well. core::error::Error got stabilized back in Rust 1.81.0, but in order to support older Rust versions we added a std feature.
1 parent 97e2588 commit 7af5bd9

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- uses: actions/checkout@v3
5555
- uses: sfackler/actions/rustup@master
5656
with:
57-
version: 1.56.0
57+
version: 1.81.0
5858
- run: echo "version=$(rustc --version)" >> $GITHUB_OUTPUT
5959
id: rust-version
6060
- uses: actions/cache@v3

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ license = "MIT/Apache-2.0"
66
description = "An implementation of the stringprep algorithm"
77
repository = "https://github.com/sfackler/rust-stringprep"
88
readme = "README.md"
9+
rust-version = "1.81.0" # For core::error::Error
910

1011
[dependencies]
1112
unicode-bidi = "0.3"
1213
unicode-normalization = "0.1"
1314
unicode-properties = "0.1.1"
15+
16+
[features]
17+
std = []

src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
//! An implementation of the "stringprep" algorithm defined in [RFC 3454][].
22
//!
33
//! [RFC 3454]: https://tools.ietf.org/html/rfc3454
4+
#![no_std]
45
#![warn(missing_docs)]
6+
extern crate alloc;
57
extern crate unicode_bidi;
68
extern crate unicode_normalization;
79
extern crate unicode_properties;
810

9-
use std::borrow::Cow;
10-
use std::fmt;
11+
#[cfg(feature = "std")]
12+
extern crate std;
13+
14+
use alloc::borrow::Cow;
15+
use alloc::string::String;
16+
use core::fmt;
1117
use unicode_normalization::UnicodeNormalization;
1218
use unicode_properties::{GeneralCategoryGroup, UnicodeGeneralCategory};
1319

@@ -44,7 +50,10 @@ impl fmt::Display for Error {
4450
}
4551
}
4652

53+
#[cfg(feature = "std")]
4754
impl std::error::Error for Error {}
55+
#[cfg(not(feature = "std"))]
56+
impl core::error::Error for Error {}
4857

4958
/// Prepares a string with the SASLprep profile of the stringprep algorithm.
5059
///

src/tables.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Character Tables
2-
use std::cmp::Ordering;
3-
use std::str::Chars;
2+
use core::cmp::Ordering;
3+
use core::str::Chars;
44
use unicode_bidi::{bidi_class, BidiClass};
55
use unicode_properties::{GeneralCategoryGroup, UnicodeGeneralCategory};
66

0 commit comments

Comments
 (0)