identifiers: Rename RoomIdOrAliasId to RoomOrAliasId
This commit is contained in:
parent
6b76d7813e
commit
8923881678
@ -1,7 +1,7 @@
|
|||||||
//! [POST /_matrix/client/r0/knock/{roomIdOrAlias}](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0knockroomidoralias)
|
//! [POST /_matrix/client/r0/knock/{roomIdOrAlias}](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0knockroomidoralias)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::{RoomId, RoomIdOrAliasId, ServerName};
|
use ruma_identifiers::{RoomId, RoomOrAliasId, ServerName};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -16,7 +16,7 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// The room the user should knock on.
|
/// The room the user should knock on.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub room_id_or_alias: &'a RoomIdOrAliasId,
|
pub room_id_or_alias: &'a RoomOrAliasId,
|
||||||
|
|
||||||
/// The reason for joining a room.
|
/// The reason for joining a room.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@ -38,7 +38,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given room ID or alias.
|
/// Creates a new `Request` with the given room ID or alias.
|
||||||
pub fn new(room_id_or_alias: &'a RoomIdOrAliasId) -> Self {
|
pub fn new(room_id_or_alias: &'a RoomOrAliasId) -> Self {
|
||||||
Self { room_id_or_alias, reason: None, server_name: &[] }
|
Self { room_id_or_alias, reason: None, server_name: &[] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-join-roomidoralias)
|
//! [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-join-roomidoralias)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::{RoomId, RoomIdOrAliasId, ServerName};
|
use ruma_identifiers::{RoomId, RoomOrAliasId, ServerName};
|
||||||
|
|
||||||
use super::{IncomingThirdPartySigned, ThirdPartySigned};
|
use super::{IncomingThirdPartySigned, ThirdPartySigned};
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// The room where the user should be invited.
|
/// The room where the user should be invited.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub room_id_or_alias: &'a RoomIdOrAliasId,
|
pub room_id_or_alias: &'a RoomOrAliasId,
|
||||||
|
|
||||||
/// The servers to attempt to join the room through.
|
/// The servers to attempt to join the room through.
|
||||||
///
|
///
|
||||||
@ -48,7 +48,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given room ID or alias ID.
|
/// Creates a new `Request` with the given room ID or alias ID.
|
||||||
pub fn new(room_id_or_alias: &'a RoomIdOrAliasId) -> Self {
|
pub fn new(room_id_or_alias: &'a RoomOrAliasId) -> Self {
|
||||||
Self {
|
Self {
|
||||||
room_id_or_alias,
|
room_id_or_alias,
|
||||||
server_name: &[],
|
server_name: &[],
|
||||||
|
@ -10,6 +10,7 @@ Breaking changes:
|
|||||||
* The corresponding macros (and also `server_name!`) now return `'static` references instead of
|
* The corresponding macros (and also `server_name!`) now return `'static` references instead of
|
||||||
owned values now – use `.to_owned()` to get an owned copy
|
owned values now – use `.to_owned()` to get an owned copy
|
||||||
* Rename `RoomVersionId::Version{X}` variants to `RoomVersionId::V{X}`
|
* Rename `RoomVersionId::Version{X}` variants to `RoomVersionId::V{X}`
|
||||||
|
* Rename `RoomIdOrAliasId` to `RoomOrAliasId`
|
||||||
|
|
||||||
# 0.20.0
|
# 0.20.0
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ pub use crate::{
|
|||||||
mxc_uri::MxcUri,
|
mxc_uri::MxcUri,
|
||||||
room_alias_id::RoomAliasId,
|
room_alias_id::RoomAliasId,
|
||||||
room_id::RoomId,
|
room_id::RoomId,
|
||||||
room_id_or_room_alias_id::RoomIdOrAliasId,
|
|
||||||
room_name::RoomName,
|
room_name::RoomName,
|
||||||
|
room_or_room_alias_id::RoomOrAliasId,
|
||||||
room_version_id::RoomVersionId,
|
room_version_id::RoomVersionId,
|
||||||
server_name::ServerName,
|
server_name::ServerName,
|
||||||
session_id::SessionId,
|
session_id::SessionId,
|
||||||
@ -59,8 +59,8 @@ mod matrix_to;
|
|||||||
mod mxc_uri;
|
mod mxc_uri;
|
||||||
mod room_alias_id;
|
mod room_alias_id;
|
||||||
mod room_id;
|
mod room_id;
|
||||||
mod room_id_or_room_alias_id;
|
|
||||||
mod room_name;
|
mod room_name;
|
||||||
|
mod room_or_room_alias_id;
|
||||||
mod room_version_id;
|
mod room_version_id;
|
||||||
mod server_name;
|
mod server_name;
|
||||||
mod session_id;
|
mod session_id;
|
||||||
|
@ -9,33 +9,33 @@ use crate::{server_name::ServerName, RoomAliasId, RoomId};
|
|||||||
|
|
||||||
/// A Matrix room ID or a Matrix room alias ID.
|
/// A Matrix room ID or a Matrix room alias ID.
|
||||||
///
|
///
|
||||||
/// `RoomIdOrAliasId` is useful for APIs that accept either kind of room identifier. It is converted
|
/// `RoomOrAliasId` is useful for APIs that accept either kind of room identifier. It is converted
|
||||||
/// from a string slice, and can be converted back into a string as needed. When converted from a
|
/// from a string slice, and can be converted back into a string as needed. When converted from a
|
||||||
/// string slice, the variant is determined by the leading sigil character.
|
/// string slice, the variant is determined by the leading sigil character.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use std::convert::TryFrom;
|
/// # use std::convert::TryFrom;
|
||||||
/// # use ruma_identifiers::RoomIdOrAliasId;
|
/// # use ruma_identifiers::RoomOrAliasId;
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// <&RoomIdOrAliasId>::try_from("#ruma:example.com").unwrap(),
|
/// <&RoomOrAliasId>::try_from("#ruma:example.com").unwrap(),
|
||||||
/// "#ruma:example.com"
|
/// "#ruma:example.com"
|
||||||
/// );
|
/// );
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// <&RoomIdOrAliasId>::try_from("!n8f893n9:example.com").unwrap(),
|
/// <&RoomOrAliasId>::try_from("!n8f893n9:example.com").unwrap(),
|
||||||
/// "!n8f893n9:example.com"
|
/// "!n8f893n9:example.com"
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct RoomIdOrAliasId(str);
|
pub struct RoomOrAliasId(str);
|
||||||
|
|
||||||
opaque_identifier_validated!(
|
opaque_identifier_validated!(
|
||||||
RoomIdOrAliasId,
|
RoomOrAliasId,
|
||||||
ruma_identifiers_validation::room_id_or_alias_id::validate
|
ruma_identifiers_validation::room_id_or_alias_id::validate
|
||||||
);
|
);
|
||||||
|
|
||||||
impl RoomIdOrAliasId {
|
impl RoomOrAliasId {
|
||||||
/// Returns the local part (everything after the `!` or `#` and before the first colon).
|
/// Returns the local part (everything after the `!` or `#` and before the first colon).
|
||||||
pub fn localpart(&self) -> &str {
|
pub fn localpart(&self) -> &str {
|
||||||
&self.as_str()[1..self.colon_idx()]
|
&self.as_str()[1..self.colon_idx()]
|
||||||
@ -56,7 +56,7 @@ impl RoomIdOrAliasId {
|
|||||||
self.variant() == Variant::RoomAliasId
|
self.variant() == Variant::RoomAliasId
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turn this `RoomIdOrAliasId` into `Either<RoomId, RoomAliasId>`
|
/// Turn this `RoomOrAliasId` into `Either<RoomId, RoomAliasId>`
|
||||||
#[cfg(feature = "either")]
|
#[cfg(feature = "either")]
|
||||||
pub fn into_either(self: Box<Self>) -> either::Either<Box<RoomId>, Box<RoomAliasId>> {
|
pub fn into_either(self: Box<Self>) -> either::Either<Box<RoomId>, Box<RoomAliasId>> {
|
||||||
let variant = self.variant();
|
let variant = self.variant();
|
||||||
@ -87,22 +87,22 @@ enum Variant {
|
|||||||
RoomAliasId,
|
RoomAliasId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<RoomId>> for Box<RoomIdOrAliasId> {
|
impl From<Box<RoomId>> for Box<RoomOrAliasId> {
|
||||||
fn from(room_id: Box<RoomId>) -> Self {
|
fn from(room_id: Box<RoomId>) -> Self {
|
||||||
Self::try_from(room_id.as_str()).unwrap()
|
Self::try_from(room_id.as_str()).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<RoomAliasId>> for Box<RoomIdOrAliasId> {
|
impl From<Box<RoomAliasId>> for Box<RoomOrAliasId> {
|
||||||
fn from(room_alias_id: Box<RoomAliasId>) -> Self {
|
fn from(room_alias_id: Box<RoomAliasId>) -> Self {
|
||||||
Self::try_from(room_alias_id.as_str()).unwrap()
|
Self::try_from(room_alias_id.as_str()).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Box<RoomIdOrAliasId>> for Box<RoomId> {
|
impl TryFrom<Box<RoomOrAliasId>> for Box<RoomId> {
|
||||||
type Error = Box<RoomAliasId>;
|
type Error = Box<RoomAliasId>;
|
||||||
|
|
||||||
fn try_from(id: Box<RoomIdOrAliasId>) -> Result<Box<RoomId>, Box<RoomAliasId>> {
|
fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomId>, Box<RoomAliasId>> {
|
||||||
match id.variant() {
|
match id.variant() {
|
||||||
Variant::RoomId => Ok(id.as_str().try_into().unwrap()),
|
Variant::RoomId => Ok(id.as_str().try_into().unwrap()),
|
||||||
Variant::RoomAliasId => Err(id.as_str().try_into().unwrap()),
|
Variant::RoomAliasId => Err(id.as_str().try_into().unwrap()),
|
||||||
@ -110,10 +110,10 @@ impl TryFrom<Box<RoomIdOrAliasId>> for Box<RoomId> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Box<RoomIdOrAliasId>> for Box<RoomAliasId> {
|
impl TryFrom<Box<RoomOrAliasId>> for Box<RoomAliasId> {
|
||||||
type Error = Box<RoomId>;
|
type Error = Box<RoomId>;
|
||||||
|
|
||||||
fn try_from(id: Box<RoomIdOrAliasId>) -> Result<Box<RoomAliasId>, Box<RoomId>> {
|
fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomAliasId>, Box<RoomId>> {
|
||||||
match id.variant() {
|
match id.variant() {
|
||||||
Variant::RoomAliasId => Ok(id.as_str().try_into().unwrap()),
|
Variant::RoomAliasId => Ok(id.as_str().try_into().unwrap()),
|
||||||
Variant::RoomId => Err(id.as_str().try_into().unwrap()),
|
Variant::RoomId => Err(id.as_str().try_into().unwrap()),
|
||||||
@ -125,13 +125,13 @@ impl TryFrom<Box<RoomIdOrAliasId>> for Box<RoomAliasId> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use super::RoomIdOrAliasId;
|
use super::RoomOrAliasId;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valid_room_id_or_alias_id_with_a_room_alias_id() {
|
fn valid_room_id_or_alias_id_with_a_room_alias_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
<&RoomIdOrAliasId>::try_from("#ruma:example.com")
|
<&RoomOrAliasId>::try_from("#ruma:example.com")
|
||||||
.expect("Failed to create RoomAliasId.")
|
.expect("Failed to create RoomAliasId.")
|
||||||
.as_ref(),
|
.as_ref(),
|
||||||
"#ruma:example.com"
|
"#ruma:example.com"
|
||||||
@ -141,7 +141,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn valid_room_id_or_alias_id_with_a_room_id() {
|
fn valid_room_id_or_alias_id_with_a_room_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
<&RoomIdOrAliasId>::try_from("!29fhd83h92h0:example.com")
|
<&RoomOrAliasId>::try_from("!29fhd83h92h0:example.com")
|
||||||
.expect("Failed to create RoomId.")
|
.expect("Failed to create RoomId.")
|
||||||
.as_ref(),
|
.as_ref(),
|
||||||
"!29fhd83h92h0:example.com"
|
"!29fhd83h92h0:example.com"
|
||||||
@ -151,7 +151,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn missing_sigil_for_room_id_or_alias_id() {
|
fn missing_sigil_for_room_id_or_alias_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
<&RoomIdOrAliasId>::try_from("ruma:example.com").unwrap_err(),
|
<&RoomOrAliasId>::try_from("ruma:example.com").unwrap_err(),
|
||||||
Error::MissingLeadingSigil
|
Error::MissingLeadingSigil
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ mod tests {
|
|||||||
fn serialize_valid_room_id_or_alias_id_with_a_room_alias_id() {
|
fn serialize_valid_room_id_or_alias_id_with_a_room_alias_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_string(
|
serde_json::to_string(
|
||||||
<&RoomIdOrAliasId>::try_from("#ruma:example.com")
|
<&RoomOrAliasId>::try_from("#ruma:example.com")
|
||||||
.expect("Failed to create RoomAliasId.")
|
.expect("Failed to create RoomAliasId.")
|
||||||
)
|
)
|
||||||
.expect("Failed to convert RoomAliasId to JSON."),
|
.expect("Failed to convert RoomAliasId to JSON."),
|
||||||
@ -174,7 +174,7 @@ mod tests {
|
|||||||
fn serialize_valid_room_id_or_alias_id_with_a_room_id() {
|
fn serialize_valid_room_id_or_alias_id_with_a_room_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_string(
|
serde_json::to_string(
|
||||||
<&RoomIdOrAliasId>::try_from("!29fhd83h92h0:example.com")
|
<&RoomOrAliasId>::try_from("!29fhd83h92h0:example.com")
|
||||||
.expect("Failed to create RoomId.")
|
.expect("Failed to create RoomId.")
|
||||||
)
|
)
|
||||||
.expect("Failed to convert RoomId to JSON."),
|
.expect("Failed to convert RoomId to JSON."),
|
||||||
@ -186,10 +186,9 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_room_id_or_alias_id_with_a_room_alias_id() {
|
fn deserialize_valid_room_id_or_alias_id_with_a_room_alias_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<RoomIdOrAliasId>>(r##""#ruma:example.com""##)
|
serde_json::from_str::<Box<RoomOrAliasId>>(r##""#ruma:example.com""##)
|
||||||
.expect("Failed to convert JSON to RoomAliasId"),
|
.expect("Failed to convert JSON to RoomAliasId"),
|
||||||
<&RoomIdOrAliasId>::try_from("#ruma:example.com")
|
<&RoomOrAliasId>::try_from("#ruma:example.com").expect("Failed to create RoomAliasId.")
|
||||||
.expect("Failed to create RoomAliasId.")
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,9 +196,9 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_room_id_or_alias_id_with_a_room_id() {
|
fn deserialize_valid_room_id_or_alias_id_with_a_room_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<RoomIdOrAliasId>>(r##""!29fhd83h92h0:example.com""##)
|
serde_json::from_str::<Box<RoomOrAliasId>>(r##""!29fhd83h92h0:example.com""##)
|
||||||
.expect("Failed to convert JSON to RoomId"),
|
.expect("Failed to convert JSON to RoomId"),
|
||||||
<&RoomIdOrAliasId>::try_from("!29fhd83h92h0:example.com")
|
<&RoomOrAliasId>::try_from("!29fhd83h92h0:example.com")
|
||||||
.expect("Failed to create RoomAliasId.")
|
.expect("Failed to create RoomAliasId.")
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -271,7 +271,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool {
|
|||||||
|| last_seg.ident == "RawJsonValue"
|
|| last_seg.ident == "RawJsonValue"
|
||||||
|| last_seg.ident == "RoomAliasId"
|
|| last_seg.ident == "RoomAliasId"
|
||||||
|| last_seg.ident == "RoomId"
|
|| last_seg.ident == "RoomId"
|
||||||
|| last_seg.ident == "RoomIdOrAliasId"
|
|| last_seg.ident == "RoomOrAliasId"
|
||||||
|| last_seg.ident == "RoomName"
|
|| last_seg.ident == "RoomName"
|
||||||
|| last_seg.ident == "ServerSigningKeyId"
|
|| last_seg.ident == "ServerSigningKeyId"
|
||||||
|| last_seg.ident == "SigningKeyId"
|
|| last_seg.ident == "SigningKeyId"
|
||||||
|
@ -85,9 +85,8 @@ pub use ruma_identifiers::{
|
|||||||
device_id, device_key_id, event_id, mxc_uri, room_alias_id, room_id, room_version_id,
|
device_id, device_key_id, event_id, mxc_uri, room_alias_id, room_id, room_version_id,
|
||||||
server_name, server_signing_key_id, user_id, ClientSecret, DeviceId, DeviceKeyAlgorithm,
|
server_name, server_signing_key_id, user_id, ClientSecret, DeviceId, DeviceKeyAlgorithm,
|
||||||
DeviceKeyId, DeviceSignatures, DeviceSigningKeyId, EntitySignatures, EventEncryptionAlgorithm,
|
DeviceKeyId, DeviceSignatures, DeviceSigningKeyId, EntitySignatures, EventEncryptionAlgorithm,
|
||||||
EventId, KeyId, KeyName, MxcUri, RoomAliasId, RoomId, RoomIdOrAliasId, RoomVersionId,
|
EventId, KeyId, KeyName, MxcUri, RoomAliasId, RoomId, RoomOrAliasId, RoomVersionId, ServerName,
|
||||||
ServerName, ServerSignatures, ServerSigningKeyId, SessionId, Signatures, SigningKeyAlgorithm,
|
ServerSignatures, ServerSigningKeyId, SessionId, Signatures, SigningKeyAlgorithm, UserId,
|
||||||
UserId,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user