identifiers: Make UserId a DST
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
convert::{TryFrom, TryInto},
|
||||
convert::TryInto,
|
||||
sync::{
|
||||
atomic::{AtomicU64, Ordering::SeqCst},
|
||||
Arc,
|
||||
@@ -29,7 +29,7 @@ use ruma_events::{
|
||||
},
|
||||
EventType,
|
||||
};
|
||||
use ruma_identifiers::{room_id, EventId, RoomId, RoomVersionId, UserId};
|
||||
use ruma_identifiers::{room_id, user_id, EventId, RoomId, RoomVersionId, UserId};
|
||||
use ruma_state_res::{self as state_res, Error, Event, Result, StateMap};
|
||||
use serde_json::{
|
||||
json,
|
||||
@@ -339,20 +339,20 @@ fn event_id(id: &str) -> Box<EventId> {
|
||||
format!("${}:foo", id).try_into().unwrap()
|
||||
}
|
||||
|
||||
fn alice() -> UserId {
|
||||
UserId::try_from("@alice:foo").unwrap()
|
||||
fn alice() -> Box<UserId> {
|
||||
user_id!("@alice:foo").to_owned()
|
||||
}
|
||||
|
||||
fn bob() -> UserId {
|
||||
UserId::try_from("@bob:foo").unwrap()
|
||||
fn bob() -> Box<UserId> {
|
||||
user_id!("@bob:foo").to_owned()
|
||||
}
|
||||
|
||||
fn charlie() -> UserId {
|
||||
UserId::try_from("@charlie:foo").unwrap()
|
||||
fn charlie() -> Box<UserId> {
|
||||
user_id!("@charlie:foo").to_owned()
|
||||
}
|
||||
|
||||
fn ella() -> UserId {
|
||||
UserId::try_from("@ella:foo").unwrap()
|
||||
fn ella() -> Box<UserId> {
|
||||
user_id!("@ella:foo").to_owned()
|
||||
}
|
||||
|
||||
fn room_id() -> &'static RoomId {
|
||||
@@ -369,7 +369,7 @@ fn member_content_join() -> Box<RawJsonValue> {
|
||||
|
||||
fn to_pdu_event<S>(
|
||||
id: &str,
|
||||
sender: UserId,
|
||||
sender: Box<UserId>,
|
||||
ev_type: EventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
|
||||
@@ -227,10 +227,10 @@ pub fn auth_check<E: Event>(
|
||||
}
|
||||
|
||||
let target_user =
|
||||
UserId::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?;
|
||||
<&UserId>::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?;
|
||||
|
||||
if !valid_membership_change(
|
||||
&target_user,
|
||||
target_user,
|
||||
fetch_state(&EventType::RoomMember, target_user.as_str()).as_ref(),
|
||||
sender,
|
||||
sender_member_event.as_ref(),
|
||||
|
||||
@@ -325,7 +325,7 @@ struct PowerLevelsContentFields {
|
||||
serde(deserialize_with = "ruma_serde::btreemap_int_or_string_to_int_values")
|
||||
)]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
users: BTreeMap<UserId, Int>,
|
||||
users: BTreeMap<Box<UserId>, Int>,
|
||||
|
||||
#[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))]
|
||||
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
|
||||
|
||||
@@ -153,7 +153,7 @@ pub fn do_check(
|
||||
let ev_id = e.event_id();
|
||||
let event = to_pdu_event(
|
||||
e.event_id().as_str(),
|
||||
e.sender().clone(),
|
||||
e.sender().to_owned(),
|
||||
e.event_type().clone(),
|
||||
e.state_key(),
|
||||
e.content().to_owned(),
|
||||
@@ -347,24 +347,24 @@ pub fn event_id(id: &str) -> Box<EventId> {
|
||||
format!("${}:foo", id).try_into().unwrap()
|
||||
}
|
||||
|
||||
pub fn alice() -> UserId {
|
||||
user_id!("@alice:foo")
|
||||
pub fn alice() -> Box<UserId> {
|
||||
user_id!("@alice:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn bob() -> UserId {
|
||||
user_id!("@bob:foo")
|
||||
pub fn bob() -> Box<UserId> {
|
||||
user_id!("@bob:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn charlie() -> UserId {
|
||||
user_id!("@charlie:foo")
|
||||
pub fn charlie() -> Box<UserId> {
|
||||
user_id!("@charlie:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn ella() -> UserId {
|
||||
user_id!("@ella:foo")
|
||||
pub fn ella() -> Box<UserId> {
|
||||
user_id!("@ella:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn zara() -> UserId {
|
||||
user_id!("@zara:foo")
|
||||
pub fn zara() -> Box<UserId> {
|
||||
user_id!("@zara:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn room_id() -> &'static RoomId {
|
||||
@@ -381,7 +381,7 @@ pub fn member_content_join() -> Box<RawJsonValue> {
|
||||
|
||||
pub fn to_init_pdu_event(
|
||||
id: &str,
|
||||
sender: UserId,
|
||||
sender: Box<UserId>,
|
||||
ev_type: EventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
@@ -414,7 +414,7 @@ pub fn to_init_pdu_event(
|
||||
|
||||
pub fn to_pdu_event<S>(
|
||||
id: &str,
|
||||
sender: UserId,
|
||||
sender: Box<UserId>,
|
||||
ev_type: EventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
|
||||
Reference in New Issue
Block a user