Revert adding #[must_use]

This commit is contained in:
Igor Aleksanov 2021-06-25 15:40:53 +03:00
parent 596012086c
commit 759f85e668
45 changed files with 0 additions and 215 deletions

View File

@ -10,7 +10,6 @@
### Changed
* Change compression algorithm features flags. [#2250]
* Deprecate `App::data` and `App::data_factory`. [#2271]
* Add `#[must_use]` attribute for many public functions/methods. [#2281]
### Fixed
@ -21,7 +20,6 @@
[#2271]: https://github.com/actix/actix-web/pull/2271
[#2262]: https://github.com/actix/actix-web/pull/2262
[#2263]: https://github.com/actix/actix-web/pull/2263
[#2281]: https://github.com/actix/actix-web/pull/2281
[#2288]: https://github.com/actix/actix-web/pull/2288

View File

@ -3,14 +3,12 @@
## Unreleased - 2021-xx-xx
### Changed
* Change compression algorithm features flags. [#2250]
* Add `#[must_use]` attribute for many public functions/methods. [#2281]
### Removed
* `downcast` and `downcast_get_type_id` macros. [#2291]
[#2291]: https://github.com/actix/actix-web/pull/2291
[#2250]: https://github.com/actix/actix-web/pull/2250
[#2281]: https://github.com/actix/actix-web/pull/2281
## 3.0.0-beta.7 - 2021-06-17

View File

@ -32,7 +32,6 @@ pub enum AnyBody {
impl AnyBody {
/// Create body from slice (copy)
#[must_use]
pub fn from_slice(s: &[u8]) -> Self {
Self::Bytes(Bytes::copy_from_slice(s))
}

View File

@ -36,7 +36,6 @@ where
<S::Service as Service<Request>>::Future: 'static,
{
/// Create instance of `ServiceConfigBuilder`
#[must_use]
pub fn new() -> Self {
HttpServiceBuilder {
keep_alive: KeepAlive::Timeout(5),

View File

@ -64,7 +64,6 @@ pub struct Connector<T> {
impl Connector<()> {
#[allow(clippy::new_ret_no_self, clippy::let_unit_value)]
#[must_use]
pub fn new() -> Connector<
impl Service<
TcpConnect<Uri>,

View File

@ -68,7 +68,6 @@ impl Default for ServiceConfig {
impl ServiceConfig {
/// Create instance of `ServiceConfig`
#[must_use]
pub fn new(
keep_alive: KeepAlive,
client_timeout: u64,
@ -100,35 +99,30 @@ impl ServiceConfig {
/// Returns true if connection is secure (HTTPS)
#[inline]
#[must_use]
pub fn secure(&self) -> bool {
self.0.secure
}
/// Returns the local address that this server is bound to.
#[inline]
#[must_use]
pub fn local_addr(&self) -> Option<net::SocketAddr> {
self.0.local_addr
}
/// Keep alive duration if configured.
#[inline]
#[must_use]
pub fn keep_alive(&self) -> Option<Duration> {
self.0.keep_alive
}
/// Return state of connection keep-alive functionality
#[inline]
#[must_use]
pub fn keep_alive_enabled(&self) -> bool {
self.0.ka_enabled
}
/// Client timeout for first request.
#[inline]
#[must_use]
pub fn client_timer(&self) -> Option<Sleep> {
let delay_time = self.0.client_timeout;
if delay_time != 0 {
@ -139,7 +133,6 @@ impl ServiceConfig {
}
/// Client timeout for first request.
#[must_use]
pub fn client_timer_expire(&self) -> Option<Instant> {
let delay = self.0.client_timeout;
if delay != 0 {
@ -150,7 +143,6 @@ impl ServiceConfig {
}
/// Client disconnect timer
#[must_use]
pub fn client_disconnect_timer(&self) -> Option<Instant> {
let delay = self.0.client_disconnect;
if delay != 0 {
@ -162,13 +154,11 @@ impl ServiceConfig {
/// Return keep-alive timer delay is configured.
#[inline]
#[must_use]
pub fn keep_alive_timer(&self) -> Option<Sleep> {
self.keep_alive().map(|ka| sleep_until(self.now() + ka))
}
/// Keep-alive expire time
#[must_use]
pub fn keep_alive_expire(&self) -> Option<Instant> {
self.keep_alive().map(|ka| self.now() + ka)
}

View File

@ -18,7 +18,6 @@ pub struct Extensions {
impl Extensions {
/// Creates an empty `Extensions`.
#[inline]
#[must_use]
pub fn new() -> Extensions {
Extensions {
map: AHashMap::default(),
@ -53,7 +52,6 @@ impl Extensions {
/// assert_eq!(map.insert(1u32), None);
/// assert!(map.contains::<u32>());
/// ```
#[must_use]
pub fn contains<T: 'static>(&self) -> bool {
self.map.contains_key(&TypeId::of::<T>())
}
@ -66,7 +64,6 @@ impl Extensions {
/// map.insert(1u32);
/// assert_eq!(map.get::<u32>(), Some(&1u32));
/// ```
#[must_use]
pub fn get<T: 'static>(&self) -> Option<&T> {
self.map
.get(&TypeId::of::<T>())

View File

@ -53,7 +53,6 @@ impl ClientCodec {
/// Create HTTP/1 codec.
///
/// `keepalive_enabled` how response `connection` header get generated.
#[must_use]
pub fn new(config: ServiceConfig) -> Self {
let flags = if config.keep_alive_enabled() {
Flags::KEEPALIVE_ENABLED
@ -75,19 +74,16 @@ impl ClientCodec {
}
/// Check if request is upgrade
#[must_use]
pub fn upgrade(&self) -> bool {
self.inner.ctype == ConnectionType::Upgrade
}
/// Check if last response is keep-alive
#[must_use]
pub fn keepalive(&self) -> bool {
self.inner.ctype == ConnectionType::KeepAlive
}
/// Check last request's message type
#[must_use]
pub fn message_type(&self) -> MessageType {
if self.inner.flags.contains(Flags::STREAM) {
MessageType::Stream
@ -99,7 +95,6 @@ impl ClientCodec {
}
/// Convert message codec to a payload codec
#[must_use]
pub fn into_payload_codec(self) -> ClientPayloadCodec {
ClientPayloadCodec { inner: self.inner }
}
@ -107,13 +102,11 @@ impl ClientCodec {
impl ClientPayloadCodec {
/// Check if last response is keep-alive
#[must_use]
pub fn keepalive(&self) -> bool {
self.inner.ctype == ConnectionType::KeepAlive
}
/// Transform payload codec to a message codec
#[must_use]
pub fn into_message_codec(self) -> ClientCodec {
ClientCodec { inner: self.inner }
}

View File

@ -52,7 +52,6 @@ impl Codec {
/// Create HTTP/1 codec.
///
/// `keepalive_enabled` how response `connection` header get generated.
#[must_use]
pub fn new(config: ServiceConfig) -> Self {
let flags = if config.keep_alive_enabled() {
Flags::KEEPALIVE_ENABLED
@ -73,28 +72,24 @@ impl Codec {
/// Check if request is upgrade.
#[inline]
#[must_use]
pub fn upgrade(&self) -> bool {
self.ctype == ConnectionType::Upgrade
}
/// Check if last response is keep-alive.
#[inline]
#[must_use]
pub fn keepalive(&self) -> bool {
self.ctype == ConnectionType::KeepAlive
}
/// Check if keep-alive enabled on server level.
#[inline]
#[must_use]
pub fn keepalive_enabled(&self) -> bool {
self.flags.contains(Flags::KEEPALIVE_ENABLED)
}
/// Check last request's message type.
#[inline]
#[must_use]
pub fn message_type(&self) -> MessageType {
if self.flags.contains(Flags::STREAM) {
MessageType::Stream
@ -106,7 +101,6 @@ impl Codec {
}
#[inline]
#[must_use]
pub fn config(&self) -> &ServiceConfig {
&self.config
}

View File

@ -41,7 +41,6 @@ impl Payload {
/// * `PayloadSender` - *Sender* side of the stream
///
/// * `Payload` - *Receiver* side of the stream
#[must_use]
pub fn create(eof: bool) -> (PayloadSender, Payload) {
let shared = Rc::new(RefCell::new(Inner::new(eof)));
@ -55,7 +54,6 @@ impl Payload {
/// Create empty payload
#[doc(hidden)]
#[must_use]
pub fn empty() -> Payload {
Payload {
inner: Rc::new(RefCell::new(Inner::new(true))),

View File

@ -81,7 +81,6 @@ impl HeaderMap {
/// assert!(map.is_empty());
/// assert_eq!(0, map.capacity());
/// ```
#[must_use]
pub fn new() -> Self {
HeaderMap::default()
}
@ -99,7 +98,6 @@ impl HeaderMap {
/// assert!(map.is_empty());
/// assert!(map.capacity() >= 16);
/// ```
#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
HeaderMap {
inner: AHashMap::with_capacity(capacity),
@ -152,7 +150,6 @@ impl HeaderMap {
/// map.append(header::SET_COOKIE, HeaderValue::from_static("two=2"));
/// assert_eq!(map.len(), 3);
/// ```
#[must_use]
pub fn len(&self) -> usize {
self.inner
.iter()
@ -176,7 +173,6 @@ impl HeaderMap {
/// map.append(header::SET_COOKIE, HeaderValue::from_static("two=2"));
/// assert_eq!(map.len_keys(), 2);
/// ```
#[must_use]
pub fn len_keys(&self) -> usize {
self.inner.len()
}
@ -192,7 +188,6 @@ impl HeaderMap {
/// map.insert(header::ACCEPT, HeaderValue::from_static("text/plain"));
/// assert!(!map.is_empty());
/// ```
#[must_use]
pub fn is_empty(&self) -> bool {
self.inner.len() == 0
}
@ -439,7 +434,6 @@ impl HeaderMap {
/// assert!(map.is_empty());
/// assert!(map.capacity() >= 16);
/// ```
#[must_use]
pub fn capacity(&self) -> usize {
self.inner.capacity()
}
@ -495,7 +489,6 @@ impl HeaderMap {
/// assert!(pairs.contains(&(&header::SET_COOKIE, &HeaderValue::from_static("one=1"))));
/// assert!(pairs.contains(&(&header::SET_COOKIE, &HeaderValue::from_static("two=2"))));
/// ```
#[must_use]
pub fn iter(&self) -> Iter<'_> {
Iter::new(self.inner.iter())
}
@ -522,7 +515,6 @@ impl HeaderMap {
/// assert!(keys.contains(&header::HOST));
/// assert!(keys.contains(&header::SET_COOKIE));
/// ```
#[must_use]
pub fn keys(&self) -> Keys<'_> {
Keys(self.inner.keys())
}

View File

@ -33,14 +33,12 @@ pub enum ContentEncoding {
impl ContentEncoding {
/// Is the content compressed?
#[inline]
#[must_use]
pub fn is_compression(self) -> bool {
matches!(self, ContentEncoding::Identity | ContentEncoding::Auto)
}
/// Convert content encoding to string
#[inline]
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
ContentEncoding::Br => "br",
@ -53,7 +51,6 @@ impl ContentEncoding {
/// Default Q-factor (quality) value.
#[inline]
#[must_use]
pub fn quality(self) -> f64 {
match self {
ContentEncoding::Br => 1.1,

View File

@ -234,7 +234,6 @@ pub struct ResponseHead {
impl ResponseHead {
/// Create new instance of `ResponseHead` type
#[inline]
#[must_use]
pub fn new(status: StatusCode) -> ResponseHead {
ResponseHead {
status,
@ -355,7 +354,6 @@ pub struct Message<T: Head> {
impl<T: Head> Message<T> {
/// Get new message from the pool of objects
#[must_use]
pub fn new() -> Self {
T::with_pool(MessagePool::get_message)
}

View File

@ -57,7 +57,6 @@ impl From<Message<RequestHead>> for Request<PayloadStream> {
impl Request<PayloadStream> {
/// Create new Request instance
#[must_use]
pub fn new() -> Request<PayloadStream> {
Request {
head: Message::new(),

View File

@ -25,7 +25,6 @@ pub struct Response<B> {
impl Response<AnyBody> {
/// Constructs a new response with default body.
#[inline]
#[must_use]
pub fn new(status: StatusCode) -> Self {
Response {
head: BoxedResponseHead::new(status),
@ -35,7 +34,6 @@ impl Response<AnyBody> {
/// Constructs a new response builder.
#[inline]
#[must_use]
pub fn build(status: StatusCode) -> ResponseBuilder {
ResponseBuilder::new(status)
}
@ -45,28 +43,24 @@ impl Response<AnyBody> {
/// Constructs a new response with status 200 OK.
#[inline]
#[must_use]
pub fn ok() -> Self {
Response::new(StatusCode::OK)
}
/// Constructs a new response with status 400 Bad Request.
#[inline]
#[must_use]
pub fn bad_request() -> Self {
Response::new(StatusCode::BAD_REQUEST)
}
/// Constructs a new response with status 404 Not Found.
#[inline]
#[must_use]
pub fn not_found() -> Self {
Response::new(StatusCode::NOT_FOUND)
}
/// Constructs a new response with status 500 Internal Server Error.
#[inline]
#[must_use]
pub fn internal_server_error() -> Self {
Response::new(StatusCode::INTERNAL_SERVER_ERROR)
}

View File

@ -62,7 +62,6 @@ impl ResponseBuilder {
/// assert_eq!(res.status(), StatusCode::OK);
/// ```
#[inline]
#[must_use]
pub fn new(status: StatusCode) -> Self {
ResponseBuilder {
head: Some(BoxedResponseHead::new(status)),
@ -221,7 +220,6 @@ impl ResponseBuilder {
/// Responses extensions
#[inline]
#[must_use]
pub fn extensions(&self) -> Ref<'_, Extensions> {
let head = self.head.as_ref().expect("cannot reuse response builder");
head.extensions.borrow()

View File

@ -47,7 +47,6 @@ where
B: MessageBody + 'static,
{
/// Create builder for `HttpService` instance.
#[must_use]
pub fn build() -> HttpServiceBuilder<T, S> {
HttpServiceBuilder::new()
}

View File

@ -80,7 +80,6 @@ bitflags! {
impl Codec {
/// Create new WebSocket frames decoder.
#[must_use]
pub const fn new() -> Codec {
Codec {
max_size: 65_536,
@ -91,7 +90,6 @@ impl Codec {
/// Set max frame size.
///
/// By default max size is set to 64kB.
#[must_use]
pub fn max_size(mut self, size: usize) -> Self {
self.max_size = size;
self
@ -100,7 +98,6 @@ impl Codec {
/// Set decoder to client mode.
///
/// By default decoder works in server mode.
#[must_use]
pub fn client_mode(mut self) -> Self {
self.flags.remove(Flags::SERVER);
self

View File

@ -139,7 +139,6 @@ impl Parser {
}
/// Parse the payload of a close frame.
#[must_use]
pub fn parse_close_payload(payload: &[u8]) -> Option<CloseReason> {
if payload.len() >= 2 {
let raw_code = u16::from_be_bytes(TryFrom::try_from(&payload[..2]).unwrap());

View File

@ -226,7 +226,6 @@ static WS_GUID: &[u8] = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
/// Hashes the `Sec-WebSocket-Key` header according to the WebSocket spec.
///
/// Result is a Base64 encoded byte array. `base64(sha1(input))` is always 28 bytes.
#[must_use]
pub fn hash_key(key: &[u8]) -> [u8; 28] {
let hash = {
use sha1::Digest as _;

View File

@ -42,7 +42,6 @@ pub struct App<T, B> {
impl App<AppEntry, Body> {
/// Create application builder. Application can be configured with a builder-like pattern.
#[allow(clippy::new_without_default)]
#[must_use]
pub fn new() -> Self {
let factory_ref = Rc::new(RefCell::new(None));

View File

@ -44,7 +44,6 @@ impl AppService {
}
/// Check if root is being configured
#[must_use]
pub fn is_root(&self) -> bool {
self.root
}
@ -75,13 +74,11 @@ impl AppService {
}
/// Returns reference to configuration.
#[must_use]
pub fn config(&self) -> &AppConfig {
&self.config
}
/// Returns default handler factory.
#[must_use]
pub fn default_service(&self) -> Rc<HttpNewService> {
self.default.clone()
}
@ -134,19 +131,16 @@ impl AppConfig {
/// documentation for more information.
///
/// By default host name is set to a "localhost" value.
#[must_use]
pub fn host(&self) -> &str {
&self.host
}
/// Returns true if connection is secure(https)
#[must_use]
pub fn secure(&self) -> bool {
self.secure
}
/// Returns the socket address of the local half of this TCP connection
#[must_use]
pub fn local_addr(&self) -> SocketAddr {
self.addr
}

View File

@ -77,13 +77,11 @@ impl<T> Data<T> {
}
/// Get reference to inner app data.
#[must_use]
pub fn get_ref(&self) -> &T {
self.0.as_ref()
}
/// Convert to the internal Arc<T>
#[must_use]
pub fn into_inner(self) -> Arc<T> {
self.0
}

View File

@ -20,19 +20,16 @@ pub struct Error {
impl Error {
/// Returns the reference to the underlying `ResponseError`.
#[must_use]
pub fn as_response_error(&self) -> &dyn ResponseError {
self.cause.as_ref()
}
/// Similar to `as_response_error` but downcasts.
#[must_use]
pub fn as_error<T: ResponseError + 'static>(&self) -> Option<&T> {
<dyn ResponseError>::downcast_ref(self.cause.as_ref())
}
/// Shortcut for creating an `HttpResponse`.
#[must_use]
pub fn error_response(&self) -> HttpResponse {
self.cause.error_response()
}

View File

@ -195,68 +195,57 @@ impl Guard for MethodGuard {
}
/// Guard to match *GET* HTTP method.
#[must_use]
pub fn Get() -> MethodGuard {
MethodGuard(http::Method::GET)
}
/// Predicate to match *POST* HTTP method.
#[must_use]
pub fn Post() -> MethodGuard {
MethodGuard(http::Method::POST)
}
/// Predicate to match *PUT* HTTP method.
#[must_use]
pub fn Put() -> MethodGuard {
MethodGuard(http::Method::PUT)
}
/// Predicate to match *DELETE* HTTP method.
#[must_use]
pub fn Delete() -> MethodGuard {
MethodGuard(http::Method::DELETE)
}
/// Predicate to match *HEAD* HTTP method.
#[must_use]
pub fn Head() -> MethodGuard {
MethodGuard(http::Method::HEAD)
}
/// Predicate to match *OPTIONS* HTTP method.
#[must_use]
pub fn Options() -> MethodGuard {
MethodGuard(http::Method::OPTIONS)
}
/// Predicate to match *CONNECT* HTTP method.
#[must_use]
pub fn Connect() -> MethodGuard {
MethodGuard(http::Method::CONNECT)
}
/// Predicate to match *PATCH* HTTP method.
#[must_use]
pub fn Patch() -> MethodGuard {
MethodGuard(http::Method::PATCH)
}
/// Predicate to match *TRACE* HTTP method.
#[must_use]
pub fn Trace() -> MethodGuard {
MethodGuard(http::Method::TRACE)
}
/// Predicate to match specified HTTP method.
#[must_use]
pub fn Method(method: http::Method) -> MethodGuard {
MethodGuard(method)
}
/// Return predicate that matches if request contains specified header and
/// value.
#[must_use]
pub fn Header(name: &'static str, value: &'static str) -> HeaderGuard {
HeaderGuard(
header::HeaderName::try_from(name).unwrap(),

View File

@ -126,31 +126,26 @@ crate::http::header::common_header! {
impl Accept {
/// Construct `Accept: */*`.
#[must_use]
pub fn star() -> Accept {
Accept(vec![qitem(mime::STAR_STAR)])
}
/// Construct `Accept: application/json`.
#[must_use]
pub fn json() -> Accept {
Accept(vec![qitem(mime::APPLICATION_JSON)])
}
/// Construct `Accept: text/*`.
#[must_use]
pub fn text() -> Accept {
Accept(vec![qitem(mime::TEXT_STAR)])
}
/// Construct `Accept: image/*`.
#[must_use]
pub fn image() -> Accept {
Accept(vec![qitem(mime::IMAGE_STAR)])
}
/// Construct `Accept: text/html`.
#[must_use]
pub fn html() -> Accept {
Accept(vec![qitem(mime::TEXT_HTML)])
}
@ -159,7 +154,6 @@ impl Accept {
/// [q-factor weighting] and specificity.
///
/// [q-factor weighting]: https://tools.ietf.org/html/rfc7231#section-5.3.2
#[must_use]
pub fn mime_precedence(&self) -> Vec<Mime> {
let mut types = self.0.clone();
@ -210,7 +204,6 @@ impl Accept {
/// Returns `None` if contained list is empty.
///
/// [q-factor weighting]: https://tools.ietf.org/html/rfc7231#section-5.3.2
#[must_use]
pub fn mime_preference(&self) -> Option<Mime> {
let types = self.mime_precedence();
types.first().cloned()

View File

@ -101,28 +101,24 @@ pub enum DispositionParam {
impl DispositionParam {
/// Returns `true` if the parameter is [`Name`](DispositionParam::Name).
#[inline]
#[must_use]
pub fn is_name(&self) -> bool {
self.as_name().is_some()
}
/// Returns `true` if the parameter is [`Filename`](DispositionParam::Filename).
#[inline]
#[must_use]
pub fn is_filename(&self) -> bool {
self.as_filename().is_some()
}
/// Returns `true` if the parameter is [`FilenameExt`](DispositionParam::FilenameExt).
#[inline]
#[must_use]
pub fn is_filename_ext(&self) -> bool {
self.as_filename_ext().is_some()
}
/// Returns `true` if the parameter is [`Unknown`](DispositionParam::Unknown) and the `name`
#[inline]
#[must_use]
/// matches.
pub fn is_unknown<T: AsRef<str>>(&self, name: T) -> bool {
self.as_unknown(name).is_some()
@ -131,14 +127,12 @@ impl DispositionParam {
/// Returns `true` if the parameter is [`UnknownExt`](DispositionParam::UnknownExt) and the
/// `name` matches.
#[inline]
#[must_use]
pub fn is_unknown_ext<T: AsRef<str>>(&self, name: T) -> bool {
self.as_unknown_ext(name).is_some()
}
/// Returns the name if applicable.
#[inline]
#[must_use]
pub fn as_name(&self) -> Option<&str> {
match self {
DispositionParam::Name(ref name) => Some(name.as_str()),
@ -148,7 +142,6 @@ impl DispositionParam {
/// Returns the filename if applicable.
#[inline]
#[must_use]
pub fn as_filename(&self) -> Option<&str> {
match self {
DispositionParam::Filename(ref filename) => Some(filename.as_str()),
@ -158,7 +151,6 @@ impl DispositionParam {
/// Returns the filename* if applicable.
#[inline]
#[must_use]
pub fn as_filename_ext(&self) -> Option<&ExtendedValue> {
match self {
DispositionParam::FilenameExt(ref value) => Some(value),
@ -169,7 +161,6 @@ impl DispositionParam {
/// Returns the value of the unrecognized regular parameter if it is
/// [`Unknown`](DispositionParam::Unknown) and the `name` matches.
#[inline]
#[must_use]
pub fn as_unknown<T: AsRef<str>>(&self, name: T) -> Option<&str> {
match self {
DispositionParam::Unknown(ref ext_name, ref value)
@ -184,7 +175,6 @@ impl DispositionParam {
/// Returns the value of the unrecognized extended parameter if it is
/// [`Unknown`](DispositionParam::Unknown) and the `name` matches.
#[inline]
#[must_use]
pub fn as_unknown_ext<T: AsRef<str>>(&self, name: T) -> Option<&ExtendedValue> {
match self {
DispositionParam::UnknownExt(ref ext_name, ref value)
@ -396,25 +386,21 @@ impl ContentDisposition {
}
/// Returns `true` if it is [`Inline`](DispositionType::Inline).
#[must_use]
pub fn is_inline(&self) -> bool {
matches!(self.disposition, DispositionType::Inline)
}
/// Returns `true` if it is [`Attachment`](DispositionType::Attachment).
#[must_use]
pub fn is_attachment(&self) -> bool {
matches!(self.disposition, DispositionType::Attachment)
}
/// Returns `true` if it is [`FormData`](DispositionType::FormData).
#[must_use]
pub fn is_form_data(&self) -> bool {
matches!(self.disposition, DispositionType::FormData)
}
/// Returns `true` if it is [`Ext`](DispositionType::Ext) and the `disp_type` matches.
#[must_use]
pub fn is_ext(&self, disp_type: impl AsRef<str>) -> bool {
matches!(
self.disposition,
@ -423,13 +409,11 @@ impl ContentDisposition {
}
/// Return the value of *name* if exists.
#[must_use]
pub fn get_name(&self) -> Option<&str> {
self.parameters.iter().find_map(DispositionParam::as_name)
}
/// Return the value of *filename* if exists.
#[must_use]
pub fn get_filename(&self) -> Option<&str> {
self.parameters
.iter()
@ -437,7 +421,6 @@ impl ContentDisposition {
}
/// Return the value of *filename\** if exists.
#[must_use]
pub fn get_filename_ext(&self) -> Option<&ExtendedValue> {
self.parameters
.iter()
@ -445,14 +428,12 @@ impl ContentDisposition {
}
/// Return the value of the parameter which the `name` matches.
#[must_use]
pub fn get_unknown(&self, name: impl AsRef<str>) -> Option<&str> {
let name = name.as_ref();
self.parameters.iter().find_map(|p| p.as_unknown(name))
}
/// Return the value of the extended parameter which the `name` matches.
#[must_use]
pub fn get_unknown_ext(&self, name: impl AsRef<str>) -> Option<&ExtendedValue> {
let name = name.as_ref();
self.parameters.iter().find_map(|p| p.as_unknown_ext(name))

View File

@ -63,7 +63,6 @@ impl ContentType {
/// A constructor to easily create a `Content-Type: application/json`
/// header.
#[inline]
#[must_use]
pub fn json() -> ContentType {
ContentType(mime::APPLICATION_JSON)
}
@ -71,21 +70,18 @@ impl ContentType {
/// A constructor to easily create a `Content-Type: text/plain;
/// charset=utf-8` header.
#[inline]
#[must_use]
pub fn plaintext() -> ContentType {
ContentType(mime::TEXT_PLAIN_UTF_8)
}
/// A constructor to easily create a `Content-Type: text/html` header.
#[inline]
#[must_use]
pub fn html() -> ContentType {
ContentType(mime::TEXT_HTML)
}
/// A constructor to easily create a `Content-Type: text/xml` header.
#[inline]
#[must_use]
pub fn xml() -> ContentType {
ContentType(mime::TEXT_XML)
}
@ -93,21 +89,18 @@ impl ContentType {
/// A constructor to easily create a `Content-Type:
/// application/www-form-url-encoded` header.
#[inline]
#[must_use]
pub fn form_url_encoded() -> ContentType {
ContentType(mime::APPLICATION_WWW_FORM_URLENCODED)
}
/// A constructor to easily create a `Content-Type: image/jpeg` header.
#[inline]
#[must_use]
pub fn jpeg() -> ContentType {
ContentType(mime::IMAGE_JPEG)
}
/// A constructor to easily create a `Content-Type: image/png` header.
#[inline]
#[must_use]
pub fn png() -> ContentType {
ContentType(mime::IMAGE_PNG)
}
@ -115,7 +108,6 @@ impl ContentType {
/// A constructor to easily create a `Content-Type:
/// application/octet-stream` header.
#[inline]
#[must_use]
pub fn octet_stream() -> ContentType {
ContentType(mime::APPLICATION_OCTET_STREAM)
}

View File

@ -38,7 +38,6 @@ crate::http::header::common_header! {
impl Date {
/// Create a date instance set to the current system time
#[must_use]
pub fn now() -> Date {
Date(SystemTime::now().into())
}

View File

@ -58,7 +58,6 @@ impl EntityTag {
/// Constructs a new EntityTag.
/// # Panics
/// If the tag contains invalid characters.
#[must_use]
pub fn new(weak: bool, tag: String) -> EntityTag {
assert!(check_slice_validity(&tag), "Invalid tag: {:?}", tag);
EntityTag { weak, tag }
@ -67,7 +66,6 @@ impl EntityTag {
/// Constructs a new weak EntityTag.
/// # Panics
/// If the tag contains invalid characters.
#[must_use]
pub fn weak(tag: String) -> EntityTag {
EntityTag::new(true, tag)
}
@ -75,13 +73,11 @@ impl EntityTag {
/// Constructs a new strong EntityTag.
/// # Panics
/// If the tag contains invalid characters.
#[must_use]
pub fn strong(tag: String) -> EntityTag {
EntityTag::new(false, tag)
}
/// Get the tag.
#[must_use]
pub fn tag(&self) -> &str {
self.tag.as_ref()
}
@ -96,7 +92,6 @@ impl EntityTag {
/// For strong comparison two entity-tags are equivalent if both are not
/// weak and their opaque-tags match character-by-character.
#[must_use]
pub fn strong_eq(&self, other: &EntityTag) -> bool {
!self.weak && !other.weak && self.tag == other.tag
}
@ -104,19 +99,16 @@ impl EntityTag {
/// For weak comparison two entity-tags are equivalent if their
/// opaque-tags match character-by-character, regardless of either or
/// both being tagged as "weak".
#[must_use]
pub fn weak_eq(&self, other: &EntityTag) -> bool {
self.tag == other.tag
}
/// The inverse of `EntityTag.strong_eq()`.
#[must_use]
pub fn strong_ne(&self, other: &EntityTag) -> bool {
!self.strong_eq(other)
}
/// The inverse of `EntityTag.weak_eq()`.
#[must_use]
pub fn weak_ne(&self, other: &EntityTag) -> bool {
!self.weak_eq(other)
}

View File

@ -161,7 +161,6 @@ impl ConnectionInfo {
/// - X-Forwarded-Proto
/// - Uri
#[inline]
#[must_use]
pub fn scheme(&self) -> &str {
&self.scheme
}
@ -175,7 +174,6 @@ impl ConnectionInfo {
/// - Host
/// - Uri
/// - Server hostname
#[must_use]
pub fn host(&self) -> &str {
&self.host
}
@ -183,7 +181,6 @@ impl ConnectionInfo {
/// remote_addr address of the request.
///
/// Get remote_addr address from socket address
#[must_use]
pub fn remote_addr(&self) -> Option<&str> {
self.remote_addr.as_ref().map(String::as_ref)
}
@ -201,7 +198,6 @@ impl ConnectionInfo {
/// address explicitly, use
/// [`HttpRequest::peer_addr()`](super::web::HttpRequest::peer_addr()) instead.
#[inline]
#[must_use]
pub fn realip_remote_addr(&self) -> Option<&str> {
if let Some(ref r) = self.realip_remote_addr {
Some(r)

View File

@ -43,7 +43,6 @@ pub struct Compress(ContentEncoding);
impl Compress {
/// Create new `Compress` middleware with the specified encoding.
#[must_use]
pub fn new(encoding: ContentEncoding) -> Self {
Compress(encoding)
}

View File

@ -65,7 +65,6 @@ impl HttpRequest {
impl HttpRequest {
/// This method returns reference to the request head
#[inline]
#[must_use]
pub fn head(&self) -> &RequestHead {
&self.inner.head
}
@ -79,27 +78,23 @@ impl HttpRequest {
/// Request's uri.
#[inline]
#[must_use]
pub fn uri(&self) -> &Uri {
&self.head().uri
}
/// Read the Request method.
#[inline]
#[must_use]
pub fn method(&self) -> &Method {
&self.head().method
}
/// Read the Request Version.
#[inline]
#[must_use]
pub fn version(&self) -> Version {
self.head().version
}
#[inline]
#[must_use]
/// Returns request's headers.
pub fn headers(&self) -> &HeaderMap {
&self.head().headers
@ -107,7 +102,6 @@ impl HttpRequest {
/// The target path of this Request.
#[inline]
#[must_use]
pub fn path(&self) -> &str {
self.head().uri.path()
}
@ -116,7 +110,6 @@ impl HttpRequest {
///
/// E.g., id=10
#[inline]
#[must_use]
pub fn query_string(&self) -> &str {
self.uri().query().unwrap_or_default()
}
@ -128,7 +121,6 @@ impl HttpRequest {
/// where the identifier can be used later in a request handler to
/// access the matched value for that segment.
#[inline]
#[must_use]
pub fn match_info(&self) -> &Path<Url> {
&self.inner.path
}
@ -145,7 +137,6 @@ impl HttpRequest {
///
/// Returns a None when no resource is fully matched, including default services.
#[inline]
#[must_use]
pub fn match_pattern(&self) -> Option<String> {
self.resource_map().match_pattern(self.path())
}
@ -154,21 +145,18 @@ impl HttpRequest {
///
/// Returns a None when no resource is fully matched, including default services.
#[inline]
#[must_use]
pub fn match_name(&self) -> Option<&str> {
self.resource_map().match_name(self.path())
}
/// Request extensions
#[inline]
#[must_use]
pub fn extensions(&self) -> Ref<'_, Extensions> {
self.head().extensions()
}
/// Mutable reference to a the request's extensions
#[inline]
#[must_use]
pub fn extensions_mut(&self) -> RefMut<'_, Extensions> {
self.head().extensions_mut()
}
@ -209,7 +197,6 @@ impl HttpRequest {
}
#[inline]
#[must_use]
/// Get a reference to a `ResourceMap` of current application.
pub fn resource_map(&self) -> &ResourceMap {
&self.app_state().rmap()
@ -224,7 +211,6 @@ impl HttpRequest {
///
/// Will only return None when called in unit tests.
#[inline]
#[must_use]
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
self.head().peer_addr
}
@ -234,14 +220,12 @@ impl HttpRequest {
/// This method panics if request's extensions container is already
/// borrowed.
#[inline]
#[must_use]
pub fn connection_info(&self) -> Ref<'_, ConnectionInfo> {
ConnectionInfo::get(self.head(), self.app_config())
}
/// App config
#[inline]
#[must_use]
pub fn app_config(&self) -> &AppConfig {
self.app_state().config()
}
@ -254,7 +238,6 @@ impl HttpRequest {
/// ```ignore
/// let opt_t = req.app_data::<Data<T>>();
/// ```
#[must_use]
pub fn app_data<T: 'static>(&self) -> Option<&T> {
for container in self.inner.app_data.iter().rev() {
if let Some(data) = container.get::<T>() {
@ -295,7 +278,6 @@ impl HttpRequest {
/// Return request cookie.
#[cfg(feature = "cookies")]
#[must_use]
pub fn cookie(&self, name: &str) -> Option<Cookie<'static>> {
if let Ok(cookies) = self.cookies() {
for cookie in cookies.iter() {

View File

@ -42,7 +42,6 @@ pub struct HttpResponseBuilder {
impl HttpResponseBuilder {
#[inline]
/// Create response builder
#[must_use]
pub fn new(status: StatusCode) -> Self {
Self {
res: Some(Response::new(status)),

View File

@ -7,7 +7,6 @@ use crate::{HttpResponse, HttpResponseBuilder};
macro_rules! static_resp {
($name:ident, $status:expr) => {
#[allow(non_snake_case, missing_docs)]
#[must_use]
pub fn $name() -> HttpResponseBuilder {
HttpResponseBuilder::new($status)
}

View File

@ -33,13 +33,11 @@ pub struct HttpResponse<B = AnyBody> {
impl HttpResponse<AnyBody> {
/// Create HTTP response builder with specific status.
#[inline]
#[must_use]
pub fn build(status: StatusCode) -> HttpResponseBuilder {
HttpResponseBuilder::new(status)
}
/// Create a response.
#[must_use]
#[inline]
pub fn new(status: StatusCode) -> Self {
Self {
@ -50,7 +48,6 @@ impl HttpResponse<AnyBody> {
/// Create an error response.
#[inline]
#[must_use]
pub fn from_error(error: impl Into<Error>) -> Self {
let error = error.into();
let mut response = error.as_response_error().error_response();

View File

@ -17,7 +17,6 @@ pub struct ResourceMap {
}
impl ResourceMap {
#[must_use]
pub fn new(root: ResourceDef) -> Self {
ResourceMap {
root,

View File

@ -28,7 +28,6 @@ pub struct Route {
impl Route {
/// Create new route which matches any request.
#[allow(clippy::new_without_default)]
#[must_use]
pub fn new() -> Route {
Route {
service: boxed::factory(HandlerService::new(HttpResponse::NotFound)),
@ -102,7 +101,6 @@ impl Route {
/// );
/// # }
/// ```
#[must_use]
pub fn method(mut self, method: Method) -> Self {
Rc::get_mut(&mut self.guards)
.unwrap()

View File

@ -65,7 +65,6 @@ pub struct Scope<T = ScopeEndpoint> {
impl Scope {
/// Create a new scope
#[must_use]
pub fn new(path: &str) -> Scope {
let factory_ref = Rc::new(RefCell::new(None));

View File

@ -75,7 +75,6 @@ impl ServiceRequest {
/// Deconstruct request into parts
#[inline]
#[must_use]
pub fn into_parts(self) -> (HttpRequest, Payload) {
(self.req, self.payload)
}
@ -87,7 +86,6 @@ impl ServiceRequest {
}
/// Construct request from parts.
#[must_use]
pub fn from_parts(req: HttpRequest, payload: Payload) -> Self {
Self { req, payload }
}
@ -95,7 +93,6 @@ impl ServiceRequest {
/// Construct request from request.
///
/// The returned `ServiceRequest` would have no payload.
#[must_use]
pub fn from_request(req: HttpRequest) -> Self {
ServiceRequest {
req,
@ -119,7 +116,6 @@ impl ServiceRequest {
/// This method returns reference to the request head
#[inline]
#[must_use]
pub fn head(&self) -> &RequestHead {
&self.req.head()
}
@ -132,34 +128,29 @@ impl ServiceRequest {
/// Request's uri.
#[inline]
#[must_use]
pub fn uri(&self) -> &Uri {
&self.head().uri
}
/// Read the Request method.
#[inline]
#[must_use]
pub fn method(&self) -> &Method {
&self.head().method
}
/// Read the Request Version.
#[inline]
#[must_use]
pub fn version(&self) -> Version {
self.head().version
}
#[inline]
#[must_use]
/// Returns request's headers.
pub fn headers(&self) -> &HeaderMap {
&self.head().headers
}
#[inline]
#[must_use]
/// Returns mutable request's headers.
pub fn headers_mut(&mut self) -> &mut HeaderMap {
&mut self.head_mut().headers
@ -167,7 +158,6 @@ impl ServiceRequest {
/// The target path of this Request.
#[inline]
#[must_use]
pub fn path(&self) -> &str {
self.head().uri.path()
}
@ -176,7 +166,6 @@ impl ServiceRequest {
///
/// E.g., id=10
#[inline]
#[must_use]
pub fn query_string(&self) -> &str {
self.uri().query().unwrap_or_default()
}
@ -190,14 +179,12 @@ impl ServiceRequest {
///
/// Will only return None when called in unit tests.
#[inline]
#[must_use]
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
self.head().peer_addr
}
/// Get *ConnectionInfo* for the current request.
#[inline]
#[must_use]
pub fn connection_info(&self) -> Ref<'_, ConnectionInfo> {
ConnectionInfo::get(self.head(), &*self.app_config())
}
@ -209,34 +196,29 @@ impl ServiceRequest {
/// where the identifier can be used later in a request handler to
/// access the matched value for that segment.
#[inline]
#[must_use]
pub fn match_info(&self) -> &Path<Url> {
self.req.match_info()
}
/// Counterpart to [`HttpRequest::match_name`](super::HttpRequest::match_name()).
#[inline]
#[must_use]
pub fn match_name(&self) -> Option<&str> {
self.req.match_name()
}
/// Counterpart to [`HttpRequest::match_pattern`](super::HttpRequest::match_pattern()).
#[inline]
#[must_use]
pub fn match_pattern(&self) -> Option<String> {
self.req.match_pattern()
}
#[inline]
#[must_use]
/// Get a mutable reference to the Path parameters.
pub fn match_info_mut(&mut self) -> &mut Path<Url> {
self.req.match_info_mut()
}
#[inline]
#[must_use]
/// Get a reference to a `ResourceMap` of current application.
pub fn resource_map(&self) -> &ResourceMap {
self.req.resource_map()
@ -244,13 +226,11 @@ impl ServiceRequest {
/// Service configuration
#[inline]
#[must_use]
pub fn app_config(&self) -> &AppConfig {
self.req.app_config()
}
/// Counterpart to [`HttpRequest::app_data`](super::HttpRequest::app_data()).
#[must_use]
pub fn app_data<T: 'static>(&self) -> Option<&T> {
for container in self.req.inner.app_data.iter().rev() {
if let Some(data) = container.get::<T>() {
@ -268,7 +248,6 @@ impl ServiceRequest {
/// Return request cookie.
#[cfg(feature = "cookies")]
#[must_use]
pub fn cookie(&self, name: &str) -> Option<Cookie<'static>> {
self.req.cookie(name)
}
@ -497,7 +476,6 @@ impl WebService {
/// Set service name.
///
/// Name is used for url generation.
#[must_use]
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self

View File

@ -31,14 +31,12 @@ use crate::{
};
/// Create service that always responds with `HttpResponse::Ok()` and no body.
#[must_use]
pub fn ok_service(
) -> impl Service<ServiceRequest, Response = ServiceResponse<Body>, Error = Error> {
default_service(StatusCode::OK)
}
/// Create service that always responds with given status code and no body.
#[must_use]
pub fn default_service(
status_code: StatusCode,
) -> impl Service<ServiceRequest, Response = ServiceResponse<Body>, Error = Error> {
@ -400,37 +398,31 @@ impl Default for TestRequest {
#[allow(clippy::wrong_self_convention)]
impl TestRequest {
/// Create TestRequest and set request uri
#[must_use]
pub fn with_uri(path: &str) -> TestRequest {
TestRequest::default().uri(path)
}
/// Create TestRequest and set method to `Method::GET`
#[must_use]
pub fn get() -> TestRequest {
TestRequest::default().method(Method::GET)
}
/// Create TestRequest and set method to `Method::POST`
#[must_use]
pub fn post() -> TestRequest {
TestRequest::default().method(Method::POST)
}
/// Create TestRequest and set method to `Method::PUT`
#[must_use]
pub fn put() -> TestRequest {
TestRequest::default().method(Method::PUT)
}
/// Create TestRequest and set method to `Method::PATCH`
#[must_use]
pub fn patch() -> TestRequest {
TestRequest::default().method(Method::PATCH)
}
/// Create TestRequest and set method to `Method::DELETE`
#[must_use]
pub fn delete() -> TestRequest {
TestRequest::default().method(Method::DELETE)
}

View File

@ -228,14 +228,12 @@ pub struct FormConfig {
impl FormConfig {
/// Set maximum accepted payload size. By default this limit is 16kB.
#[must_use]
pub fn limit(mut self, limit: usize) -> Self {
self.limit = limit;
self
}
/// Set custom error handler
#[must_use]
pub fn error_handler<F>(mut self, f: F) -> Self
where
F: Fn(UrlencodedError, &HttpRequest) -> Error + 'static,
@ -332,7 +330,6 @@ impl<T> UrlEncoded<T> {
}
/// Set maximum accepted payload size. The default limit is 256kB.
#[must_use]
pub fn limit(mut self, limit: usize) -> Self {
self.limit = limit;
self

View File

@ -241,14 +241,12 @@ pub struct JsonConfig {
impl JsonConfig {
/// Set maximum accepted payload size. By default this limit is 2MB.
#[must_use]
pub fn limit(mut self, limit: usize) -> Self {
self.limit = limit;
self
}
/// Set custom error handler.
#[must_use]
pub fn error_handler<F>(mut self, f: F) -> Self
where
F: Fn(JsonPayloadError, &HttpRequest) -> Error + Send + Sync + 'static,
@ -258,7 +256,6 @@ impl JsonConfig {
}
/// Set predicate for allowed content types.
#[must_use]
pub fn content_type<F>(mut self, predicate: F) -> Self
where
F: Fn(mime::Mime) -> bool + Send + Sync + 'static,
@ -368,7 +365,6 @@ where
}
/// Set maximum accepted payload size. The default limit is 2MB.
#[must_use]
pub fn limit(self, limit: usize) -> Self {
match self {
JsonBody::Body {

View File

@ -47,7 +47,6 @@ pub struct Payload(pub crate::dev::Payload);
impl Payload {
/// Unwrap to inner Payload type.
#[must_use]
pub fn into_inner(self) -> crate::dev::Payload {
self.0
}
@ -215,7 +214,6 @@ pub struct PayloadConfig {
impl PayloadConfig {
/// Create new instance with a size limit (in bytes) and no mime type condition.
#[must_use]
pub fn new(limit: usize) -> Self {
Self {
limit,
@ -224,14 +222,12 @@ impl PayloadConfig {
}
/// Set maximum accepted payload size in bytes. The default limit is 256kB.
#[must_use]
pub fn limit(mut self, limit: usize) -> Self {
self.limit = limit;
self
}
/// Set required mime type of the request. By default mime type is not enforced.
#[must_use]
pub fn mimetype(mut self, mt: Mime) -> Self {
self.mimetype = Some(mt);
self

View File

@ -51,7 +51,6 @@ pub use crate::types::*;
/// .route(web::head().to(|| HttpResponse::MethodNotAllowed()))
/// );
/// ```
#[must_use]
pub fn resource<T: IntoPattern>(path: T) -> Resource {
Resource::new(path)
}
@ -77,13 +76,11 @@ pub fn resource<T: IntoPattern>(path: T) -> Resource {
/// * /{project_id}/path2
/// * /{project_id}/path3
///
#[must_use]
pub fn scope(path: &str) -> Scope {
Scope::new(path)
}
/// Create *route* without configuration.
#[must_use]
pub fn route() -> Route {
Route::new()
}
@ -102,7 +99,6 @@ pub fn route() -> Route {
/// In the above example, one `GET` route gets added:
/// * /{project_id}
///
#[must_use]
pub fn get() -> Route {
method(Method::GET)
}
@ -121,7 +117,6 @@ pub fn get() -> Route {
/// In the above example, one `POST` route gets added:
/// * /{project_id}
///
#[must_use]
pub fn post() -> Route {
method(Method::POST)
}
@ -140,7 +135,6 @@ pub fn post() -> Route {
/// In the above example, one `PUT` route gets added:
/// * /{project_id}
///
#[must_use]
pub fn put() -> Route {
method(Method::PUT)
}
@ -159,7 +153,6 @@ pub fn put() -> Route {
/// In the above example, one `PATCH` route gets added:
/// * /{project_id}
///
#[must_use]
pub fn patch() -> Route {
method(Method::PATCH)
}
@ -178,7 +171,6 @@ pub fn patch() -> Route {
/// In the above example, one `DELETE` route gets added:
/// * /{project_id}
///
#[must_use]
pub fn delete() -> Route {
method(Method::DELETE)
}
@ -197,7 +189,6 @@ pub fn delete() -> Route {
/// In the above example, one `HEAD` route gets added:
/// * /{project_id}
///
#[must_use]
pub fn head() -> Route {
method(Method::HEAD)
}
@ -216,7 +207,6 @@ pub fn head() -> Route {
/// In the above example, one `HEAD` route gets added:
/// * /{project_id}
///
#[must_use]
pub fn trace() -> Route {
method(Method::TRACE)
}
@ -235,7 +225,6 @@ pub fn trace() -> Route {
/// In the above example, one `GET` route gets added:
/// * /{project_id}
///
#[must_use]
pub fn method(method: Method) -> Route {
Route::new().method(method)
}
@ -254,7 +243,6 @@ pub fn method(method: Method) -> Route {
/// web::to(index))
/// );
/// ```
#[must_use]
pub fn to<F, I, R>(handler: F) -> Route
where
F: Handler<I, R>,
@ -280,7 +268,6 @@ where
/// .finish(my_service)
/// );
/// ```
#[must_use]
pub fn service<T: IntoPattern>(path: T) -> WebService {
WebService::new(path)
}