diff --git a/Cargo.toml b/Cargo.toml index e7223e5..034f399 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,7 @@ readme = "README.md" unicode-bidi = "0.3" unicode-normalization = "0.1" unicode-properties = "0.1.1" + +[features] +default = ["std"] +std = [] diff --git a/src/lib.rs b/src/lib.rs index 7027761..2cdb25d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,13 +1,18 @@ //! An implementation of the "stringprep" algorithm defined in [RFC 3454][]. //! //! [RFC 3454]: https://tools.ietf.org/html/rfc3454 +#![no_std] #![warn(missing_docs)] +extern crate alloc; +#[cfg(feature = "std")] +extern crate std; extern crate unicode_bidi; extern crate unicode_normalization; extern crate unicode_properties; -use std::borrow::Cow; -use std::fmt; +use alloc::borrow::Cow; +use alloc::string::String; +use core::fmt; use unicode_normalization::UnicodeNormalization; use unicode_properties::{GeneralCategoryGroup, UnicodeGeneralCategory}; @@ -44,6 +49,11 @@ impl fmt::Display for Error { } } +// TODO: We can remove this feature check and use core::error::Error directly once it gets +// stabilized, see https://github.com/rust-lang/rust/issues/103765 +// +// For now we could use it in nightly with #![feature(error_in_core)] but hopefully not for long. +#[cfg(feature = "std")] impl std::error::Error for Error {} /// Prepares a string with the SASLprep profile of the stringprep algorithm. diff --git a/src/tables.rs b/src/tables.rs index 3eccb35..ecee304 100644 --- a/src/tables.rs +++ b/src/tables.rs @@ -1,6 +1,6 @@ //! Character Tables -use std::cmp::Ordering; -use std::str::Chars; +use core::cmp::Ordering; +use core::str::Chars; use unicode_bidi::{bidi_class, BidiClass}; use unicode_properties::{GeneralCategoryGroup, UnicodeGeneralCategory};