mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-31 12:42:09 +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
|
# 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
|
* Fix hash impl
|
||||||
|
|
||||||
[0.1.0] - 2019-12-07
|
## [0.1.0] - 2019-12-07
|
||||||
|
|
||||||
* Initial release
|
* Initial release
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bytestring"
|
name = "bytestring"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
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"]
|
||||||
@ -9,11 +9,10 @@ repository = "https://github.com/actix/actix-net.git"
|
|||||||
documentation = "https://docs.rs/bytestring/"
|
documentation = "https://docs.rs/bytestring/"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
workspace = ".."
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "bytestring"
|
name = "bytestring"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[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.
|
/// 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)]
|
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Default)]
|
||||||
pub struct ByteString(Bytes);
|
pub struct ByteString(Bytes);
|
||||||
|
|
||||||
impl ByteString {
|
impl ByteString {
|
||||||
/// Creates a new `ByteString`.
|
/// Creates a new `ByteString`.
|
||||||
pub fn new() -> String {
|
pub fn new() -> Self {
|
||||||
String::default()
|
ByteString(Bytes::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to the underlying bytes object.
|
/// Get a reference to the underlying bytes object.
|
||||||
@ -27,12 +27,12 @@ impl ByteString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `ByteString` from a static str.
|
/// Creates a new `ByteString` from a static str.
|
||||||
pub fn from_static(src: &'static str) -> ByteString {
|
pub const fn from_static(src: &'static str) -> ByteString {
|
||||||
Self(Bytes::from_static(src.as_ref()))
|
Self(Bytes::from_static(src.as_bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `ByteString` from a 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)
|
Self(src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,6 +147,11 @@ 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_new() {
|
||||||
|
let _: ByteString = ByteString::new();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hash() {
|
fn test_hash() {
|
||||||
let mut hasher1 = DefaultHasher::default();
|
let mut hasher1 = DefaultHasher::default();
|
||||||
@ -171,6 +176,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_static_str() {
|
fn test_from_static_str() {
|
||||||
|
const _S: ByteString = ByteString::from_static("hello");
|
||||||
let _ = ByteString::from_static("str");
|
let _ = ByteString::from_static("str");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user