refactor
This commit is contained in:
parent
d750f87331
commit
4d590f328f
8 changed files with 39 additions and 33 deletions
|
|
@ -1,20 +1,22 @@
|
|||
use bytes::{Buf, Bytes};
|
||||
|
||||
pub trait BytesName {
|
||||
type Output;
|
||||
fn to_byte_name(self) -> Self::Output;
|
||||
fn to_ascii_lowercase_byte_name(self) -> Self::Output;
|
||||
type Output: Buf;
|
||||
fn to_bytes(self) -> Self::Output;
|
||||
fn to_ascii_lowercase_bytes(self) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<T: Into<String>> BytesName for T {
|
||||
type Output = Vec<u8>;
|
||||
type Output = Bytes;
|
||||
|
||||
fn to_byte_name(self) -> Self::Output {
|
||||
self.into().bytes().collect::<Vec<u8>>()
|
||||
// Bytes::from(b)
|
||||
fn to_bytes(self) -> Self::Output {
|
||||
let b = self.into().bytes().collect::<Vec<u8>>();
|
||||
Bytes::from(b)
|
||||
}
|
||||
|
||||
fn to_ascii_lowercase_byte_name(self) -> Self::Output {
|
||||
self.into().bytes().collect::<Vec<u8>>().to_ascii_lowercase()
|
||||
// Bytes::from(b)
|
||||
fn to_ascii_lowercase_bytes(self) -> Self::Output {
|
||||
let b = self.into().bytes().collect::<Vec<u8>>().to_ascii_lowercase();
|
||||
Bytes::from(b)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -24,10 +26,10 @@ mod tests {
|
|||
#[test]
|
||||
fn bytes_name_str_works() {
|
||||
let s = "OK_string";
|
||||
let bn = s.to_byte_name();
|
||||
let bn_lc = s.to_ascii_lowercase_byte_name();
|
||||
let bn = s.to_bytes();
|
||||
let bn_lc = s.to_ascii_lowercase_bytes();
|
||||
|
||||
assert_eq!(Vec::from(s.as_bytes()), bn);
|
||||
assert_eq!(Vec::from("ok_string"), bn_lc);
|
||||
assert_eq!(Bytes::from(s.as_bytes()), bn);
|
||||
assert_eq!(Bytes::from("ok_string"), bn_lc);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue