Skip to content

Commit e801f3a

Browse files
authored
Improve usage of FixedString (#3418)
1 parent 8d51244 commit e801f3a

File tree

7 files changed

+21
-25
lines changed

7 files changed

+21
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ base64 = { version = "0.22.0" }
4141
zeroize = { version = "1.7" } # Not used in serenity, but bumps the minimal version from secrecy
4242
arrayvec = { version = "0.7.4", features = ["serde"] }
4343
serde_cow = { version = "0.1.0" }
44-
small-fixed-array = { version = "0.4", features = ["serde"] }
44+
small-fixed-array = { version = "0.4.10", features = ["serde"] }
4545
bool_to_bitflags = { version = "0.1.2" }
4646
nonmax = { version = "0.5.5", features = ["serde"] }
4747
strum = { version = "0.26", features = ["derive"] }
@@ -154,4 +154,3 @@ native_tls_backend = [
154154
[package.metadata.docs.rs]
155155
features = ["full"]
156156
rustdoc-args = ["--cfg", "docsrs"]
157-

src/builder/create_embed.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
1717
use std::borrow::Cow;
1818

19-
#[cfg(feature = "http")]
20-
use crate::internal::prelude::*;
2119
use crate::model::prelude::*;
2220

2321
/// A builder to create an embed in a message
@@ -247,16 +245,16 @@ impl From<Embed> for CreateEmbed<'_> {
247245
fn from(embed: Embed) -> Self {
248246
Self {
249247
fields: embed.fields.into_iter().map(Into::into).collect(),
250-
description: embed.description.map(FixedString::into_string).map(Into::into),
248+
description: embed.description.map(Into::into),
251249
thumbnail: embed.thumbnail.map(Into::into),
252250
timestamp: embed.timestamp,
253251
kind: Some("rich"),
254252
author: embed.author.map(Into::into),
255253
colour: embed.colour,
256254
footer: embed.footer.map(Into::into),
257255
image: embed.image.map(Into::into),
258-
title: embed.title.map(FixedString::into_string).map(Into::into),
259-
url: embed.url.map(FixedString::into_string).map(Into::into),
256+
title: embed.title.map(Into::into),
257+
url: embed.url.map(Into::into),
260258
}
261259
}
262260
}
@@ -302,9 +300,9 @@ impl<'a> CreateEmbedAuthor<'a> {
302300
impl From<EmbedAuthor> for CreateEmbedAuthor<'_> {
303301
fn from(author: EmbedAuthor) -> Self {
304302
Self {
305-
name: author.name.into_string().into(),
306-
url: author.url.map(|f| f.into_string().into()),
307-
icon_url: author.icon_url.map(|f| f.into_string().into()),
303+
name: author.name.into(),
304+
url: author.url.map(Into::into),
305+
icon_url: author.icon_url.map(Into::into),
308306
}
309307
}
310308
}
@@ -360,8 +358,8 @@ impl<'a> CreateEmbedFooter<'a> {
360358
impl From<EmbedFooter> for CreateEmbedFooter<'_> {
361359
fn from(footer: EmbedFooter) -> Self {
362360
Self {
363-
text: footer.text.into_string().into(),
364-
icon_url: footer.icon_url.map(|f| f.into_string().into()),
361+
text: footer.text.into(),
362+
icon_url: footer.icon_url.map(Into::into),
365363
}
366364
}
367365
}
@@ -386,8 +384,8 @@ impl<'a> From<&'a EmbedField> for CreateEmbedField<'a> {
386384
impl From<EmbedField> for CreateEmbedField<'_> {
387385
fn from(field: EmbedField) -> Self {
388386
Self {
389-
name: field.name.into_string().into(),
390-
value: field.value.into_string().into(),
387+
name: field.name.into(),
388+
value: field.value.into(),
391389
inline: field.inline,
392390
}
393391
}
@@ -401,15 +399,15 @@ struct CreateEmbedImage<'a> {
401399
impl From<EmbedImage> for CreateEmbedImage<'_> {
402400
fn from(field: EmbedImage) -> Self {
403401
Self {
404-
url: field.url.into_string().into(),
402+
url: field.url.into(),
405403
}
406404
}
407405
}
408406

409407
impl From<EmbedThumbnail> for CreateEmbedImage<'_> {
410408
fn from(field: EmbedThumbnail) -> Self {
411409
Self {
412-
url: field.url.into_string().into(),
410+
url: field.url.into(),
413411
}
414412
}
415413
}

src/builder/create_forum_tag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'a> CreateForumTag<'a> {
3939
},
4040
ReactionType::Unicode(unicode_emoji) => {
4141
self.emoji_id = None;
42-
self.emoji_name = Some(unicode_emoji.into_string().into());
42+
self.emoji_name = Some(unicode_emoji.into());
4343
},
4444
}
4545
self

src/gateway/client/dispatch.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use super::{Context, FullEvent};
66
use crate::cache::{Cache, CacheUpdate};
77
#[cfg(feature = "framework")]
88
use crate::framework::Framework;
9-
use crate::internal::prelude::*;
109
use crate::internal::tokio::spawn_named;
1110
use crate::model::channel::ChannelType;
1211
use crate::model::event::Event;
@@ -380,11 +379,11 @@ fn update_cache_with_event(
380379
}
381380
},
382381
Event::VoiceChannelStatusUpdate(mut event) => {
383-
let old = if_cache!(event.update(cache).map(FixedString::into_string));
382+
let old = if_cache!(event.update(cache).map(Into::into));
384383

385384
FullEvent::VoiceChannelStatusUpdate {
386385
old,
387-
status: event.status.map(FixedString::into_string),
386+
status: event.status.map(Into::into),
388387
id: event.id,
389388
guild_id: event.guild_id,
390389
}

src/gateway/sharding/shard_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ impl ShardManager {
202202
// We must wait 5 seconds between IDENTIFYs to avoid session invalidations.
203203
if let Some(instant) = self.last_start {
204204
let elapsed = instant.elapsed();
205-
if elapsed < self.wait_time_between_shard_start {
206-
sleep(self.wait_time_between_shard_start - elapsed).await;
205+
if let Some(duration) = self.wait_time_between_shard_start.checked_sub(elapsed) {
206+
sleep(duration).await;
207207
}
208208
}
209209

src/gateway/sharding/shard_queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub struct ShardQueue {
1313

1414
impl ShardQueue {
1515
pub fn new(max_concurrency: NonZeroU16) -> Self {
16-
let buckets = vec![VecDeque::new(); max_concurrency.get() as usize].into_boxed_slice();
17-
let buckets = FixedArray::try_from(buckets).expect("should fit without truncation");
16+
let buckets = vec![VecDeque::new(); max_concurrency.get() as usize];
17+
let buckets = buckets.try_into().expect("should fit without truncation");
1818

1919
Self {
2020
buckets,

src/model/channel/reaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl From<char> for ReactionType {
368368
/// # fn main() {}
369369
/// ```
370370
fn from(ch: char) -> ReactionType {
371-
ReactionType::Unicode(ch.to_string().trunc_into())
371+
ReactionType::Unicode(ch.into())
372372
}
373373
}
374374

0 commit comments

Comments
 (0)