Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit d028143

Browse files
authored
Merge pull request #250 from artichoke/dev/lopopolo-core-error
Use `core::error` for `NoSuchCaseFoldingScheme`
2 parents 75a1028 + 85697b3 commit d028143

File tree

4 files changed

+16
-61
lines changed

4 files changed

+16
-61
lines changed

Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "focaccia"
3-
version = "1.6.0" # remember to set `html_root_url` in `src/lib.rs`.
3+
version = "2.0.0" # remember to set `html_root_url` in `src/lib.rs`.
44
authors = ["Ryan Lopopolo <rjl@hyperbo.la>"]
55
license = "MIT AND Unicode-3.0"
66
edition = "2021"
@@ -26,12 +26,6 @@ include = [
2626
"/README.md",
2727
]
2828

29-
[features]
30-
default = ["std"]
31-
# Enable a dependency on the Rust `std` library. This feature implements the
32-
# `Error` trait on error structs in `focaccia`.
33-
std = []
34-
3529
[dependencies]
3630

3731
[dev-dependencies]

README.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Add this to your `Cargo.toml`:
3939

4040
```toml
4141
[dependencies]
42-
focaccia = "1.6.0"
42+
focaccia = "2.0.0"
4343
```
4444

4545
Then make case insensitive string comparisons like:
@@ -109,19 +109,8 @@ implements case folding as defined in the [Unicode standard][casemap] (see
109109

110110
## `no_std`
111111

112-
Focaccia is `no_std` compatible with an optional and enabled by default
113-
dependency on `std`. Focaccia does not link to `alloc` in its `no_std`
114-
configuration.
115-
116-
## Crate features
117-
118-
All features are enabled by default.
119-
120-
- **std** - Enable linking to the [Rust Standard Library]. Enabling this feature
121-
adds [`Error`] implementations to error types in this crate.
122-
123-
[rust standard library]: https://doc.rust-lang.org/stable/std/index.html
124-
[`error`]: https://doc.rust-lang.org/stable/std/error/trait.Error.html
112+
Focaccia is `no_std` compatible and only depends on `core`. Focaccia does not
113+
link to `alloc` in its `no_std` configuration.
125114

126115
### Minimum Supported Rust Version
127116

src/folding/mapping/mod.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,13 @@ impl FusedIterator for Iter {}
8585

8686
#[cfg(test)]
8787
mod tests {
88-
use super::Mapping;
88+
use core::fmt::Write as _;
89+
use std::string::String;
90+
91+
use super::{Mapping, Mode};
8992

9093
#[test]
91-
#[cfg(feature = "std")]
9294
fn mode_debug_is_not_empty() {
93-
use std::fmt::Write;
94-
use std::string::String;
95-
96-
use super::Mode;
97-
9895
let mut buf = String::new();
9996
write!(&mut buf, "{:?}", Mode::Full).unwrap();
10097
assert!(!buf.is_empty());
@@ -105,11 +102,7 @@ mod tests {
105102
}
106103

107104
#[test]
108-
#[cfg(feature = "std")]
109105
fn mapping_debug_is_not_empty() {
110-
use std::fmt::Write;
111-
use std::string::String;
112-
113106
let mut buf = String::new();
114107
write!(&mut buf, "{:?}", Mapping::Empty).unwrap();
115108
assert!(!buf.is_empty());
@@ -128,11 +121,7 @@ mod tests {
128121
}
129122

130123
#[test]
131-
#[cfg(feature = "std")]
132124
fn mapping_iter_debug_is_not_empty() {
133-
use std::fmt::Write;
134-
use std::string::String;
135-
136125
let mut buf = String::new();
137126
write!(&mut buf, "{:?}", Mapping::Empty.into_iter()).unwrap();
138127
assert!(!buf.is_empty());

src/lib.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,8 @@
8282
//!
8383
//! # `no_std`
8484
//!
85-
//! Focaccia is `no_std` compatible. By default, Focaccia builds with its
86-
//! **std** feature enabled to implement [`Error`].
87-
//!
88-
//! When built without the **std** feature, Focaccia does not link to `alloc`.
89-
//!
90-
//! # Crate features
91-
//!
92-
//! All features are enabled by default.
93-
//!
94-
//! - **std** - Enable linking to the [Rust Standard Library]. Enabling this
95-
//! feature adds [`Error`] implementations to error types in this crate.
85+
//! Focaccia is `no_std` compatible and only depends on [`core`]. Focaccia does not
86+
//! link to `alloc` in its `no_std` configuration.
9687
//!
9788
//! # Unicode Version
9889
//!
@@ -106,13 +97,11 @@
10697
//! [Unicode case folding]: https://www.w3.org/International/wiki/Case_folding
10798
//! [`Ordering`]: core::cmp::Ordering
10899
//! [dotted and dotless I]: https://en.wikipedia.org/wiki/Dotted_and_dotless_I
109-
//! [Rust Standard Library]: https://doc.rust-lang.org/stable/std/index.html
110-
//! [`Error`]: https://doc.rust-lang.org/stable/std/error/trait.Error.html
111100
112101
#![no_std]
113-
#![doc(html_root_url = "https://docs.rs/focaccia/1.6.0")]
102+
#![doc(html_root_url = "https://docs.rs/focaccia/2.0.0")]
114103

115-
#[cfg(feature = "std")]
104+
#[cfg(any(test, doctest))]
116105
extern crate std;
117106

118107
use core::cmp::Ordering;
@@ -364,8 +353,7 @@ impl CaseFold {
364353
/// Error type for returned when a folding scheme could not be resolved in a
365354
/// [`TryFrom`] implementation.
366355
///
367-
/// When this crate's `std` feature is enabled, `NoSuchCaseFoldingScheme`
368-
/// implements [`std::error::Error`].
356+
/// `NoSuchCaseFoldingScheme` implements [`core::error::Error`].
369357
///
370358
/// # Examples
371359
///
@@ -378,8 +366,6 @@ impl CaseFold {
378366
/// assert_eq!(CaseFold::try_from(Some("lithuanian")), Ok(CaseFold::Lithuanian));
379367
/// assert_eq!(CaseFold::try_from(Some("xxx")), Err(NoSuchCaseFoldingScheme::new()));
380368
/// ```
381-
///
382-
/// [`std::error::Error`]: https://doc.rust-lang.org/stable/std/error/trait.Error.html
383369
#[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
384370
pub struct NoSuchCaseFoldingScheme {
385371
_private: (),
@@ -407,8 +393,7 @@ impl fmt::Display for NoSuchCaseFoldingScheme {
407393
}
408394
}
409395

410-
#[cfg(feature = "std")]
411-
impl std::error::Error for NoSuchCaseFoldingScheme {}
396+
impl core::error::Error for NoSuchCaseFoldingScheme {}
412397

413398
impl TryFrom<Option<&str>> for CaseFold {
414399
type Error = NoSuchCaseFoldingScheme;
@@ -439,9 +424,7 @@ impl TryFrom<Option<&[u8]>> for CaseFold {
439424
mod tests {
440425
use core::cmp::Ordering;
441426

442-
use crate::CaseFold;
443-
#[cfg(feature = "std")]
444-
use crate::NoSuchCaseFoldingScheme;
427+
use crate::{CaseFold, NoSuchCaseFoldingScheme};
445428

446429
// https://tools.ietf.org/html/draft-josefsson-idn-test-vectors-00#section-4.2
447430
#[test]
@@ -617,7 +600,6 @@ mod tests {
617600
}
618601

619602
#[test]
620-
#[cfg(feature = "std")]
621603
fn error_display_is_not_empty() {
622604
use core::fmt::Write as _;
623605
use std::string::String;
@@ -628,6 +610,7 @@ mod tests {
628610
assert!(!buf.is_empty());
629611
}
630612
}
613+
631614
// Ensure code blocks in `README.md` compile.
632615
//
633616
// This module and macro declaration should be kept at the end of the file, in

0 commit comments

Comments
 (0)