Skip to content

Commit

Permalink
Make this crate no_std
Browse files Browse the repository at this point in the history
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
  • Loading branch information
linkmauve committed Jun 23, 2024
1 parent 97e2588 commit 0865315
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ readme = "README.md"
unicode-bidi = "0.3"
unicode-normalization = "0.1"
unicode-properties = "0.1.1"

[features]
default = ["std"]
std = []
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/tables.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down

0 comments on commit 0865315

Please sign in to comment.