identifiers: Rename MatrixToRef to matrix_uri::MatrixToUri
This commit is contained in:
parent
c5a6cf033f
commit
52268b5dc2
@ -32,7 +32,7 @@ pub use crate::{
|
||||
event_id::EventId,
|
||||
key_id::{DeviceSigningKeyId, KeyId, ServerSigningKeyId, SigningKeyId},
|
||||
key_name::KeyName,
|
||||
matrix_to::MatrixToRef,
|
||||
matrix_uri::MatrixToUri,
|
||||
mxc_uri::MxcUri,
|
||||
room_alias_id::RoomAliasId,
|
||||
room_id::RoomId,
|
||||
@ -51,6 +51,7 @@ pub use ruma_identifiers_validation::error::Error;
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
pub mod matrix_uri;
|
||||
pub mod user_id;
|
||||
|
||||
mod client_secret;
|
||||
@ -60,7 +61,6 @@ mod device_key_id;
|
||||
mod event_id;
|
||||
mod key_id;
|
||||
mod key_name;
|
||||
mod matrix_to;
|
||||
mod mxc_uri;
|
||||
mod room_alias_id;
|
||||
mod room_id;
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Matrix URIs.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use percent_encoding::{percent_encode, AsciiSet, CONTROLS};
|
||||
@ -33,13 +35,13 @@ const TO_ENCODE: &AsciiSet = &CONTROLS
|
||||
/// Turn it into a `matrix.to` URL through its `Display` implementation (i.e. by
|
||||
/// interpolating it in a formatting macro or via `.to_string()`).
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct MatrixToRef<'a> {
|
||||
pub struct MatrixToUri<'a> {
|
||||
id: &'a str,
|
||||
event_id: Option<&'a EventId>,
|
||||
via: Vec<&'a ServerName>,
|
||||
}
|
||||
|
||||
impl<'a> MatrixToRef<'a> {
|
||||
impl<'a> MatrixToUri<'a> {
|
||||
pub(crate) fn new(id: &'a str, via: Vec<&'a ServerName>) -> Self {
|
||||
Self { id, event_id: None, via }
|
||||
}
|
||||
@ -49,7 +51,7 @@ impl<'a> MatrixToRef<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for MatrixToRef<'a> {
|
||||
impl<'a> fmt::Display for MatrixToUri<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(BASE_URL)?;
|
||||
write!(f, "{}", percent_encode(self.id.as_bytes(), TO_ENCODE))?;
|
||||
@ -75,7 +77,7 @@ mod tests {
|
||||
use crate::user_id;
|
||||
|
||||
#[test]
|
||||
fn matrix_to_ref() {
|
||||
fn matrix_to_uri() {
|
||||
assert_eq!(
|
||||
user_id!("@jplatte:notareal.hs").matrix_to_url().to_string(),
|
||||
"https://matrix.to/#/%40jplatte%3Anotareal.hs"
|
@ -1,6 +1,6 @@
|
||||
//! Matrix room alias identifiers.
|
||||
|
||||
use crate::{server_name::ServerName, EventId, MatrixToRef};
|
||||
use crate::{server_name::ServerName, EventId, MatrixToUri};
|
||||
|
||||
/// A Matrix room alias ID.
|
||||
///
|
||||
@ -30,13 +30,13 @@ impl RoomAliasId {
|
||||
}
|
||||
|
||||
/// Create a `matrix.to` reference for this room alias ID.
|
||||
pub fn matrix_to_url(&self) -> MatrixToRef<'_> {
|
||||
MatrixToRef::new(self.as_str(), Vec::new())
|
||||
pub fn matrix_to_url(&self) -> MatrixToUri<'_> {
|
||||
MatrixToUri::new(self.as_str(), Vec::new())
|
||||
}
|
||||
|
||||
/// Create a `matrix.to` reference for an event scoped under this room alias ID.
|
||||
pub fn matrix_to_event_url<'a>(&'a self, ev_id: &'a EventId) -> MatrixToRef<'a> {
|
||||
MatrixToRef::event(self.as_str(), ev_id, Vec::new())
|
||||
pub fn matrix_to_event_url<'a>(&'a self, ev_id: &'a EventId) -> MatrixToUri<'a> {
|
||||
MatrixToUri::event(self.as_str(), ev_id, Vec::new())
|
||||
}
|
||||
|
||||
fn colon_idx(&self) -> usize {
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Matrix room identifiers.
|
||||
|
||||
use crate::{EventId, MatrixToRef, ServerName};
|
||||
use crate::{EventId, MatrixToUri, ServerName};
|
||||
|
||||
/// A Matrix room ID.
|
||||
///
|
||||
@ -55,13 +55,13 @@ impl RoomId {
|
||||
pub fn matrix_to_url<'a>(
|
||||
&'a self,
|
||||
via: impl IntoIterator<Item = &'a ServerName>,
|
||||
) -> MatrixToRef<'a> {
|
||||
MatrixToRef::new(self.as_str(), via.into_iter().collect())
|
||||
) -> MatrixToUri<'a> {
|
||||
MatrixToUri::new(self.as_str(), via.into_iter().collect())
|
||||
}
|
||||
|
||||
/// Create a `matrix.to` reference for an event scoped under this room ID.
|
||||
pub fn matrix_to_event_url<'a>(&'a self, ev_id: &'a EventId) -> MatrixToRef<'a> {
|
||||
MatrixToRef::event(self.as_str(), ev_id, Vec::new())
|
||||
pub fn matrix_to_event_url<'a>(&'a self, ev_id: &'a EventId) -> MatrixToUri<'a> {
|
||||
MatrixToUri::event(self.as_str(), ev_id, Vec::new())
|
||||
}
|
||||
|
||||
fn colon_idx(&self) -> usize {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
use crate::{MatrixToRef, ServerName};
|
||||
use crate::{MatrixToUri, ServerName};
|
||||
|
||||
/// A Matrix user ID.
|
||||
///
|
||||
@ -116,8 +116,8 @@ impl UserId {
|
||||
/// display_name = "jplatte",
|
||||
/// );
|
||||
/// ```
|
||||
pub fn matrix_to_url(&self) -> MatrixToRef<'_> {
|
||||
MatrixToRef::new(self.as_str(), Vec::new())
|
||||
pub fn matrix_to_url(&self) -> MatrixToUri<'_> {
|
||||
MatrixToUri::new(self.as_str(), Vec::new())
|
||||
}
|
||||
|
||||
fn colon_idx(&self) -> usize {
|
||||
|
Loading…
x
Reference in New Issue
Block a user