diff --git a/idna/Cargo.toml b/idna/Cargo.toml index 9566cc72e..7caa44595 100644 --- a/idna/Cargo.toml +++ b/idna/Cargo.toml @@ -12,6 +12,10 @@ rust-version = "1.45" [lib] doctest = false +[features] +default = ["std"] +std = [] + [[test]] name = "tests" harness = false @@ -26,8 +30,8 @@ tester = "0.9" serde_json = "1.0" [dependencies] -unicode-bidi = "0.3" -unicode-normalization = "0.1.17" +unicode-bidi = { version = "0.3.7", default-features = false } +unicode-normalization = { version = "0.1.17", default-features = false } [[bench]] name = "all" diff --git a/idna/src/lib.rs b/idna/src/lib.rs index 37d638741..a4d03c08a 100644 --- a/idna/src/lib.rs +++ b/idna/src/lib.rs @@ -31,11 +31,19 @@ //! > This document specifies a mechanism //! > that minimizes the impact of this transition for client software, //! > allowing client software to access domains that are valid under either system. +#![no_std] + +extern crate alloc; + +#[cfg(feature = "std")] +extern crate std; #[cfg(test)] #[macro_use] extern crate assert_matches; +use alloc::string::String; + pub mod punycode; mod uts46; diff --git a/idna/src/punycode.rs b/idna/src/punycode.rs index 21955f359..faef379ca 100644 --- a/idna/src/punycode.rs +++ b/idna/src/punycode.rs @@ -13,8 +13,9 @@ //! `encode_str` and `decode_to_string` provide convenience wrappers //! that convert from and to Rust’s UTF-8 based `str` and `String` types. -use std::char; -use std::u32; +use alloc::{string::String, vec::Vec}; +use core::char; +use core::u32; // Bootstring parameters for Punycode static BASE: u32 = 36; @@ -168,7 +169,7 @@ impl Decoder { } pub(crate) struct Decode<'a> { - base: std::str::Chars<'a>, + base: core::str::Chars<'a>, pub(crate) insertions: &'a [(usize, char)], inserted: usize, position: usize, diff --git a/idna/src/uts46.rs b/idna/src/uts46.rs index 9ee83bc88..6c7d82cd4 100644 --- a/idna/src/uts46.rs +++ b/idna/src/uts46.rs @@ -11,7 +11,9 @@ use self::Mapping::*; use crate::punycode; -use std::{error::Error as StdError, fmt}; + +use alloc::string::String; +use core::fmt; use unicode_bidi::{bidi_class, BidiClass}; use unicode_normalization::char::is_combining_mark; use unicode_normalization::{is_nfc, UnicodeNormalization}; @@ -70,10 +72,10 @@ fn find_char(codepoint: char) -> &'static Mapping { } struct Mapper<'a> { - chars: std::str::Chars<'a>, + chars: core::str::Chars<'a>, config: Config, errors: &'a mut Errors, - slice: Option>, + slice: Option>, } impl<'a> Iterator for Mapper<'a> { @@ -697,7 +699,8 @@ impl From for Result<(), Errors> { } } -impl StdError for Errors {} +#[cfg(feature = "std")] +impl std::error::Error for Errors {} impl fmt::Display for Errors { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {