aboutsummaryrefslogtreecommitdiff
path: root/src/message.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-03-23 07:39:41 +0000
committerAkshay <[email protected]>2021-03-23 07:39:41 +0000
commit0ecfaf7b7cf762590d5ba92f57567901c02af15b (patch)
treeef008b50fe6219a66fe91b4735dab6d952f2a3bd /src/message.rs
parente2c2cc460052191439abec62c465f0a4430b5b8a (diff)
implement message display and types
Diffstat (limited to 'src/message.rs')
-rw-r--r--src/message.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/message.rs b/src/message.rs
new file mode 100644
index 0000000..d1032cf
--- /dev/null
+++ b/src/message.rs
@@ -0,0 +1,42 @@
1#[derive(Debug)]
2pub struct Message {
3 pub text: String,
4 pub kind: MessageKind,
5}
6
7impl Message {
8 pub fn new() -> Self {
9 Self {
10 text: String::new(),
11 kind: MessageKind::Info,
12 }
13 }
14 pub fn kind(mut self, kind: MessageKind) -> Self {
15 self.kind = kind;
16 self
17 }
18 pub fn text<S: AsRef<str>>(mut self, text: S) -> Self {
19 self.text = text.as_ref().into();
20 self
21 }
22}
23
24#[derive(Debug, Copy, Clone)]
25pub enum MessageKind {
26 Error,
27 Info,
28 Hint,
29 LispResult,
30}
31
32impl<T> From<T> for Message
33where
34 T: AsRef<str>,
35{
36 fn from(item: T) -> Self {
37 return Message {
38 text: item.as_ref().into(),
39 kind: MessageKind::Info,
40 };
41 }
42}