ruwuma/crates/ruma-common/tests/events/ui/07-enum-sanity-check.rs
Kévin Commaille 1073530ac6 events: Add support for type aliases
Allow to use unstable types
2022-05-16 13:24:25 +02:00

42 lines
1.4 KiB
Rust

use ruma_common::events;
use ruma_macros::event_enum;
event_enum! {
/// Any global account data event.
enum GlobalAccountData {
#[ruma_enum(alias = "io.ruma.direct")]
"m.direct" => events::direct,
#[ruma_enum(alias = "m.identity_server")]
"io.ruma.identity_server" => events::identity_server,
#[cfg(test)]
"m.ignored_user_list" => events::ignored_user_list,
// Doesn't actually have a wildcard, but this should work as a wildcard test
"m.push_rules.*" => events::push_rules,
#[cfg(any())]
"m.ruma_test" => events::ruma_test,
}
}
fn main() {
assert_eq!(GlobalAccountDataEventType::from("m.direct"), GlobalAccountDataEventType::Direct);
assert_eq!(
GlobalAccountDataEventType::from("io.ruma.direct"),
GlobalAccountDataEventType::Direct
);
assert_eq!(GlobalAccountDataEventType::Direct.to_cow_str(), "m.direct");
assert_eq!(
GlobalAccountDataEventType::from("m.identity_server"),
GlobalAccountDataEventType::IdentityServer
);
assert_eq!(
GlobalAccountDataEventType::from("io.ruma.identity_server"),
GlobalAccountDataEventType::IdentityServer
);
assert_eq!(GlobalAccountDataEventType::IdentityServer.to_cow_str(), "io.ruma.identity_server");
}
#[doc(hidden)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PrivOwnedStr(Box<str>);