Remove most unreachable visibility modifiers
This commit is contained in:
parent
ffc271f3ec
commit
3dac70ead9
@ -9,6 +9,7 @@ rustflags = [
|
|||||||
"-Wprivate_in_public",
|
"-Wprivate_in_public",
|
||||||
"-Wrust_2018_idioms",
|
"-Wrust_2018_idioms",
|
||||||
"-Wsemicolon_in_expressions_from_macros",
|
"-Wsemicolon_in_expressions_from_macros",
|
||||||
|
"-Wunreachable_pub",
|
||||||
"-Wunused_import_braces",
|
"-Wunused_import_braces",
|
||||||
"-Wunused_qualifications",
|
"-Wunused_qualifications",
|
||||||
"-Wclippy::branches_sharing_code",
|
"-Wclippy::branches_sharing_code",
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Get information about a specific backup.
|
//! Get information about a specific backup.
|
||||||
|
|
||||||
|
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/112615
|
||||||
pub mod v3 {
|
pub mod v3 {
|
||||||
//! `/v3/` ([spec])
|
//! `/v3/` ([spec])
|
||||||
//!
|
//!
|
||||||
|
@ -329,7 +329,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
struct Wrapper {
|
struct Wrapper {
|
||||||
pub flows: Vec<LoginType>,
|
flows: Vec<LoginType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -201,7 +201,7 @@ pub mod v3 {
|
|||||||
struct RequestQuery {
|
struct RequestQuery {
|
||||||
/// Timestamp to use for the `origin_server_ts` of the event.
|
/// Timestamp to use for the `origin_server_ts` of the event.
|
||||||
#[serde(rename = "ts", skip_serializing_if = "Option::is_none")]
|
#[serde(rename = "ts", skip_serializing_if = "Option::is_none")]
|
||||||
pub timestamp: Option<MilliSecondsSinceUnixEpoch>,
|
timestamp: Option<MilliSecondsSinceUnixEpoch>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
|
@ -248,7 +248,7 @@ impl From<AnyTimelineEvent> for AnySyncTimelineEvent {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
struct EventDeHelper {
|
struct EventDeHelper {
|
||||||
pub state_key: Option<de::IgnoredAny>,
|
state_key: Option<de::IgnoredAny>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for AnyTimelineEvent {
|
impl<'de> Deserialize<'de> for AnyTimelineEvent {
|
||||||
|
@ -56,7 +56,7 @@ impl<'de> Deserialize<'de> for MediaSource {
|
|||||||
D: serde::Deserializer<'de>,
|
D: serde::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct MediaSourceJsonRepr {
|
struct MediaSourceJsonRepr {
|
||||||
url: Option<OwnedMxcUri>,
|
url: Option<OwnedMxcUri>,
|
||||||
file: Option<Box<EncryptedFile>>,
|
file: Option<Box<EncryptedFile>>,
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ impl<'de> Deserialize<'de> for MessageType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/112615
|
||||||
#[cfg(feature = "unstable-msc3488")]
|
#[cfg(feature = "unstable-msc3488")]
|
||||||
pub(in super::super) mod msc3488 {
|
pub(in super::super) mod msc3488 {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -106,7 +106,7 @@ impl fmt::Display for FormattedOrPlainBody<'_> {
|
|||||||
///
|
///
|
||||||
/// [HTML tags and attributes]: https://spec.matrix.org/latest/client-server-api/#mroommessage-msgtypes
|
/// [HTML tags and attributes]: https://spec.matrix.org/latest/client-server-api/#mroommessage-msgtypes
|
||||||
/// [rich reply fallbacks]: https://spec.matrix.org/latest/client-server-api/#fallbacks-for-rich-replies
|
/// [rich reply fallbacks]: https://spec.matrix.org/latest/client-server-api/#fallbacks-for-rich-replies
|
||||||
pub fn plain_and_formatted_reply_body(
|
pub(crate) fn plain_and_formatted_reply_body(
|
||||||
body: &str,
|
body: &str,
|
||||||
formatted: Option<impl fmt::Display>,
|
formatted: Option<impl fmt::Display>,
|
||||||
original_message: &OriginalRoomMessageEvent,
|
original_message: &OriginalRoomMessageEvent,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Convenience methods and types to sanitize text messages.
|
//! Convenience methods and types to sanitize text messages.
|
||||||
|
|
||||||
|
#![allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/112615
|
||||||
|
|
||||||
#[cfg(feature = "unstable-sanitize")]
|
#[cfg(feature = "unstable-sanitize")]
|
||||||
mod html_fragment;
|
mod html_fragment;
|
||||||
#[cfg(feature = "unstable-sanitize")]
|
#[cfg(feature = "unstable-sanitize")]
|
||||||
|
@ -10,7 +10,7 @@ use crate::OwnedMxcUri;
|
|||||||
use super::{EncryptedFile, MediaSource};
|
use super::{EncryptedFile, MediaSource};
|
||||||
|
|
||||||
/// Serializes a MediaSource to a thumbnail source.
|
/// Serializes a MediaSource to a thumbnail source.
|
||||||
pub fn serialize<S>(source: &Option<MediaSource>, serializer: S) -> Result<S::Ok, S::Error>
|
pub(crate) fn serialize<S>(source: &Option<MediaSource>, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
@ -27,12 +27,12 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deserializes a thumbnail source to a MediaSource.
|
/// Deserializes a thumbnail source to a MediaSource.
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<MediaSource>, D::Error>
|
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<Option<MediaSource>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct ThumbnailSourceJsonRepr {
|
struct ThumbnailSourceJsonRepr {
|
||||||
thumbnail_url: Option<OwnedMxcUri>,
|
thumbnail_url: Option<OwnedMxcUri>,
|
||||||
thumbnail_file: Option<Box<EncryptedFile>>,
|
thumbnail_file: Option<Box<EncryptedFile>>,
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![cfg(feature = "api")]
|
#![cfg(feature = "api")]
|
||||||
|
#![allow(unreachable_pub)]
|
||||||
|
|
||||||
mod conversions;
|
mod conversions;
|
||||||
mod header_override;
|
mod header_override;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//! Modules for custom serde de/-serialization implementations.
|
//! Modules for custom serde de/-serialization implementations.
|
||||||
|
|
||||||
pub mod pdu_process_response;
|
pub(crate) mod pdu_process_response;
|
||||||
pub mod v1_pdu;
|
pub(crate) mod v1_pdu;
|
||||||
|
@ -13,7 +13,7 @@ struct WrappedError {
|
|||||||
error: Option<String>,
|
error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize<S>(
|
pub(crate) fn serialize<S>(
|
||||||
response: &BTreeMap<OwnedEventId, Result<(), String>>,
|
response: &BTreeMap<OwnedEventId, Result<(), String>>,
|
||||||
serializer: S,
|
serializer: S,
|
||||||
) -> Result<S::Ok, S::Error>
|
) -> Result<S::Ok, S::Error>
|
||||||
@ -34,7 +34,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub fn deserialize<'de, D>(
|
pub(crate) fn deserialize<'de, D>(
|
||||||
deserializer: D,
|
deserializer: D,
|
||||||
) -> Result<BTreeMap<OwnedEventId, Result<(), String>>, D::Error>
|
) -> Result<BTreeMap<OwnedEventId, Result<(), String>>, D::Error>
|
||||||
where
|
where
|
||||||
|
@ -15,7 +15,7 @@ use serde::{
|
|||||||
ser::{Serialize, SerializeSeq, Serializer},
|
ser::{Serialize, SerializeSeq, Serializer},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn serialize<T, S>(val: &T, serializer: S) -> Result<S::Ok, S::Error>
|
pub(crate) fn serialize<T, S>(val: &T, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
@ -26,7 +26,7 @@ where
|
|||||||
seq.end()
|
seq.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error>
|
pub(crate) fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
T: Deserialize<'de>,
|
T: Deserialize<'de>,
|
||||||
|
@ -10,7 +10,7 @@ use super::{
|
|||||||
attribute::{DeriveRequestMeta, RequestMeta},
|
attribute::{DeriveRequestMeta, RequestMeta},
|
||||||
ensure_feature_presence,
|
ensure_feature_presence,
|
||||||
};
|
};
|
||||||
use crate::util::import_ruma_common;
|
use crate::util::{import_ruma_common, PrivateField};
|
||||||
|
|
||||||
mod incoming;
|
mod incoming;
|
||||||
mod outgoing;
|
mod outgoing;
|
||||||
@ -147,7 +147,8 @@ impl Request {
|
|||||||
|
|
||||||
let request_body_struct = self.has_body_fields().then(|| {
|
let request_body_struct = self.has_body_fields().then(|| {
|
||||||
let serde_attr = self.has_newtype_body().then(|| quote! { #[serde(transparent)] });
|
let serde_attr = self.has_newtype_body().then(|| quote! { #[serde(transparent)] });
|
||||||
let fields = self.fields.iter().filter_map(RequestField::as_body_field);
|
let fields =
|
||||||
|
self.fields.iter().filter_map(RequestField::as_body_field).map(PrivateField);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
/// Data in the request body.
|
/// Data in the request body.
|
||||||
@ -162,9 +163,11 @@ impl Request {
|
|||||||
|
|
||||||
let request_query_def = if let Some(f) = self.query_map_field() {
|
let request_query_def = if let Some(f) = self.query_map_field() {
|
||||||
let field = Field { ident: None, colon_token: None, ..f.clone() };
|
let field = Field { ident: None, colon_token: None, ..f.clone() };
|
||||||
|
let field = PrivateField(&field);
|
||||||
Some(quote! { (#field); })
|
Some(quote! { (#field); })
|
||||||
} else if self.has_query_fields() {
|
} else if self.has_query_fields() {
|
||||||
let fields = self.fields.iter().filter_map(RequestField::as_query_field);
|
let fields =
|
||||||
|
self.fields.iter().filter_map(RequestField::as_query_field).map(PrivateField);
|
||||||
Some(quote! { { #(#fields),* } })
|
Some(quote! { { #(#fields),* } })
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -13,7 +13,7 @@ use super::{
|
|||||||
attribute::{DeriveResponseMeta, ResponseMeta},
|
attribute::{DeriveResponseMeta, ResponseMeta},
|
||||||
ensure_feature_presence,
|
ensure_feature_presence,
|
||||||
};
|
};
|
||||||
use crate::util::import_ruma_common;
|
use crate::util::{import_ruma_common, PrivateField};
|
||||||
|
|
||||||
mod incoming;
|
mod incoming;
|
||||||
mod outgoing;
|
mod outgoing;
|
||||||
@ -132,7 +132,8 @@ impl Response {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let serde_attr = self.has_newtype_body().then(|| quote! { #[serde(transparent)] });
|
let serde_attr = self.has_newtype_body().then(|| quote! { #[serde(transparent)] });
|
||||||
let fields = self.fields.iter().filter_map(ResponseField::as_body_field);
|
let fields =
|
||||||
|
self.fields.iter().filter_map(ResponseField::as_body_field).map(PrivateField);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
/// Data in the response body.
|
/// Data in the response body.
|
||||||
|
@ -12,7 +12,7 @@ use syn::{
|
|||||||
DeriveInput, Field, Ident, LitStr, Meta, Token, Type,
|
DeriveInput, Field, Ident, LitStr, Meta, Token, Type,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::util::m_prefix_name_to_type_name;
|
use crate::util::{m_prefix_name_to_type_name, PrivateField};
|
||||||
|
|
||||||
use super::event_parse::{EventKind, EventKindVariation};
|
use super::event_parse::{EventKind, EventKindVariation};
|
||||||
|
|
||||||
@ -930,9 +930,10 @@ fn generate_event_content_impl<'a>(
|
|||||||
&& matches!(a.parse_args(), Ok(EventFieldMeta::TypeFragment))
|
&& matches!(a.parse_args(), Ok(EventFieldMeta::TypeFragment))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.map(PrivateField)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let fields_ident_without_type_fragment =
|
let fields_ident_without_type_fragment =
|
||||||
fields_without_type_fragment.iter().filter_map(|f| f.ident.as_ref());
|
fields_without_type_fragment.iter().filter_map(|f| f.0.ident.as_ref());
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #ruma_common::events::EventContentFromType for #ident {
|
impl #ruma_common::events::EventContentFromType for #ident {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
//! See the documentation for the individual macros for usage details.
|
//! See the documentation for the individual macros for usage details.
|
||||||
|
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
#![allow(unreachable_pub)]
|
||||||
// https://github.com/rust-lang/rust-clippy/issues/9029
|
// https://github.com/rust-lang/rust-clippy/issues/9029
|
||||||
#![allow(clippy::derive_partial_eq_without_eq)]
|
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use proc_macro_crate::{crate_name, FoundCrate};
|
use proc_macro_crate::{crate_name, FoundCrate};
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote, ToTokens};
|
||||||
use syn::{Ident, LitStr};
|
use syn::{Field, Ident, LitStr};
|
||||||
|
|
||||||
pub(crate) fn import_ruma_common() -> TokenStream {
|
pub(crate) fn import_ruma_common() -> TokenStream {
|
||||||
if let Ok(FoundCrate::Name(name)) = crate_name("ruma-common") {
|
if let Ok(FoundCrate::Name(name)) = crate_name("ruma-common") {
|
||||||
@ -55,3 +55,21 @@ pub(crate) fn m_prefix_name_to_type_name(name: &LitStr) -> syn::Result<Ident> {
|
|||||||
|
|
||||||
Ok(Ident::new(&s, span))
|
Ok(Ident::new(&s, span))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wrapper around [`syn::Field`] that emits the field without its visibility,
|
||||||
|
/// thus making it private.
|
||||||
|
pub struct PrivateField<'a>(pub &'a Field);
|
||||||
|
|
||||||
|
impl ToTokens for PrivateField<'_> {
|
||||||
|
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||||
|
let Field { attrs, vis: _, mutability, ident, colon_token, ty } = self.0;
|
||||||
|
assert_eq!(*mutability, syn::FieldMutability::None);
|
||||||
|
|
||||||
|
for attr in attrs {
|
||||||
|
attr.to_tokens(tokens);
|
||||||
|
}
|
||||||
|
ident.to_tokens(tokens);
|
||||||
|
colon_token.to_tokens(tokens);
|
||||||
|
ty.to_tokens(tokens);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -305,7 +305,7 @@ pub mod v1 {
|
|||||||
Deserializer, Serializer,
|
Deserializer, Serializer,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn serialize<S>(tweak: &[Tweak], serializer: S) -> Result<S::Ok, S::Error>
|
pub(super) fn serialize<S>(tweak: &[Tweak], serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
@ -364,7 +364,7 @@ pub mod v1 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<Tweak>, D::Error>
|
pub(super) fn deserialize<'de, D>(deserializer: D) -> Result<Vec<Tweak>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,7 @@ pub trait KeyPair: Sized {
|
|||||||
fn sign(&self, message: &[u8]) -> Signature;
|
fn sign(&self, message: &[u8]) -> Signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ED25519_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.101.112");
|
const ED25519_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.101.112");
|
||||||
|
|
||||||
/// An Ed25519 key pair.
|
/// An Ed25519 key pair.
|
||||||
pub struct Ed25519KeyPair {
|
pub struct Ed25519KeyPair {
|
||||||
|
@ -5,7 +5,7 @@ use ed25519_dalek::{PublicKey, Verifier as _};
|
|||||||
use crate::{Error, ParseError, VerificationError};
|
use crate::{Error, ParseError, VerificationError};
|
||||||
|
|
||||||
/// A digital signature verifier.
|
/// A digital signature verifier.
|
||||||
pub trait Verifier {
|
pub(crate) trait Verifier {
|
||||||
/// Use a public key to verify a signature against the JSON object that was signed.
|
/// Use a public key to verify a signature against the JSON object that was signed.
|
||||||
///
|
///
|
||||||
/// # Parameters
|
/// # Parameters
|
||||||
@ -23,7 +23,7 @@ pub trait Verifier {
|
|||||||
|
|
||||||
/// A verifier for Ed25519 digital signatures.
|
/// A verifier for Ed25519 digital signatures.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Ed25519Verifier;
|
pub(crate) struct Ed25519Verifier;
|
||||||
|
|
||||||
impl Verifier for Ed25519Verifier {
|
impl Verifier for Ed25519Verifier {
|
||||||
fn verify_json(
|
fn verify_json(
|
||||||
|
@ -16,34 +16,34 @@ use crate::RoomVersion;
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct IntRoomPowerLevelsEventContent {
|
struct IntRoomPowerLevelsEventContent {
|
||||||
#[serde(default = "default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub ban: Int,
|
ban: Int,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub events: BTreeMap<TimelineEventType, Int>,
|
events: BTreeMap<TimelineEventType, Int>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub events_default: Int,
|
events_default: Int,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub invite: Int,
|
invite: Int,
|
||||||
|
|
||||||
#[serde(default = "default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub kick: Int,
|
kick: Int,
|
||||||
|
|
||||||
#[serde(default = "default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub redact: Int,
|
redact: Int,
|
||||||
|
|
||||||
#[serde(default = "default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub state_default: Int,
|
state_default: Int,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub users: BTreeMap<OwnedUserId, Int>,
|
users: BTreeMap<OwnedUserId, Int>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub users_default: Int,
|
users_default: Int,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub notifications: IntNotificationPowerLevels,
|
notifications: IntNotificationPowerLevels,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<IntRoomPowerLevelsEventContent> for RoomPowerLevelsEventContent {
|
impl From<IntRoomPowerLevelsEventContent> for RoomPowerLevelsEventContent {
|
||||||
@ -80,7 +80,7 @@ impl From<IntRoomPowerLevelsEventContent> for RoomPowerLevelsEventContent {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct IntNotificationPowerLevels {
|
struct IntNotificationPowerLevels {
|
||||||
#[serde(default = "default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub room: Int,
|
room: Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for IntNotificationPowerLevels {
|
impl Default for IntNotificationPowerLevels {
|
||||||
|
@ -29,11 +29,11 @@ use tracing::info;
|
|||||||
|
|
||||||
use crate::{auth_types_for_event, Error, Event, EventTypeExt, Result, StateMap};
|
use crate::{auth_types_for_event, Error, Event, EventTypeExt, Result, StateMap};
|
||||||
|
|
||||||
pub use event::PduEvent;
|
pub(crate) use event::PduEvent;
|
||||||
|
|
||||||
static SERVER_TIMESTAMP: AtomicU64 = AtomicU64::new(0);
|
static SERVER_TIMESTAMP: AtomicU64 = AtomicU64::new(0);
|
||||||
|
|
||||||
pub fn do_check(
|
pub(crate) fn do_check(
|
||||||
events: &[Arc<PduEvent>],
|
events: &[Arc<PduEvent>],
|
||||||
edges: Vec<Vec<OwnedEventId>>,
|
edges: Vec<Vec<OwnedEventId>>,
|
||||||
expected_state_ids: Vec<OwnedEventId>,
|
expected_state_ids: Vec<OwnedEventId>,
|
||||||
@ -206,10 +206,10 @@ pub fn do_check(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
pub struct TestStore<E: Event>(pub HashMap<OwnedEventId, Arc<E>>);
|
pub(crate) struct TestStore<E: Event>(pub(crate) HashMap<OwnedEventId, Arc<E>>);
|
||||||
|
|
||||||
impl<E: Event> TestStore<E> {
|
impl<E: Event> TestStore<E> {
|
||||||
pub fn get_event(&self, _: &RoomId, event_id: &EventId) -> Result<Arc<E>> {
|
pub(crate) fn get_event(&self, _: &RoomId, event_id: &EventId) -> Result<Arc<E>> {
|
||||||
self.0
|
self.0
|
||||||
.get(event_id)
|
.get(event_id)
|
||||||
.map(Arc::clone)
|
.map(Arc::clone)
|
||||||
@ -217,7 +217,7 @@ impl<E: Event> TestStore<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a Vec of the related auth events to the given `event`.
|
/// Returns a Vec of the related auth events to the given `event`.
|
||||||
pub fn auth_event_ids(
|
pub(crate) fn auth_event_ids(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_ids: Vec<E::Id>,
|
event_ids: Vec<E::Id>,
|
||||||
@ -245,7 +245,7 @@ impl<E: Event> TestStore<E> {
|
|||||||
// A StateStore implementation for testing
|
// A StateStore implementation for testing
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
impl TestStore<PduEvent> {
|
impl TestStore<PduEvent> {
|
||||||
pub fn set_up(
|
pub(crate) fn set_up(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> (StateMap<OwnedEventId>, StateMap<OwnedEventId>, StateMap<OwnedEventId>) {
|
) -> (StateMap<OwnedEventId>, StateMap<OwnedEventId>, StateMap<OwnedEventId>) {
|
||||||
let create_event = to_pdu_event::<&EventId>(
|
let create_event = to_pdu_event::<&EventId>(
|
||||||
@ -331,7 +331,7 @@ impl TestStore<PduEvent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn event_id(id: &str) -> OwnedEventId {
|
pub(crate) fn event_id(id: &str) -> OwnedEventId {
|
||||||
if id.contains('$') {
|
if id.contains('$') {
|
||||||
return id.try_into().unwrap();
|
return id.try_into().unwrap();
|
||||||
}
|
}
|
||||||
@ -339,39 +339,39 @@ pub fn event_id(id: &str) -> OwnedEventId {
|
|||||||
format!("${id}:foo").try_into().unwrap()
|
format!("${id}:foo").try_into().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn alice() -> &'static UserId {
|
pub(crate) fn alice() -> &'static UserId {
|
||||||
user_id!("@alice:foo")
|
user_id!("@alice:foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bob() -> &'static UserId {
|
pub(crate) fn bob() -> &'static UserId {
|
||||||
user_id!("@bob:foo")
|
user_id!("@bob:foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn charlie() -> &'static UserId {
|
pub(crate) fn charlie() -> &'static UserId {
|
||||||
user_id!("@charlie:foo")
|
user_id!("@charlie:foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ella() -> &'static UserId {
|
pub(crate) fn ella() -> &'static UserId {
|
||||||
user_id!("@ella:foo")
|
user_id!("@ella:foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn zara() -> &'static UserId {
|
pub(crate) fn zara() -> &'static UserId {
|
||||||
user_id!("@zara:foo")
|
user_id!("@zara:foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn room_id() -> &'static RoomId {
|
pub(crate) fn room_id() -> &'static RoomId {
|
||||||
room_id!("!test:foo")
|
room_id!("!test:foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn member_content_ban() -> Box<RawJsonValue> {
|
pub(crate) fn member_content_ban() -> Box<RawJsonValue> {
|
||||||
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Ban)).unwrap()
|
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Ban)).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn member_content_join() -> Box<RawJsonValue> {
|
pub(crate) fn member_content_join() -> Box<RawJsonValue> {
|
||||||
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Join)).unwrap()
|
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Join)).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_init_pdu_event(
|
pub(crate) fn to_init_pdu_event(
|
||||||
id: &str,
|
id: &str,
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
ev_type: TimelineEventType,
|
ev_type: TimelineEventType,
|
||||||
@ -402,7 +402,7 @@ pub fn to_init_pdu_event(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_pdu_event<S>(
|
pub(crate) fn to_pdu_event<S>(
|
||||||
id: &str,
|
id: &str,
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
ev_type: TimelineEventType,
|
ev_type: TimelineEventType,
|
||||||
@ -442,7 +442,7 @@ where
|
|||||||
|
|
||||||
// all graphs start with these input events
|
// all graphs start with these input events
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn INITIAL_EVENTS() -> HashMap<OwnedEventId, Arc<PduEvent>> {
|
pub(crate) fn INITIAL_EVENTS() -> HashMap<OwnedEventId, Arc<PduEvent>> {
|
||||||
vec![
|
vec![
|
||||||
to_pdu_event::<&EventId>(
|
to_pdu_event::<&EventId>(
|
||||||
"CREATE",
|
"CREATE",
|
||||||
@ -524,7 +524,7 @@ pub fn INITIAL_EVENTS() -> HashMap<OwnedEventId, Arc<PduEvent>> {
|
|||||||
|
|
||||||
// all graphs start with these input events
|
// all graphs start with these input events
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn INITIAL_EVENTS_CREATE_ROOM() -> HashMap<OwnedEventId, Arc<PduEvent>> {
|
pub(crate) fn INITIAL_EVENTS_CREATE_ROOM() -> HashMap<OwnedEventId, Arc<PduEvent>> {
|
||||||
vec![to_pdu_event::<&EventId>(
|
vec![to_pdu_event::<&EventId>(
|
||||||
"CREATE",
|
"CREATE",
|
||||||
alice(),
|
alice(),
|
||||||
@ -540,14 +540,14 @@ pub fn INITIAL_EVENTS_CREATE_ROOM() -> HashMap<OwnedEventId, Arc<PduEvent>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn INITIAL_EDGES() -> Vec<OwnedEventId> {
|
pub(crate) fn INITIAL_EDGES() -> Vec<OwnedEventId> {
|
||||||
vec!["START", "IMC", "IMB", "IJR", "IPOWER", "IMA", "CREATE"]
|
vec!["START", "IMC", "IMB", "IJR", "IPOWER", "IMA", "CREATE"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(event_id)
|
.map(event_id)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod event {
|
pub(crate) mod event {
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
events::{pdu::Pdu, TimelineEventType},
|
events::{pdu::Pdu, TimelineEventType},
|
||||||
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId,
|
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId,
|
||||||
@ -648,9 +648,9 @@ pub mod event {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
pub struct PduEvent {
|
pub(crate) struct PduEvent {
|
||||||
pub event_id: OwnedEventId,
|
pub(crate) event_id: OwnedEventId,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub rest: Pdu,
|
pub(crate) rest: Pdu,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
//! This binary is integrated into the `cargo` command line by using an alias in
|
//! This binary is integrated into the `cargo` command line by using an alias in
|
||||||
//! `.cargo/config`. Run commands as `cargo xtask [command]`.
|
//! `.cargo/config`. Run commands as `cargo xtask [command]`.
|
||||||
|
|
||||||
|
#![allow(unreachable_pub)]
|
||||||
#![allow(clippy::exhaustive_structs)]
|
#![allow(clippy::exhaustive_structs)]
|
||||||
// https://github.com/rust-lang/rust-clippy/issues/9029
|
// https://github.com/rust-lang/rust-clippy/issues/9029
|
||||||
#![allow(clippy::derive_partial_eq_without_eq)]
|
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user