client-api: Add constructors for the types in unversioned

This commit is contained in:
Jonas Platte 2020-06-18 21:33:22 +02:00
parent 4abcc4c0bd
commit f9639e110e
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 45 additions and 0 deletions

View File

@ -3,6 +3,7 @@
//! shared by client and server code.
#![deny(missing_copy_implementations, missing_debug_implementations, missing_docs)]
#![allow(clippy::new_without_default)]
pub mod error;
pub mod r0;

View File

@ -28,16 +28,46 @@ ruma_api! {
error: crate::Error
}
impl Request {
/// Creates an empty `Request`.
pub fn new() -> Self {
Self
}
}
impl Response {
/// Creates a `Response` with the given `HomeserverInfo`.
pub fn new(homeserver: HomeserverInfo) -> Self {
Self { homeserver, identity_server: None }
}
}
/// Information about a discovered homeserver.
#[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
#[non_exhaustive]
pub struct HomeserverInfo {
/// The base URL for the homeserver for client-server connections.
pub base_url: String,
}
impl HomeserverInfo {
/// Creates a `HomeserverInfo` with the given `base_url`.
pub fn new(base_url: String) -> Self {
Self { base_url }
}
}
/// Information about a discovered identity server.
#[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
#[non_exhaustive]
pub struct IdentityServerInfo {
/// The base URL for the identity server for client-server connections.
pub base_url: String,
}
impl IdentityServerInfo {
/// Creates an `IdentityServerInfo` with the given `base_url`.
pub fn new(base_url: String) -> Self {
Self { base_url }
}
}

View File

@ -27,3 +27,17 @@ ruma_api! {
error: crate::Error
}
impl Request {
/// Creates an empty `Request`.
pub fn new() -> Self {
Self
}
}
impl Response {
/// Creates a `Response` with the given `versions`.
pub fn new(versions: Vec<String>) -> Self {
Self { versions, unstable_features: BTreeMap::new() }
}
}