Skip to content

Commit b07ca11

Browse files
authored
Merge pull request #29 from rust-lang/better-args
Improve Args
2 parents 9fe1429 + c9a058a commit b07ca11

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/commands.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pub(crate) type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
77
pub(crate) type CmdPtr = for<'m> fn(Args<'m>) -> Result<()>;
88

99
pub struct Args<'m> {
10-
pub cx: Context,
11-
pub msg: Message,
10+
pub cx: &'m Context,
11+
pub msg: &'m Message,
1212
pub params: HashMap<&'m str, &'m str>,
1313
}
1414

@@ -59,13 +59,13 @@ impl Commands {
5959
}
6060

6161
pub(crate) fn execute<'m>(&'m self, cx: Context, msg: Message) {
62-
if !msg.is_own(&cx) && msg.content.starts_with(PREFIX) {
63-
let message = &msg.content.clone();
64-
self.state_machine.process(&message).map(|matched| {
62+
let message = &msg.content;
63+
if !msg.is_own(&cx) && message.starts_with(PREFIX) {
64+
self.state_machine.process(message).map(|matched| {
6565
info!("Executing command {}", message);
6666
let args = Args {
67-
cx,
68-
msg,
67+
cx: &cx,
68+
msg: &msg,
6969
params: matched.params,
7070
};
7171
if let Err(e) = (matched.handler)(args) {
@@ -98,7 +98,7 @@ fn add_dynamic_segment(state_machine: &mut StateMachine, mut state: usize) -> us
9898

9999
#[inline]
100100
fn add_remaining_segment(state_machine: &mut StateMachine, mut state: usize) -> usize {
101-
let mut char_set = CharacterSet::any();
101+
let char_set = CharacterSet::any();
102102
state = state_machine.add(state, char_set);
103103
state_machine.add_next_state(state, state);
104104
state_machine.start_parse(state);

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn ban(args: Args) -> Result {
165165

166166
if let Some(guild) = args.msg.guild(&args.cx) {
167167
info!("Banning user from guild");
168-
guild.read().ban(&args.cx, UserId::from(user_id), &"all")?
168+
guild.read().ban(args.cx, UserId::from(user_id), &"all")?
169169
}
170170
}
171171
Ok(())
@@ -223,7 +223,7 @@ fn welcome_message(args: Args) -> Result {
223223
})?;
224224

225225
let white_check_mark = ReactionType::from("✅");
226-
message.react(&args.cx, white_check_mark)?;
226+
message.react(args.cx, white_check_mark)?;
227227
}
228228
Ok(())
229229
}

src/tags.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub fn delete(args: Args) -> Result<()> {
1616
.ok_or("Unable to retrieve param: key")?;
1717

1818
match diesel::delete(tags::table.filter(tags::key.eq(key))).execute(&conn) {
19-
Ok(_) => args.msg.react(&args.cx, "✅")?,
20-
Err(_) => args.msg.react(&args.cx, "❌")?,
19+
Ok(_) => args.msg.react(args.cx, "✅")?,
20+
Err(_) => args.msg.react(args.cx, "❌")?,
2121
}
2222
Ok(())
2323
}
@@ -40,8 +40,8 @@ pub fn post(args: Args) -> Result<()> {
4040
.values((tags::key.eq(key), tags::value.eq(value)))
4141
.execute(&conn)
4242
{
43-
Ok(_) => args.msg.react(&args.cx, "✅")?,
44-
Err(_) => args.msg.react(&args.cx, "❌")?,
43+
Ok(_) => args.msg.react(args.cx, "✅")?,
44+
Err(_) => args.msg.react(args.cx, "❌")?,
4545
}
4646

4747
Ok(())

0 commit comments

Comments
 (0)