Skip to content

Commit 0865315

Browse files
committed
Make this crate no_std
As almost nothing actually depends on std, there is no need to keep a dependency on it. This allows users such as the jid crate to actually be no_std as well. The only exception is std::error::Error, which is now exposed as core::error::Error in nightly but not yet stabilized, see rust-lang/rust#103765
1 parent 97e2588 commit 0865315

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ readme = "README.md"
1111
unicode-bidi = "0.3"
1212
unicode-normalization = "0.1"
1313
unicode-properties = "0.1.1"
14+
15+
[features]
16+
default = ["std"]
17+
std = []

src/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
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;
7+
#[cfg(feature = "std")]
8+
extern crate std;
59
extern crate unicode_bidi;
610
extern crate unicode_normalization;
711
extern crate unicode_properties;
812

9-
use std::borrow::Cow;
10-
use std::fmt;
13+
use alloc::borrow::Cow;
14+
use alloc::string::String;
15+
use core::fmt;
1116
use unicode_normalization::UnicodeNormalization;
1217
use unicode_properties::{GeneralCategoryGroup, UnicodeGeneralCategory};
1318

@@ -44,6 +49,11 @@ impl fmt::Display for Error {
4449
}
4550
}
4651

52+
// TODO: We can remove this feature check and use core::error::Error directly once it gets
53+
// stabilized, see https://github.com/rust-lang/rust/issues/103765
54+
//
55+
// For now we could use it in nightly with #![feature(error_in_core)] but hopefully not for long.
56+
#[cfg(feature = "std")]
4757
impl std::error::Error for Error {}
4858

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

src/tables.rs

+2-2
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)