Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no_std + alloc support for ucd-util #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ cargo doc --all --verbose
cargo test --all --verbose
if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
cargo bench --all --verbose --no-run
# Test no_std + alloc mode for ucd-util
cargo test --lib --manifest-path ucd-util/Cargo.toml --no-default-features --features "alloc"
fi
7 changes: 7 additions & 0 deletions ucd-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ repository = "https://github.com/BurntSushi/rucd"
readme = "README.md"
keywords = ["unicode", "database", "character", "property"]
license = "MIT/Apache-2.0"

[features]
default = ["std"]
# Disable this on-by-default feature and add "alloc" to allow use in no_std builds
std = []
# Required for use in no_std builds, presently nightly-only
alloc = []
3 changes: 3 additions & 0 deletions ucd-util/src/hangul.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::{String, ToString};

use unicode_tables::jamo_short_name::JAMO_SHORT_NAME;

// This implementation should correspond to the algorithms described in
Expand Down
3 changes: 3 additions & 0 deletions ucd-util/src/ideograph.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::String;

/// A set of ranges that corresponds to the set of all ideograph codepoints.
///
/// These ranges are defined in Unicode 4.8 Table 4-13.
Expand Down
11 changes: 11 additions & 0 deletions ucd-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ canonicalization functions, you'll need to supply your own table, which can
be generated using `ucd-generate`.
*/

#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc))]

#![deny(missing_docs)]

#[cfg(all(test, not(feature = "std")))]
#[macro_use]
extern crate std;

#[cfg(all(feature = "alloc", not(feature = "std")))]
#[macro_use]
extern crate alloc;

mod hangul;
mod ideograph;
mod name;
Expand Down
6 changes: 6 additions & 0 deletions ucd-util/src/name.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::String;

/// Normalize the given character name in place according to UAX44-LM2.
///
/// See: http://unicode.org/reports/tr44/#UAX44-LM2
Expand Down Expand Up @@ -137,6 +140,9 @@ fn symbolic_name_normalize_bytes(slice: &mut [u8]) -> &mut [u8] {

#[cfg(test)]
mod tests {
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::{String, ToString};

use super::{
character_name_normalize, character_name_normalize_bytes,
symbolic_name_normalize, symbolic_name_normalize_bytes,
Expand Down