-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Vec<Ascii>
and [Ascii]
with newtypes
#6
Conversation
I don't know if I missed to implement important traits. Due to the missing tests I'm not sure if everything works as it should. @frewsxcv Do you want to test this in your code for feedback? |
So I'm a little confused, why did all of this stuff get changed? |
I planned to replace Now the new coherence rules also made it difficult to do something like The new generic conversation traits just replaced some specialized traits in this library, similar to what happened in std. I just found some traits I want to implement additionally like |
} | ||
} | ||
|
||
impl PartialEq for AsciiString { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use derive(PartialEq)
for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, also Eq
, PartialOrd
, Ord
and Hash
can be derived on AsciiString
. On AsciiStr
only Hash
can be derived because of rust-lang/rust#23649.
Looks alright with me |
dec4b19
to
50bc785
Compare
@tomprogrammer Need any help with getting the tests to pass? |
@frewsxcv Yes, that would be great. I can't work on it at the moment, exams want to be done. I learned that the types |
I've decided not to throw away |
The ascii crate now provides types for owned ascii strings and borrowed ascii slices. Their implementation should allow them to be used like `String` and `str`. Changes: - `AsciiString` replaces `Vec<Ascii>` - `AsciiStr` replaces `[Ascii]` - Remove traits `IntoString`, `IntoBytes` and `AsciiStr` Migration (for details see new implementations): - You can't construct `AsciiString` and `AsciiStr` like a collection anymore, use the `from_bytes` or `from_str` method instead. - To convert from the ascii types to bytes or strings please use the new generic conversion traits `Into` and `AsRef` instead of `IntoString`, `IntoBytes` or `AsciiStr`. - The AsciiCast and OwnedAsciiCast traits are unchanged for now. New implementations: - `AsciiString::from_bytes` and `AsciiStr::from_bytes` for construction from types which can be represented as a byte slice. - `FromStr::from_str for AsciiString` and `AsciiStr::from_str` for construction from string slices. - Implements `fmt::{Debug, Display}` like `String` does - `AsciiString` derefs to `AsciiStr`, additionally `DerefMut` is implemented so `AsciiExt` is fully useable - Implements `Hash`, `Borrow` and `ToOwned` so it can easily be used in collections. - Implements `PartialEq`, `PartialOrd`, `Eq` and `Ord`. - `AsciiString` implements `Into<String>`, `Into<Vec<u8>>` and `AsRef<AsciiStr>`. - `AsciiStr` implements `AsRef<[u8]>` and `AsRef<str>`. [breaking-change]
Hum, |
oh, that is correct. I screwed something up in my head. Sorry for the frequent breakage, I update ascii again. |
The ascii crate now provides types for owned ascii strings and borrowed
ascii slices. Their implementation should allow them to be used like
String
andstr
.Changes:
AsciiString
replacesVec<Ascii>
AsciiStr
replaces[Ascii]
RemoveAscii::to_lowercase()
andAscii::to_uppercase()
IntoString
,IntoBytes
andAsciiStr
Migration (for details see new implementations):
AsciiString
andAsciiStr
like a collectionanymore, use the
from_bytes
orfrom_str
method instead.FromStr::from_str for AsciiString
andAsciiStr::from_str
forconstruction from string slices.
new generic conversion traits
Into
andAsRef
instead ofIntoString
,IntoBytes
orAsciiStr
.UseAsciiExt::to_ascii_lowercase()
andAsciiExt::to_ascii_uppercase()
instead of the removed methods which where implemented directly onAscii
.AsciiCast
andOwnedAsciiCast
traits are unchanged for now.New implementations:
AsciiString::from_bytes
andAsciiStr::from_bytes
for construction fromtypes which can be represented as a byte slice.
fmt::{Debug, Display}
likeString
doesAsciiString
derefs toAsciiStr
, additionallyDerefMut
is implemented soAsciiExt
is fully useableHash
,Borrow
andToOwned
so it can easily be used incollections.
PartialEq
,PartialOrd
,Eq
andOrd
for itself andstr
AsciiString
implementsInto<String>
,Into<Vec<u8>>
andAsRef<AsciiStr>
AsciiStr
implementsAsRef<[u8]>
andAsRef<str>
[breaking-change]
Fixes: #5
As of now documentation and more tests for the new functionality are missing.