Skip to content

Commit 5141360

Browse files
committed
Make unicode-width an optional default dependency
1 parent 57b183a commit 5141360

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ edition = "2021"
1010
rust-version = "1.66"
1111

1212
[dependencies]
13-
unicode-width = "0.2.0"
13+
unicode-width = { version = "0.2.0", optional = true }
1414
std = { version = "1.0", package = "rustc-std-workspace-std", optional = true }
1515
core = { version = "1.0", package = "rustc-std-workspace-core", optional = true }
1616

1717
[dev-dependencies]
1818
log = "0.4"
1919

2020
[features]
21+
default = ["unicode"]
2122
rustc-dep-of-std = ["unicode-width/rustc-dep-of-std", "std", "core"]
23+
unicode = ["dep:unicode-width"]

src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
#[cfg(test)]
105105
#[macro_use]
106106
extern crate log;
107-
extern crate unicode_width;
108107

109108
use self::Fail::*;
110109
use self::HasArg::*;
@@ -119,8 +118,21 @@ use std::iter::{repeat, IntoIterator};
119118
use std::result;
120119
use std::str::FromStr;
121120

121+
#[cfg(feature = "unicode")]
122122
use unicode_width::UnicodeWidthStr;
123123

124+
#[cfg(not(feature = "unicode"))]
125+
trait UnicodeWidthStr {
126+
fn width(&self) -> usize;
127+
}
128+
129+
#[cfg(not(feature = "unicode"))]
130+
impl UnicodeWidthStr for str {
131+
fn width(&self) -> usize {
132+
self.len()
133+
}
134+
}
135+
124136
#[cfg(test)]
125137
mod tests;
126138

0 commit comments

Comments
 (0)