From c8ef995bc053276190e731c5ffe9b41c2261b6ef Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 20 May 2023 21:13:59 +0200 Subject: [PATCH 1/2] feat: smaller binaries --- Cargo.toml | 7 +++++++ src/commands/bib.rs | 13 ++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 518d125..b41350e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,10 @@ diesel = { version = "2.0.4", features = ["sqlite", "returning_clauses_for_sqlit diesel_migrations = { version = "2.0.0", features = [ "sqlite" ] } # Force sqlite3 to be bundled, allowing for a fully static binary libsqlite3-sys = { version = "*", features = ["bundled"] } + +# https://stackoverflow.com/a/54842093 +[profile.release] +lto = true # Enable link-time optimization +codegen-units = 1 # Reduce number of codegen units to increase optimizations +panic = 'abort' # Abort on panic +strip = true # Strip symbols from binary* diff --git a/src/commands/bib.rs b/src/commands/bib.rs index 32fbbe2..01e7dab 100644 --- a/src/commands/bib.rs +++ b/src/commands/bib.rs @@ -48,8 +48,10 @@ fn resource_to_embed_field(resource: Resource) -> EmbedField { #[poise::command(prefix_command, slash_command)] pub async fn available(ctx: Context<'_>, date: HumanNaiveDate) -> Result<(), Error> { let client = &ctx.data().client; + let date: NaiveDate = date.into(); + let mut resources = client - .available(STERRE_BIB_ID, date.clone().into(), 1) + .available(STERRE_BIB_ID, date, 1) .await?; // Cloning here isn't super efficient, but this list only consists of a handful of elements so // it's fine @@ -59,7 +61,7 @@ pub async fn available(ctx: Context<'_>, date: HumanNaiveDate) -> Result<(), Err f.embed(|e| { e.description(format!( "Available booking dates for {}.", - Into::::into(date) + date )) .fields( resources @@ -91,6 +93,7 @@ pub async fn book( let guild_id = ctx.guild_id().unwrap(); let discord_id = ctx.author().id.0 as i64; + let date: NaiveDate = date.into(); let user = { let mut conn = ctx.data().pool.get()?; @@ -108,7 +111,7 @@ pub async fn book( let client = &ctx.data().client; let resources = client - .available(STERRE_BIB_ID, date.clone().into(), 1) + .available(STERRE_BIB_ID, date, 1) .await?; let chosen_resource = resources .iter() @@ -119,7 +122,7 @@ pub async fn book( let reservation = Reservation { auth_type: None, email: user.email.clone(), - date: date.clone().into(), + date, start_time, end_time, note: "coworking space".to_string(), @@ -136,7 +139,7 @@ pub async fn book( ctx.send(|f| { f.embed(|e| { e.description("A new reservation has been made.") - .field("when", format!("{} {} - {}", Into::::into(date), start_time.format(TIME_FORMAT), end_time.format(TIME_FORMAT)), false) + .field("when", format!("{} {} - {}", date, start_time.format(TIME_FORMAT), end_time.format(TIME_FORMAT)), false) .field("where", &chosen_resource.resource_name, false) .footer(|ft| ft.text( format!("A confirmation mail has been sent to {}. Please check your email and confirm your reservation within two hours.", user.email))) From fa24625a1f75c168bcb107ecab1fd14f27ddfcce Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 20 May 2023 21:17:01 +0200 Subject: [PATCH 2/2] chore: conform linting --- src/commands/bib.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/commands/bib.rs b/src/commands/bib.rs index 01e7dab..9f28cee 100644 --- a/src/commands/bib.rs +++ b/src/commands/bib.rs @@ -50,25 +50,20 @@ pub async fn available(ctx: Context<'_>, date: HumanNaiveDate) -> Result<(), Err let client = &ctx.data().client; let date: NaiveDate = date.into(); - let mut resources = client - .available(STERRE_BIB_ID, date, 1) - .await?; + let mut resources = client.available(STERRE_BIB_ID, date, 1).await?; // Cloning here isn't super efficient, but this list only consists of a handful of elements so // it's fine resources.sort_by_key(|k| k.resource_name.clone()); ctx.send(|f| { f.embed(|e| { - e.description(format!( - "Available booking dates for {}.", - date - )) - .fields( - resources - .into_iter() - .map(resource_to_embed_field) - .collect::>(), - ) + e.description(format!("Available booking dates for {}.", date)) + .fields( + resources + .into_iter() + .map(resource_to_embed_field) + .collect::>(), + ) }) }) .await?; @@ -110,9 +105,7 @@ pub async fn book( let user = user.unwrap(); let client = &ctx.data().client; - let resources = client - .available(STERRE_BIB_ID, date, 1) - .await?; + let resources = client.available(STERRE_BIB_ID, date, 1).await?; let chosen_resource = resources .iter() .filter(|r| capacity.is_none() || capacity.unwrap() <= r.capacity)