Skip to content

Commit

Permalink
Merge pull request #36 from dvdhrm/pr/nostd
Browse files Browse the repository at this point in the history
nostd: remove left-overs from `no_std` feature flag
  • Loading branch information
Manishearth committed Apr 11, 2024
2 parents fda272b + 3a57d02 commit 7c489c3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 26 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ compiler_builtins = { version = "0.1", optional = true }

[features]
default = []
no_std = []
bench = []
rustc-dep-of-std = ['std', 'core', 'compiler_builtins']

# Legacy, now a no-op
no_std = []
2 changes: 0 additions & 2 deletions scripts/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ def emit_module(
module.write(
"""
pub mod charwidth {
use core::option::Option::{self, None, Some};
/// Returns the [UAX #11](https://www.unicode.org/reports/tr11/) based width of `c` by
/// consulting a multi-level lookup table.
/// If `is_cjk == true`, ambiguous width characters are treated as double width; otherwise,
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
//!
//! # features
//!
//! unicode-width supports a `no_std` feature. This eliminates dependence
//! on std, and instead uses equivalent functions from core.
//! unicode-width does not depend on `std`, so it can be used in crates
//! with the `#![no_std]` attribute.
//!
//! # crates.io
//!
Expand Down
2 changes: 0 additions & 2 deletions src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
pub const UNICODE_VERSION: (u8, u8, u8) = (15, 1, 0);

pub mod charwidth {
use core::option::Option::{self, None, Some};

/// Returns the [UAX #11](https://www.unicode.org/reports/tr11/) based width of `c` by
/// consulting a multi-level lookup table.
/// If `is_cjk == true`, ambiguous width characters are treated as double width; otherwise,
Expand Down
22 changes: 3 additions & 19 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{UnicodeWidthChar, UnicodeWidthStr};
#[cfg(feature = "bench")]
use std::iter;
#[cfg(feature = "bench")]
use test::{self, Bencher};
use test::Bencher;

use std::prelude::v1::*;

Expand Down Expand Up @@ -93,15 +93,15 @@ fn simple_width_match(c: char) -> Option<usize> {
_ => UnicodeWidthChar::width(c),
}
}
#[cfg(all(feature = "bench", not(feature = "no_std")))]
#[cfg(feature = "bench")]
#[bench]
fn enwik8(b: &mut Bencher) {
// To benchmark, download & unzip `enwik8` from https://data.deepai.org/enwik8.zip
let data_path = "bench_data/enwik8";
let string = std::fs::read_to_string(data_path).unwrap_or_default();
b.iter(|| test::black_box(UnicodeWidthStr::width(string.as_str())));
}
#[cfg(all(feature = "bench", not(feature = "no_std")))]
#[cfg(feature = "bench")]
#[bench]
fn jawiki(b: &mut Bencher) {
// To benchmark, download & extract `jawiki-20220501-pages-articles-multistream-index.txt` from
Expand Down Expand Up @@ -140,8 +140,6 @@ fn test_emoji() {
#[test]
fn test_char() {
use super::UnicodeWidthChar;
#[cfg(feature = "no_std")]
use core::option::Option::{None, Some};

assert_eq!(UnicodeWidthChar::width('h'), Some(2));
assert_eq!('h'.width_cjk(), Some(2));
Expand All @@ -156,8 +154,6 @@ fn test_char() {
#[test]
fn test_char2() {
use super::UnicodeWidthChar;
#[cfg(feature = "no_std")]
use core::option::Option::{None, Some};

assert_eq!(UnicodeWidthChar::width('\x00'), Some(0));
assert_eq!('\x00'.width_cjk(), Some(0));
Expand Down Expand Up @@ -187,17 +183,13 @@ fn test_char2() {
#[test]
fn unicode_12() {
use super::UnicodeWidthChar;
#[cfg(feature = "no_std")]
use core::option::Option::{None, Some};

assert_eq!(UnicodeWidthChar::width('\u{1F971}'), Some(2));
}

#[test]
fn test_default_ignorable() {
use super::UnicodeWidthChar;
#[cfg(feature = "no_std")]
use core::option::Option::{None, Some};

assert_eq!(UnicodeWidthChar::width('\u{E0000}'), Some(0));

Expand All @@ -209,8 +201,6 @@ fn test_default_ignorable() {
#[test]
fn test_jamo() {
use super::UnicodeWidthChar;
#[cfg(feature = "no_std")]
use core::option::Option::{None, Some};

assert_eq!(UnicodeWidthChar::width('\u{1100}'), Some(2));
assert_eq!(UnicodeWidthChar::width('\u{A97C}'), Some(2));
Expand All @@ -225,8 +215,6 @@ fn test_jamo() {
#[test]
fn test_prepended_concatenation_marks() {
use super::UnicodeWidthChar;
#[cfg(feature = "no_std")]
use core::option::Option::{None, Some};

assert_eq!(UnicodeWidthChar::width('\u{0600}'), Some(1));
assert_eq!(UnicodeWidthChar::width('\u{070F}'), Some(1));
Expand All @@ -237,8 +225,6 @@ fn test_prepended_concatenation_marks() {
#[test]
fn test_interlinear_annotation_chars() {
use super::UnicodeWidthChar;
#[cfg(feature = "no_std")]
use core::option::Option::{None, Some};

assert_eq!(UnicodeWidthChar::width('\u{FFF9}'), Some(1));
assert_eq!(UnicodeWidthChar::width('\u{FFFA}'), Some(1));
Expand All @@ -248,8 +234,6 @@ fn test_interlinear_annotation_chars() {
#[test]
fn test_hieroglyph_format_controls() {
use super::UnicodeWidthChar;
#[cfg(feature = "no_std")]
use core::option::Option::{None, Some};

assert_eq!(UnicodeWidthChar::width('\u{13430}'), Some(1));
assert_eq!(UnicodeWidthChar::width('\u{13436}'), Some(1));
Expand Down

0 comments on commit 7c489c3

Please sign in to comment.