Skip to content

Commit

Permalink
Mark some functions as constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed May 19, 2021
1 parent 94da933 commit be251cf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
8 changes: 2 additions & 6 deletions http/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ where
B: Stream<Item = io::Result<&'b [u8]>>,
{
/// Use a [`Stream`] as HTTP body.
// TODO: make this a `const` fn once trait bounds (`FileSend`) on `const`
// functions are stable.
pub fn new(length: usize, stream: B) -> StreamingBody<'b, B> {
pub const fn new(length: usize, stream: B) -> StreamingBody<'b, B> {
StreamingBody {
length,
body: stream,
Expand Down Expand Up @@ -402,9 +400,7 @@ where
///
/// This uses the bytes `offset..end` from `file` as HTTP body and sends
/// them using `sendfile(2)` (using [`TcpStream::send_file`]).
// TODO: make this a `const` fn once trait bounds (`FileSend`) on `const`
// functions are stable.
pub fn new(file: &'f F, offset: usize, end: NonZeroUsize) -> FileBody<'f, F> {
pub const fn new(file: &'f F, offset: usize, end: NonZeroUsize) -> FileBody<'f, F> {
debug_assert!(end.get() >= offset);
FileBody { file, offset, end }
}
Expand Down
4 changes: 2 additions & 2 deletions http/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Headers {
/// Returns an iterator over all headers.
///
/// The order is unspecified.
pub fn iter<'a>(&'a self) -> Iter<'a> {
pub const fn iter<'a>(&'a self) -> Iter<'a> {
Iter {
headers: self,
pos: 0,
Expand Down Expand Up @@ -863,7 +863,7 @@ impl HeaderName<'static> {
/// This is only header to test [`HeaderName::from_str`], not part of the
/// stable API.
#[doc(hidden)]
pub fn is_heap_allocated(&self) -> bool {
pub const fn is_heap_allocated(&self) -> bool {
matches!(self.inner, Cow::Owned(_))
}
}
Expand Down
4 changes: 2 additions & 2 deletions http/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<B> Request<B> {
}

/// Returns mutable access to the headers.
pub fn headers_mut(&mut self) -> &mut Headers {
pub const fn headers_mut(&mut self) -> &mut Headers {
&mut self.headers
}

Expand All @@ -69,7 +69,7 @@ impl<B> Request<B> {
}

/// Mutable access to the request body.
pub fn body_mut(&mut self) -> &mut B {
pub const fn body_mut(&mut self) -> &mut B {
&mut self.body
}
}
Expand Down
4 changes: 2 additions & 2 deletions http/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<B> Response<B> {
}

/// Returns mutable access to the headers.
pub fn headers_mut(&mut self) -> &mut Headers {
pub const fn headers_mut(&mut self) -> &mut Headers {
&mut self.headers
}

Expand All @@ -52,7 +52,7 @@ impl<B> Response<B> {
}

/// Returns a mutable reference to the body.
pub fn body_mut(&mut self) -> &mut B {
pub const fn body_mut(&mut self) -> &mut B {
&mut self.body
}

Expand Down

0 comments on commit be251cf

Please sign in to comment.