Rerun cargo fmt
This commit is contained in:
parent
1df77c2c19
commit
50b74e2b76
@ -202,13 +202,7 @@ impl EndpointError for Error {
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut 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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,21 +210,14 @@ impl std::error::Error for Error {}
|
||||
|
||||
impl From<Error> for ErrorBody {
|
||||
fn from(error: Error) -> Self {
|
||||
Self {
|
||||
kind: error.kind,
|
||||
message: error.message,
|
||||
}
|
||||
Self { kind: error.kind, message: error.message }
|
||||
}
|
||||
}
|
||||
|
||||
impl ErrorBody {
|
||||
/// Convert the ErrorBody into an Error by adding the http status code.
|
||||
pub fn into_error(self, status_code: http::StatusCode) -> Error {
|
||||
Error {
|
||||
kind: self.kind,
|
||||
message: self.message,
|
||||
status_code,
|
||||
}
|
||||
Error { kind: self.kind, message: self.message, status_code }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,7 @@
|
||||
//! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be
|
||||
//! shared by client and server code.
|
||||
|
||||
#![deny(
|
||||
missing_copy_implementations,
|
||||
missing_debug_implementations,
|
||||
missing_docs
|
||||
)]
|
||||
#![deny(missing_copy_implementations, missing_debug_implementations, missing_docs)]
|
||||
|
||||
pub mod error;
|
||||
pub mod r0;
|
||||
|
@ -72,13 +72,7 @@ mod tests {
|
||||
"added_at": 1_535_336_848_756u64
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
to_json_value(third_party_id.clone()).unwrap(),
|
||||
third_party_id_serialized
|
||||
);
|
||||
assert_eq!(
|
||||
third_party_id,
|
||||
from_json_value(third_party_id_serialized).unwrap()
|
||||
);
|
||||
assert_eq!(to_json_value(third_party_id.clone()).unwrap(), third_party_id_serialized);
|
||||
assert_eq!(third_party_id, from_json_value(third_party_id_serialized).unwrap());
|
||||
}
|
||||
}
|
||||
|
@ -187,10 +187,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_deserialize_matrix_network_only() {
|
||||
let json = json!({ "include_all_networks": false });
|
||||
assert_eq!(
|
||||
from_json_value::<RoomNetwork>(json).unwrap(),
|
||||
RoomNetwork::Matrix
|
||||
);
|
||||
assert_eq!(from_json_value::<RoomNetwork>(json).unwrap(), RoomNetwork::Matrix);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -202,10 +199,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_deserialize_empty_network_is_default() {
|
||||
let json = json!({});
|
||||
assert_eq!(
|
||||
from_json_value::<RoomNetwork>(json).unwrap(),
|
||||
RoomNetwork::default()
|
||||
);
|
||||
assert_eq!(from_json_value::<RoomNetwork>(json).unwrap(), RoomNetwork::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -217,19 +211,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_deserialize_include_all_networks() {
|
||||
let json = json!({ "include_all_networks": true });
|
||||
assert_eq!(
|
||||
from_json_value::<RoomNetwork>(json).unwrap(),
|
||||
RoomNetwork::All
|
||||
);
|
||||
assert_eq!(from_json_value::<RoomNetwork>(json).unwrap(), RoomNetwork::All);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_third_party_network() {
|
||||
let json = json!({ "third_party_instance_id": "freenode" });
|
||||
assert_eq!(
|
||||
to_json_value(RoomNetwork::ThirdParty("freenode".to_string())).unwrap(),
|
||||
json
|
||||
);
|
||||
assert_eq!(to_json_value(RoomNetwork::ThirdParty("freenode".to_string())).unwrap(), json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -245,10 +233,7 @@ mod tests {
|
||||
fn test_deserialize_include_all_networks_and_third_party_exclusivity() {
|
||||
let json = json!({ "include_all_networks": true, "third_party_instance_id": "freenode" });
|
||||
assert_eq!(
|
||||
from_json_value::<RoomNetwork>(json)
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.as_str(),
|
||||
from_json_value::<RoomNetwork>(json).unwrap_err().to_string().as_str(),
|
||||
"`include_all_networks = true` and `third_party_instance_id` are mutually exclusive."
|
||||
);
|
||||
}
|
||||
|
@ -87,10 +87,7 @@ pub struct RoomEventFilter {
|
||||
impl RoomEventFilter {
|
||||
/// A filter that can be used to ignore all room events
|
||||
pub fn ignore_all() -> Self {
|
||||
Self {
|
||||
types: Some(vec![]),
|
||||
..Default::default()
|
||||
}
|
||||
Self { types: Some(vec![]), ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,10 +136,7 @@ pub struct RoomFilter {
|
||||
impl RoomFilter {
|
||||
/// A filter that can be used to ignore all room events (of any type)
|
||||
pub fn ignore_all() -> Self {
|
||||
Self {
|
||||
rooms: Some(vec![]),
|
||||
..Default::default()
|
||||
}
|
||||
Self { rooms: Some(vec![]), ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,10 +179,7 @@ pub struct Filter {
|
||||
impl Filter {
|
||||
/// A filter that can be used to ignore all events
|
||||
pub fn ignore_all() -> Self {
|
||||
Self {
|
||||
types: Some(vec![]),
|
||||
..Default::default()
|
||||
}
|
||||
Self { types: Some(vec![]), ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,9 +251,7 @@ impl Serialize for LazyLoadOptions {
|
||||
{
|
||||
let mut state;
|
||||
match *self {
|
||||
Self::Enabled {
|
||||
include_redundant_members: true,
|
||||
} => {
|
||||
Self::Enabled { include_redundant_members: true } => {
|
||||
state = serializer.serialize_struct("LazyLoad", 2)?;
|
||||
state.serialize_field("lazy_load_members", &true)?;
|
||||
state.serialize_field("include_redundant_members", &true)?;
|
||||
@ -309,9 +298,7 @@ impl<'de> Visitor<'de> for LazyLoadOptionsVisitor {
|
||||
}
|
||||
|
||||
Ok(if lazy_load_members {
|
||||
LazyLoadOptions::Enabled {
|
||||
include_redundant_members,
|
||||
}
|
||||
LazyLoadOptions::Enabled { include_redundant_members }
|
||||
} else {
|
||||
LazyLoadOptions::Disabled
|
||||
})
|
||||
@ -341,20 +328,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_serializing_lazy_load_no_redundant() {
|
||||
let lazy_load_options = LazyLoadOptions::Enabled {
|
||||
include_redundant_members: false,
|
||||
};
|
||||
assert_eq!(
|
||||
to_json_value(lazy_load_options).unwrap(),
|
||||
json!({ "lazy_load_members": true })
|
||||
);
|
||||
let lazy_load_options = LazyLoadOptions::Enabled { include_redundant_members: false };
|
||||
assert_eq!(to_json_value(lazy_load_options).unwrap(), json!({ "lazy_load_members": true }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serializing_lazy_load_with_redundant() {
|
||||
let lazy_load_options = LazyLoadOptions::Enabled {
|
||||
include_redundant_members: true,
|
||||
};
|
||||
let lazy_load_options = LazyLoadOptions::Enabled { include_redundant_members: true };
|
||||
assert_eq!(
|
||||
to_json_value(lazy_load_options).unwrap(),
|
||||
json!({ "lazy_load_members": true, "include_redundant_members": true })
|
||||
@ -364,18 +344,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_deserializing_no_lazy_load() {
|
||||
let json = json!({});
|
||||
assert_eq!(
|
||||
from_json_value::<LazyLoadOptions>(json).unwrap(),
|
||||
LazyLoadOptions::Disabled,
|
||||
);
|
||||
assert_eq!(from_json_value::<LazyLoadOptions>(json).unwrap(), LazyLoadOptions::Disabled,);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserializing_ignore_redundant_members_when_no_lazy_load() {
|
||||
let json = json!({ "include_redundant_members": true });
|
||||
assert_eq!(
|
||||
from_json_value::<LazyLoadOptions>(json).unwrap(),
|
||||
LazyLoadOptions::Disabled,
|
||||
);
|
||||
assert_eq!(from_json_value::<LazyLoadOptions>(json).unwrap(), LazyLoadOptions::Disabled,);
|
||||
}
|
||||
}
|
||||
|
@ -103,10 +103,9 @@ impl<'de> Deserialize<'de> for AlgorithmAndDeviceId {
|
||||
let algorithm_result = KeyAlgorithm::try_from(parts[0]);
|
||||
match algorithm_result {
|
||||
Ok(algorithm) => Ok(AlgorithmAndDeviceId(algorithm, parts[1].to_string())),
|
||||
Err(_) => Err(de::Error::invalid_value(
|
||||
Unexpected::Str(parts[0]),
|
||||
&"valid key algorithm",
|
||||
)),
|
||||
Err(_) => {
|
||||
Err(de::Error::invalid_value(Unexpected::Str(parts[0]), &"valid key algorithm"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,15 +51,9 @@ mod tests {
|
||||
fn raw_json_deserialize() {
|
||||
type OptRawJson = Option<Box<RawJsonValue>>;
|
||||
|
||||
assert!(from_json_value::<OptRawJson>(json!(null))
|
||||
.unwrap()
|
||||
.is_none());
|
||||
assert!(from_json_value::<OptRawJson>(json!("test"))
|
||||
.unwrap()
|
||||
.is_some());
|
||||
assert!(from_json_value::<OptRawJson>(json!({ "a": "b" }))
|
||||
.unwrap()
|
||||
.is_some());
|
||||
assert!(from_json_value::<OptRawJson>(json!(null)).unwrap().is_none());
|
||||
assert!(from_json_value::<OptRawJson>(json!("test")).unwrap().is_some());
|
||||
assert!(from_json_value::<OptRawJson>(json!({ "a": "b" })).unwrap().is_some());
|
||||
}
|
||||
|
||||
// For completeness sake, make sure serialization works too
|
||||
|
@ -112,9 +112,7 @@ mod tests {
|
||||
fn test_serialize_some_room_event_filter() {
|
||||
let room_id = RoomId::try_from("!roomid:example.org").unwrap();
|
||||
let filter = RoomEventFilter {
|
||||
lazy_load_options: LazyLoadOptions::Enabled {
|
||||
include_redundant_members: true,
|
||||
},
|
||||
lazy_load_options: LazyLoadOptions::Enabled { include_redundant_members: true },
|
||||
rooms: Some(vec![room_id.clone()]),
|
||||
not_rooms: vec!["room".into(), "room2".into(), "room3".into()],
|
||||
not_types: vec!["type".into()],
|
||||
@ -149,10 +147,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let request: http::Request<Vec<u8>> = req.try_into().unwrap();
|
||||
assert_eq!(
|
||||
"from=token&to=token2&dir=b&limit=0",
|
||||
request.uri().query().unwrap(),
|
||||
);
|
||||
assert_eq!("from=token&to=token2&dir=b&limit=0", request.uri().query().unwrap(),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -116,19 +116,11 @@ impl CreationContent {
|
||||
/// Given a `CreationContent` and the other fields that a homeserver has to fill, construct
|
||||
/// a `CreateEventContent`.
|
||||
pub fn into_event_content(
|
||||
Self {
|
||||
federate,
|
||||
predecessor,
|
||||
}: Self,
|
||||
Self { federate, predecessor }: Self,
|
||||
creator: UserId,
|
||||
room_version: RoomVersionId,
|
||||
) -> CreateEventContent {
|
||||
CreateEventContent {
|
||||
creator,
|
||||
federate,
|
||||
room_version,
|
||||
predecessor,
|
||||
}
|
||||
CreateEventContent { creator, federate, room_version, predecessor }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,9 +155,7 @@ mod tests {
|
||||
"password": "ilovebananas"
|
||||
}),)
|
||||
.unwrap(),
|
||||
LoginInfo::Password {
|
||||
password: "ilovebananas".into()
|
||||
}
|
||||
LoginInfo::Password { password: "ilovebananas".into() }
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@ -166,9 +164,7 @@ mod tests {
|
||||
"token": "1234567890abcdef"
|
||||
}),)
|
||||
.unwrap(),
|
||||
LoginInfo::Token {
|
||||
token: "1234567890abcdef".into()
|
||||
}
|
||||
LoginInfo::Token { token: "1234567890abcdef".into() }
|
||||
);
|
||||
}
|
||||
|
||||
@ -193,9 +189,7 @@ mod tests {
|
||||
address: "hello@example.com".to_owned(),
|
||||
medium: Medium::Email,
|
||||
},
|
||||
login_info: LoginInfo::Token {
|
||||
token: "0xdeadbeef".to_owned(),
|
||||
},
|
||||
login_info: LoginInfo::Token { token: "0xdeadbeef".to_owned() },
|
||||
device_id: None,
|
||||
initial_device_display_name: Some("test".to_string()),
|
||||
}
|
||||
|
@ -28,15 +28,13 @@ impl From<super::UserInfo> for UserInfo {
|
||||
use super::UserInfo::*;
|
||||
|
||||
match info {
|
||||
MatrixId(user) => UserInfo {
|
||||
identifier: UserIdentifier::MatrixId { user },
|
||||
},
|
||||
ThirdPartyId { address, medium } => UserInfo {
|
||||
identifier: UserIdentifier::ThirdPartyId { address, medium },
|
||||
},
|
||||
PhoneNumber { country, phone } => UserInfo {
|
||||
identifier: UserIdentifier::PhoneNumber { country, phone },
|
||||
},
|
||||
MatrixId(user) => UserInfo { identifier: UserIdentifier::MatrixId { user } },
|
||||
ThirdPartyId { address, medium } => {
|
||||
UserInfo { identifier: UserIdentifier::ThirdPartyId { address, medium } }
|
||||
}
|
||||
PhoneNumber { country, phone } => {
|
||||
UserInfo { identifier: UserIdentifier::PhoneNumber { country, phone } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -253,19 +253,13 @@ pub struct RoomSummary {
|
||||
/// Number of users whose membership status is `join`.
|
||||
/// Required if field has changed since last sync; otherwise, it may be
|
||||
/// omitted.
|
||||
#[serde(
|
||||
rename = "m.joined_member_count",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[serde(rename = "m.joined_member_count", skip_serializing_if = "Option::is_none")]
|
||||
pub joined_member_count: Option<UInt>,
|
||||
|
||||
/// Number of users whose membership status is `invite`.
|
||||
/// Required if field has changed since last sync; otherwise, it may be
|
||||
/// omitted.
|
||||
#[serde(
|
||||
rename = "m.invited_member_count",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[serde(rename = "m.invited_member_count", skip_serializing_if = "Option::is_none")]
|
||||
pub invited_member_count: Option<UInt>,
|
||||
}
|
||||
|
||||
@ -370,12 +364,8 @@ mod tests {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let req: Request = http::Request::builder()
|
||||
.uri(uri)
|
||||
.body(Vec::<u8>::new())
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
let req: Request =
|
||||
http::Request::builder().uri(uri).body(Vec::<u8>::new()).unwrap().try_into().unwrap();
|
||||
|
||||
assert_matches!(req.filter, Some(Filter::FilterId(id)) if id == "myfilter");
|
||||
assert_eq!(req.since, Some("myts".into()));
|
||||
@ -393,12 +383,8 @@ mod tests {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let req: Request = http::Request::builder()
|
||||
.uri(uri)
|
||||
.body(Vec::<u8>::new())
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
let req: Request =
|
||||
http::Request::builder().uri(uri).body(Vec::<u8>::new()).unwrap().try_into().unwrap();
|
||||
|
||||
assert_matches!(req.filter, None);
|
||||
assert_eq!(req.since, None);
|
||||
@ -420,12 +406,8 @@ mod tests {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let req: Request = http::Request::builder()
|
||||
.uri(uri)
|
||||
.body(Vec::<u8>::new())
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
let req: Request =
|
||||
http::Request::builder().uri(uri).body(Vec::<u8>::new()).unwrap().try_into().unwrap();
|
||||
|
||||
assert_matches!(req.filter, Some(Filter::FilterId(id)) if id == "EOKFFmdZYF");
|
||||
assert_eq!(req.since, None);
|
||||
|
@ -40,9 +40,7 @@ impl TryFrom<&str> for DeviceIdOrAllDevices {
|
||||
} else if "*" == device_id_or_all_devices {
|
||||
Ok(DeviceIdOrAllDevices::AllDevices)
|
||||
} else {
|
||||
Ok(DeviceIdOrAllDevices::DeviceId(
|
||||
device_id_or_all_devices.to_string(),
|
||||
))
|
||||
Ok(DeviceIdOrAllDevices::DeviceId(device_id_or_all_devices.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,14 +187,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_serialize_authentication_data_fallback() {
|
||||
let authentication_data = AuthData::FallbackAcknowledgement {
|
||||
session: "ZXY000".to_string(),
|
||||
};
|
||||
let authentication_data =
|
||||
AuthData::FallbackAcknowledgement { session: "ZXY000".to_string() };
|
||||
|
||||
assert_eq!(
|
||||
json!({ "session": "ZXY000" }),
|
||||
to_json_value(authentication_data).unwrap()
|
||||
);
|
||||
assert_eq!(json!({ "session": "ZXY000" }), to_json_value(authentication_data).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -331,10 +327,7 @@ mod tests {
|
||||
}
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
uiaa_response.status(),
|
||||
http::status::StatusCode::UNAUTHORIZED
|
||||
);
|
||||
assert_eq!(uiaa_response.status(), http::status::StatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user