Skip to content

Commit 8afef1b

Browse files
authored
Merge pull request #140 from Fishrock123/from_bytes
src: rename remaining `from_ascii()` to `from_bytes()`
2 parents 4fef61b + 79e458e commit 8afef1b

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/headers/header_name.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ use crate::Error;
99
pub struct HeaderName(Cow<'static, str>);
1010

1111
impl HeaderName {
12-
/// Create a new `HeaderName`.
13-
pub fn from_ascii(mut bytes: Vec<u8>) -> Result<Self, Error> {
12+
/// Create a new `HeaderName` from a Vec of ASCII bytes.
13+
///
14+
/// # Error
15+
///
16+
/// This function will error if the bytes is not valid ASCII.
17+
pub fn from_bytes(mut bytes: Vec<u8>) -> Result<Self, Error> {
1418
crate::ensure!(bytes.is_ascii(), "Bytes should be valid ASCII");
1519
bytes.make_ascii_lowercase();
1620

@@ -33,7 +37,7 @@ impl HeaderName {
3337
/// ASCII. If this constraint is violated, it may cause memory
3438
/// unsafety issues with future users of the HeaderName, as the rest of the library assumes
3539
/// that Strings are valid ASCII.
36-
pub unsafe fn from_ascii_unchecked(mut bytes: Vec<u8>) -> Self {
40+
pub unsafe fn from_bytes_unchecked(mut bytes: Vec<u8>) -> Self {
3741
bytes.make_ascii_lowercase();
3842
let string = String::from_utf8_unchecked(bytes);
3943
HeaderName(Cow::Owned(string))

src/headers/header_value.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ pub struct HeaderValue {
1313
}
1414

1515
impl HeaderValue {
16-
/// Create a new `HeaderValue` from ASCII bytes.
16+
/// Create a new `HeaderValue` from a Vec of ASCII bytes.
1717
///
1818
/// # Error
1919
///
20-
/// This function will error if the string is not a valid ASCII.
21-
pub fn from_ascii(bytes: &[u8]) -> Result<Self, Error> {
20+
/// This function will error if the bytes is not valid ASCII.
21+
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
2222
crate::ensure!(bytes.is_ascii(), "Bytes should be valid ASCII");
2323

2424
// This is permitted because ASCII is valid UTF-8, and we just checked that.
@@ -35,7 +35,7 @@ impl HeaderValue {
3535
/// ASCII. If this constraint is violated, it may cause memory
3636
/// unsafety issues with future users of the HeaderValue, as the rest of the library assumes
3737
/// that Strings are valid ASCII.
38-
pub unsafe fn from_ascii_unchecked(bytes: Vec<u8>) -> Self {
38+
pub unsafe fn from_bytes_unchecked(bytes: Vec<u8>) -> Self {
3939
let string = String::from_utf8_unchecked(bytes);
4040
Self { inner: string }
4141
}

src/hyperium_http.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ impl From<Version> for http::Version {
5757
fn hyperium_headers_to_headers(hyperium_headers: http::HeaderMap, headers: &mut Headers) {
5858
for (name, value) in hyperium_headers {
5959
let value = value.as_bytes().to_owned();
60-
let value = unsafe { HeaderValue::from_ascii_unchecked(value) };
60+
let value = unsafe { HeaderValue::from_bytes_unchecked(value) };
6161
if let Some(name) = name {
6262
let name = name.as_str().as_bytes().to_owned();
63-
let name = unsafe { HeaderName::from_ascii_unchecked(name) };
63+
let name = unsafe { HeaderName::from_bytes_unchecked(name) };
6464
headers.insert(name, value).unwrap();
6565
}
6666
}

0 commit comments

Comments
 (0)