Skip to content

Commit a9773b1

Browse files
committed
Add and update documentation
1 parent db7baed commit a9773b1

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ Types and conversion traits are described in the
88

99
# Using ascii without libstd
1010

11-
Most of `AsciiChar` and `AsciiStr` can be used without `std` by enabling the feature `no_std`. The
12-
owned string type `AsciiString` and the conversion trait `IntoAsciiString` as well as all methods
13-
referring to these types aren't available without `std`.
11+
Most of `AsciiChar` and `AsciiStr` can be used without `std` by enabling the feature `no_std`.
12+
The owned string type `AsciiString` and the conversion trait `IntoAsciiString` as well as all methods referring to these types are unavailable.
13+
Because libcore doesn't have `AsciiExt` and `Error`, most of their methods are implemented directly:
14+
* `Ascii{Char,Str}::eq_ignore_ascii_case()`
15+
* `AsciiChar::to_ascii_{upper,lower}case()`
16+
* `AsciiStr::make_ascii_{upper,lower}case()`
17+
* `{ToAsciiChar,AsAsciiStr}Error::description()`
1418

1519
# Requirements
1620

RELEASES.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
Unreleased
22
==========
33
* Return `FromAsciiError` instead of the input when `AsciiString::from_ascii()` or `into_ascii_string()` fails.
4+
* Fix `AsciiChar::to_ascii_lowercase()` converting to uppercase. (introduced by 0.7.0)
45
* Make `AsciiChar` comparable with `char` and `u8`.
56
* Add `AsciiChar::as_printable_char()` and the free functions `caret_encode()` and `caret_decode()`.
6-
* Fix the implementation of `AsciiExt::to_ascii_lowercase()` for `AsciiChar` converting to uppercase. (introduced in 0.7.0)
7+
* Implement some methods from `AsciiExt` and `Error` (which are not in libcore) directly in `no_std` mode:
8+
* `Ascii{Char,Str}::eq_ignore_ascii_case()`
9+
* `AsciiChar::to_ascii_{upper,lower}case()`
10+
* `AsciiStr::make_ascii_{upper,lower}case()`
11+
* `{ToAsciiChar,AsAsciiStr}Error::description()`
712

813
Version 0.7.0 (2016-06-25)
914
==========================

src/ascii_char.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@ impl AsciiChar {
474474
}
475475

476476
#[cfg(feature = "no_std")]
477+
/// Maps letters `a`...`z` to `A`...`Z` and returns everything else unchanged.
478+
///
479+
/// A replacement for `AsciiExt::to_ascii_uppercase()`.
477480
pub fn to_ascii_uppercase(&self) -> Self {
478481
unsafe{ match *self as u8 {
479482
b'a'...b'z' => AsciiChar::from_unchecked(self.as_byte() - (b'a' - b'A')),
@@ -482,6 +485,9 @@ impl AsciiChar {
482485
}
483486

484487
#[cfg(feature = "no_std")]
488+
/// Maps letters `A`...`Z` to `a`...`z` and returns everything else unchanged.
489+
///
490+
/// A replacement for `AsciiExt::to_ascii_lowercase()`.
485491
pub fn to_ascii_lowercase(&self) -> Self {
486492
unsafe{ match *self as u8 {
487493
b'A'...b'Z' => AsciiChar::from_unchecked(self.as_byte() + (b'a' - b'A')),
@@ -490,6 +496,9 @@ impl AsciiChar {
490496
}
491497

492498
#[cfg(feature = "no_std")]
499+
/// Compares two characters case-insensitively.
500+
///
501+
/// A replacement for `AsciiExt::eq_ignore_ascii_case()`.
493502
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool {
494503
self.to_ascii_lowercase() == other.to_ascii_lowercase()
495504
}
@@ -578,6 +587,7 @@ const ERRORMSG_CHAR: &'static str = "not an ASCII character";
578587

579588
#[cfg(feature = "no_std")]
580589
impl ToAsciiCharError {
590+
/// Returns a description for this error, like `std::error::Error::description`.
581591
pub fn description(&self) -> &'static str {
582592
ERRORMSG_CHAR
583593
}

src/ascii_str.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,28 @@ impl AsciiStr {
168168
}
169169

170170
#[cfg(feature = "no_std")]
171+
/// Compares two strings case-insensitively.
172+
///
173+
/// A replacement for `AsciiExt::eq_ignore_ascii_case()`.
171174
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool {
172175
self.len() == other.len() &&
173176
self.slice.iter().zip(other.slice.iter()).all(|(a, b)| a.eq_ignore_ascii_case(b) )
174177
}
175178

176179
#[cfg(feature = "no_std")]
180+
/// Replaces lowercase letters with their uppercase equivalent.
181+
///
182+
/// A replacement for `AsciiExt::make_ascii_uppercase()`.
177183
pub fn make_ascii_uppercase(&mut self) {
178184
for a in &mut self.slice {
179185
*a = a.to_ascii_uppercase();
180186
}
181187
}
182188

183189
#[cfg(feature = "no_std")]
190+
/// Replaces uppercase letters with their lowercase equivalent.
191+
///
192+
/// A replacement for `AsciiExt::make_ascii_lowercase()`.
184193
pub fn make_ascii_lowercase(&mut self) {
185194
for a in &mut self.slice {
186195
*a = a.to_ascii_lowercase();
@@ -370,6 +379,7 @@ impl AsAsciiStrError {
370379
self.0
371380
}
372381
#[cfg(feature = "no_std")]
382+
/// Returns a description for this error, like `std::error::Error::description`.
373383
pub fn description(&self) -> &'static str {
374384
ERRORMSG_STR
375385
}
@@ -381,7 +391,6 @@ impl fmt::Display for AsAsciiStrError {
381391
}
382392
#[cfg(not(feature = "no_std"))]
383393
impl Error for AsAsciiStrError {
384-
/// Returns "one or more bytes are not ASCII"
385394
fn description(&self) -> &'static str {
386395
ERRORMSG_STR
387396
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy