mirror of
https://github.com/fafhrd91/actix-net
synced 2025-02-21 17:32:47 +01:00
Add PartialEq<T: AsRef<str>>, AsRef<[u8]> impls
This commit is contained in:
parent
7c5fa25b23
commit
3048073919
@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.3] - 2020-01-13
|
||||||
|
|
||||||
|
* Add `PartialEq<T: AsRef<str>>`, `AsRef<[u8]>` impls
|
||||||
|
|
||||||
## [0.1.2] - 2019-12-22
|
## [0.1.2] - 2019-12-22
|
||||||
|
|
||||||
* Fix `new()` method
|
* Fix `new()` method
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bytestring"
|
name = "bytestring"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "A UTF-8 encoded string with Bytes as a storage"
|
description = "A UTF-8 encoded string with Bytes as a storage"
|
||||||
keywords = ["actix"]
|
keywords = ["actix"]
|
||||||
|
@ -43,6 +43,18 @@ impl PartialEq<str> for ByteString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: AsRef<str>> PartialEq<T> for ByteString {
|
||||||
|
fn eq(&self, other: &T) -> bool {
|
||||||
|
&self[..] == other.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for ByteString {
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
self.0.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl hash::Hash for ByteString {
|
impl hash::Hash for ByteString {
|
||||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||||
(**self).hash(state);
|
(**self).hash(state);
|
||||||
@ -147,6 +159,14 @@ mod test {
|
|||||||
use std::collections::hash_map::DefaultHasher;
|
use std::collections::hash_map::DefaultHasher;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_partial_eq() {
|
||||||
|
let s: ByteString = ByteString::from_static("test");
|
||||||
|
assert_eq!(s, "test");
|
||||||
|
assert_eq!(s, *"test");
|
||||||
|
assert_eq!(s, "test".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new() {
|
fn test_new() {
|
||||||
let _: ByteString = ByteString::new();
|
let _: ByteString = ByteString::new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user