1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
use std::fmt;
use super::{
ChannelId,
Channel,
Emoji,
Member,
RoleId,
Role,
UserId,
User,
IncidentStatus
};
use ::internal::prelude::*;
pub trait Mentionable {
fn mention(&self) -> String;
}
impl Mentionable for ChannelId {
fn mention(&self) -> String {
format!("{}", self)
}
}
impl Mentionable for Channel {
fn mention(&self) -> String {
format!("{}", self)
}
}
impl Mentionable for Emoji {
fn mention(&self) -> String {
format!("{}", self)
}
}
impl Mentionable for Member {
fn mention(&self) -> String {
format!("{}", self.user)
}
}
impl Mentionable for RoleId {
fn mention(&self) -> String {
format!("{}", self)
}
}
impl Mentionable for Role {
fn mention(&self) -> String {
format!("{}", self)
}
}
impl Mentionable for UserId {
fn mention(&self) -> String {
format!("{}", self)
}
}
impl Mentionable for User {
fn mention(&self) -> String {
format!("{}", self)
}
}
/// A mention targeted at a certain model.
///
/// A mention can be created by calling `.mention()` on anything that is
/// mentionable - or an item's Id - and can be formatted into a string using
/// [`format!`]:
///
/// ```rust,ignore
/// let message = format!("Mentioning {}", user.mention());
/// ```
///
/// If a `String` is required, call `mention.to_string()`.
pub struct Mention {
pub prefix: &'static str,
pub id: u64,
}
impl fmt::Display for Mention {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(f.write_str(self.prefix));
try!(fmt::Display::fmt(&self.id, f));
fmt::Write::write_char(f, '>')
}
}
impl IncidentStatus {
#[doc(hidden)]
pub fn decode(value: Value) -> Result<Self> {
Self::decode_str(value)
}
}
|