File tree Expand file tree Collapse file tree 2 files changed +60
-2
lines changed Expand file tree Collapse file tree 2 files changed +60
-2
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ cfg_if::cfg_if! {
2929 pub use client:: Client ;
3030 pub use error:: { Error , Result } ;
3131 pub use snowflake:: Snowflake ; // for doc purposes
32+
33+ #[ doc( inline) ]
34+ pub use widget:: WidgetType ;
3235 }
3336}
3437
Original file line number Diff line number Diff line change 11use crate :: Snowflake ;
22
3+ /// Widget type.
4+ #[ non_exhaustive]
5+ pub enum WidgetType {
6+ DiscordBot ,
7+ DiscordServer ,
8+ }
9+
10+ impl WidgetType {
11+ const fn as_path ( & self ) -> & ' static str {
12+ match self {
13+ Self :: DiscordBot => "discord/bot" ,
14+ Self :: DiscordServer => "discord/server" ,
15+ }
16+ }
17+ }
18+
319/// Generates a large widget URL.
420#[ inline( always) ]
5- pub fn large < I > ( id : I ) -> String
21+ pub fn large < I > ( ty : WidgetType , id : I ) -> String
22+ where
23+ I : Snowflake ,
24+ {
25+ crate :: client:: api!( "/widgets/large/{}/{}" , ty. as_path( ) , id. as_snowflake( ) )
26+ }
27+
28+ /// Generates a small widget URL for displaying votes.
29+ #[ inline( always) ]
30+ pub fn votes < I > ( ty : WidgetType , id : I ) -> String
31+ where
32+ I : Snowflake ,
33+ {
34+ crate :: client:: api!(
35+ "/widgets/small/votes/{}/{}" ,
36+ ty. as_path( ) ,
37+ id. as_snowflake( )
38+ )
39+ }
40+
41+ /// Generates a small widget URL for displaying an entity's owner.
42+ #[ inline( always) ]
43+ pub fn owner < I > ( ty : WidgetType , id : I ) -> String
44+ where
45+ I : Snowflake ,
46+ {
47+ crate :: client:: api!(
48+ "/widgets/small/owner/{}/{}" ,
49+ ty. as_path( ) ,
50+ id. as_snowflake( )
51+ )
52+ }
53+
54+ /// Generates a small widget URL for displaying social stats.
55+ #[ inline( always) ]
56+ pub fn social < I > ( ty : WidgetType , id : I ) -> String
657where
758 I : Snowflake ,
859{
9- crate :: client:: api!( "/widgets/large/{}" , id. as_snowflake( ) )
60+ crate :: client:: api!(
61+ "/widgets/small/social/{}/{}" ,
62+ ty. as_path( ) ,
63+ id. as_snowflake( )
64+ )
1065}
You can’t perform that action at this time.
0 commit comments