Skip to content

Commit 30dda80

Browse files
committed
Wrap Config object in Arc.
1 parent 3900c3c commit 30dda80

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

src/authorizations/users.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub fn is_authorized(id: &str, config: &Config) -> bool {
1414
#[cfg(test)]
1515
mod tests {
1616
use super::*;
17-
use std::env;
1817

1918
fn test_config() -> Config {
2019
Config::new(

src/commands/heroku.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ struct HerokuApp {
1616

1717
#[command]
1818
pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult {
19-
let ctx_clone = ctx.clone();
20-
let data = ctx_clone.data.read();
21-
let config = data.get::<Config>().expect("Expected config");
19+
let config = ctx.data.read().get::<Config>().expect("Expected config").clone();
2220

2321
let response = heroku_client(&config.heroku_api_key)
2422
.get()

src/commands/ping.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ use crate::config::config::Config;
99
fn ping(ctx: &mut Context, msg: &Message) -> CommandResult {
1010
println!("running pong command");
1111

12-
let ctx_clone = ctx.clone();
13-
let data = ctx_clone.data.read();
14-
let config = data.get::<Config>().expect("Expected config");
12+
let config = ctx.data.read().get::<Config>().expect("Expected config").clone();
1513

16-
if is_authorized(&msg.author.id.to_string(), config) {
14+
if is_authorized(&msg.author.id.to_string(), &*config) {
1715
msg.reply(ctx, "Pong!")?;
1816
} else {
1917
msg.reply(

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod config {
2+
use std::sync::Arc;
23
use serenity::prelude::TypeMapKey;
34

45
#[derive(Debug)]
@@ -23,6 +24,6 @@ pub mod config {
2324
}
2425

2526
impl TypeMapKey for Config {
26-
type Value = Config;
27+
type Value = Arc<Config>;
2728
}
2829
}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use serenity::client::Client;
24
use serenity::framework::standard::{macros::group, StandardFramework};
35
use serenity::model::gateway::Ready;
@@ -32,7 +34,7 @@ pub fn run(config: Config) {
3234
// that is passed to each of the commands
3335
{
3436
let mut data = client.data.write();
35-
data.insert::<Config>(config);
37+
data.insert::<Config>(Arc::new(config));
3638
}
3739

3840
client.with_framework(

0 commit comments

Comments
 (0)