mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-18 20:01:48 +01:00
fix new() method and make from_static and from_bytes_unchecked methods const
This commit is contained in:
parent
5fe759cc02
commit
a80e1f8370
@ -1,9 +1,15 @@
|
||||
# Changes
|
||||
|
||||
[0.1.1] - 2019-12-07
|
||||
## [0.1.2] - 2019-12-22
|
||||
|
||||
* Fix `new()` method
|
||||
|
||||
* Make `ByteString::from_static()` and `ByteString::from_bytes_unchecked()` methods const.
|
||||
|
||||
## [0.1.1] - 2019-12-07
|
||||
|
||||
* Fix hash impl
|
||||
|
||||
[0.1.0] - 2019-12-07
|
||||
## [0.1.0] - 2019-12-07
|
||||
|
||||
* Initial release
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "bytestring"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "A UTF-8 encoded string with Bytes as a storage"
|
||||
keywords = ["actix"]
|
||||
@ -9,11 +9,10 @@ repository = "https://github.com/actix/actix-net.git"
|
||||
documentation = "https://docs.rs/bytestring/"
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2018"
|
||||
workspace = ".."
|
||||
|
||||
[lib]
|
||||
name = "bytestring"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
bytes = "0.5.2"
|
||||
bytes = "0.5.3"
|
||||
|
@ -6,14 +6,14 @@ use bytes::Bytes;
|
||||
|
||||
/// A utf-8 encoded string with [`Bytes`] as a storage.
|
||||
///
|
||||
/// [`Bytes`]: https://docs.rs/bytes/0.5.2/bytes/struct.Bytes.html
|
||||
/// [`Bytes`]: https://docs.rs/bytes/0.5.3/bytes/struct.Bytes.html
|
||||
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Default)]
|
||||
pub struct ByteString(Bytes);
|
||||
|
||||
impl ByteString {
|
||||
/// Creates a new `ByteString`.
|
||||
pub fn new() -> String {
|
||||
String::default()
|
||||
pub fn new() -> Self {
|
||||
ByteString(Bytes::new())
|
||||
}
|
||||
|
||||
/// Get a reference to the underlying bytes object.
|
||||
@ -27,12 +27,12 @@ impl ByteString {
|
||||
}
|
||||
|
||||
/// Creates a new `ByteString` from a static str.
|
||||
pub fn from_static(src: &'static str) -> ByteString {
|
||||
Self(Bytes::from_static(src.as_ref()))
|
||||
pub const fn from_static(src: &'static str) -> ByteString {
|
||||
Self(Bytes::from_static(src.as_bytes()))
|
||||
}
|
||||
|
||||
/// Creates a new `ByteString` from a Bytes.
|
||||
pub unsafe fn from_bytes_unchecked(src: Bytes) -> ByteString {
|
||||
pub const unsafe fn from_bytes_unchecked(src: Bytes) -> ByteString {
|
||||
Self(src)
|
||||
}
|
||||
}
|
||||
@ -147,6 +147,11 @@ mod test {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
#[test]
|
||||
fn test_new() {
|
||||
let _: ByteString = ByteString::new();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hash() {
|
||||
let mut hasher1 = DefaultHasher::default();
|
||||
@ -171,6 +176,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_from_static_str() {
|
||||
const _S: ByteString = ByteString::from_static("hello");
|
||||
let _ = ByteString::from_static("str");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user