Clean up std::fmt imports

We were pretty inconsistent about them before.
This commit is contained in:
Jonas Platte 2021-03-25 16:32:08 +01:00
parent f053200462
commit 12686fe6e3
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
8 changed files with 28 additions and 51 deletions

View File

@ -1,10 +1,6 @@
//! Errors that can be sent from the homeserver. //! Errors that can be sent from the homeserver.
use std::{ use std::{collections::BTreeMap, fmt, time::Duration};
collections::BTreeMap,
fmt::{self, Display, Formatter},
time::Duration,
};
use ruma_api::{error::ResponseDeserializationError, EndpointError}; use ruma_api::{error::ResponseDeserializationError, EndpointError};
use ruma_identifiers::RoomVersionId; use ruma_identifiers::RoomVersionId;
@ -173,8 +169,8 @@ impl AsRef<str> for ErrorKind {
} }
} }
impl Display for ErrorKind { impl fmt::Display for ErrorKind {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_ref()) write!(f, "{}", self.as_ref())
} }
} }
@ -216,8 +212,8 @@ impl EndpointError for Error {
} }
} }
impl Display for Error { impl fmt::Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{} / {}] {}", self.status_code.as_u16(), self.kind, self.message) write!(f, "[{} / {}] {}", self.status_code.as_u16(), self.kind, self.message)
} }
} }

View File

@ -1,9 +1,5 @@
//! Endpoints for push notifications. //! Endpoints for push notifications.
use std::{ use std::{convert::TryFrom, error::Error, fmt};
convert::TryFrom,
error::Error,
fmt::{self, Display, Formatter},
};
use ruma_common::push::{ use ruma_common::push::{
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule, PatternedPushRuleInit, Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule, PatternedPushRuleInit,
@ -111,8 +107,8 @@ impl From<PushRule> for SimplePushRule {
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct MissingPatternError; pub struct MissingPatternError;
impl Display for MissingPatternError { impl fmt::Display for MissingPatternError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Push rule does not have a pattern.") write!(f, "Push rule does not have a pattern.")
} }
} }
@ -139,8 +135,8 @@ impl TryFrom<PushRule> for PatternedPushRule {
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct MissingConditionsError; pub struct MissingConditionsError;
impl Display for MissingConditionsError { impl fmt::Display for MissingConditionsError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Push rule has no conditions.") write!(f, "Push rule has no conditions.")
} }
} }

View File

@ -1,9 +1,6 @@
//! Module for User-Interactive Authentication API types. //! Module for User-Interactive Authentication API types.
use std::{ use std::{collections::BTreeMap, fmt};
collections::BTreeMap,
fmt::{self, Display, Formatter},
};
use ruma_api::{error::ResponseDeserializationError, EndpointError}; use ruma_api::{error::ResponseDeserializationError, EndpointError};
use ruma_serde::Outgoing; use ruma_serde::Outgoing;
@ -120,8 +117,8 @@ pub enum UiaaResponse {
MatrixError(MatrixError), MatrixError(MatrixError),
} }
impl Display for UiaaResponse { impl fmt::Display for UiaaResponse {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::AuthResponse(_) => write!(f, "User-Interactive Authentication required."), Self::AuthResponse(_) => write!(f, "User-Interactive Authentication required."),
Self::MatrixError(err) => write!(f, "{}", err), Self::MatrixError(err) => write!(f, "{}", err),

View File

@ -1,5 +1,5 @@
use std::{ use std::{
fmt::{self, Display, Formatter}, fmt,
ops::{Bound, RangeBounds, RangeFrom, RangeTo, RangeToInclusive}, ops::{Bound, RangeBounds, RangeFrom, RangeTo, RangeToInclusive},
str::FromStr, str::FromStr,
}; };
@ -101,8 +101,8 @@ impl From<RangeToInclusive<UInt>> for RoomMemberCountIs {
} }
} }
impl Display for RoomMemberCountIs { impl fmt::Display for RoomMemberCountIs {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use ComparisonOperator as Op; use ComparisonOperator as Op;
let prefix = match self.prefix { let prefix = match self.prefix {

View File

@ -1,7 +1,4 @@
use std::{ use std::{error::Error, fmt};
error::Error,
fmt::{self, Display, Formatter},
};
/// An error returned when attempting to create an event with data that would make it invalid. /// An error returned when attempting to create an event with data that would make it invalid.
/// ///
@ -10,8 +7,8 @@ use std::{
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct InvalidInput(pub(crate) String); pub struct InvalidInput(pub(crate) String);
impl Display for InvalidInput { impl fmt::Display for InvalidInput {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0) write!(f, "{}", self.0)
} }
} }
@ -22,8 +19,8 @@ impl Error for InvalidInput {}
#[derive(Clone, Eq, Debug, Hash, PartialEq)] #[derive(Clone, Eq, Debug, Hash, PartialEq)]
pub struct FromStrError; pub struct FromStrError;
impl Display for FromStrError { impl fmt::Display for FromStrError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "failed to parse type from string") write!(f, "failed to parse type from string")
} }
} }

View File

@ -1,6 +1,6 @@
//! Error conditions. //! Error conditions.
use std::fmt::{self, Display, Formatter}; use std::fmt;
/// An error encountered when trying to parse an invalid ID string. /// An error encountered when trying to parse an invalid ID string.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)] #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
@ -36,8 +36,8 @@ pub enum Error {
MissingLeadingSigil, MissingLeadingSigil,
} }
impl Display for Error { impl fmt::Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let message = match self { let message = match self {
Error::EmptyRoomVersionId => "room version ID is empty", Error::EmptyRoomVersionId => "room version ID is empty",
Error::InvalidCharacters => "localpart contains invalid characters", Error::InvalidCharacters => "localpart contains invalid characters",

View File

@ -1,10 +1,6 @@
//! Matrix-spec compliant mxc:// urls. //! Matrix-spec compliant mxc:// urls.
use std::{ use std::{convert::TryFrom, fmt, str::FromStr};
convert::TryFrom,
fmt::{self, Display},
str::FromStr,
};
use ruma_identifiers_validation::mxc_uri::validate; use ruma_identifiers_validation::mxc_uri::validate;
@ -39,7 +35,7 @@ impl fmt::Debug for MxcUri {
} }
} }
impl Display for MxcUri { impl fmt::Display for MxcUri {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.mxc_uri_fmt(f) self.mxc_uri_fmt(f)
} }

View File

@ -1,11 +1,6 @@
//! Matrix-spec compliant server names. //! Matrix-spec compliant server names.
use std::{ use std::{convert::TryFrom, fmt, mem, str::FromStr};
convert::TryFrom,
fmt::{self, Display},
mem,
str::FromStr,
};
use ruma_identifiers_validation::server_name::validate; use ruma_identifiers_validation::server_name::validate;
@ -130,7 +125,7 @@ impl TryFrom<String> for Box<ServerName> {
} }
} }
impl Display for ServerName { impl fmt::Display for ServerName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str()) write!(f, "{}", self.as_str())
} }