Description
Motivation
Preliminary
While str
guarantees statically that data of its type is valid UTF-8, the type Ascii
guarantees ASCII-conformance. Therefore the types [Ascii]
and str
and their owned counterparts Vec<Ascii>
and String
should behave similar.
Topic of this Issue
Ascii
provides functions like to_uppercase()
and to_lowercase()
which can be applied to single ascii-characters. Currently such operations are not implemented on owned or borrowed strings of ascii-characters. As the types Vec<Ascii>
and [Ascii]
should be opaque manually implementing the iteration isn't recommended because it is a implementation detail of these types.
Example:
error: type `&[Ascii]` does not implement any method in scope named `to_uppercase`
let _ = "abcXYZ".to_ascii().unwrap().to_uppercase();
^~~~~~~~~~~~~~~~~~~~
Design
The types String
and str
provide functionality for converting to uppercase and lowercase with their implementations of the traits std::ascii::{AsciiExt, OwnedAsciiExt}
. These traits are intended for "[…] ASCII-subset only operations on string slices" and owned strings. Of course Vec<Ascii>
and [Ascii]
are subsets of ascii, they are equivalent so it's valid to implement them for the ascii only string types.
Implement the traits:
impl AsciiExt<Vec<Ascii>> for [Ascii]
impl AsciiExt for Ascii
impl OwnedAsciiExt for Vec<Ascii>
The implementations use functionality present in Ascii
if possible.
Design flaws
- The traits
std::ascii::{AsciiExt, OwnedAsciiExt}
are marked experimental. This shouldn't be a real issue as I expect this crate to follow the way conversions are done in the standard library. - All functions declared by the traits
std::ascii::{AsciiExt, OwnedAsciiExt}
carry the infixascii
which is redundant in the case the traits are implemented onVec<Ascii>
,[Ascii]
andAscii
. This redundancy must be tolerated to achieve the goals described above.
Drawbacks
- Duplicate implementations arise because the type
Ascii
implements the same functionality in the functionsto_uppercase()
/to_ascii_uppercase()
andto_lowercase()
andto_ascii_lowercase()
.
Further considerations after discussion
- Deprecate and remove the functions
to_uppercase()
andto_lowercase()
onAscii
in favour of their equivalents inAsciiExt
. That removes the duplication mentioned in the drawbacks.