Skip to content

Commit 2f45c2f

Browse files
committed
convert remaining &str to Cow<str>
1 parent dcf8418 commit 2f45c2f

24 files changed

+84
-80
lines changed

src/helix/client/client_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a, C: crate::HttpClient<'a> + Sync> HelixClient<'a, C> {
141141
where
142142
T: TwitchToken + Send + Sync + ?Sized,
143143
{
144-
let req = helix::search::SearchCategoriesRequest::query(query).first(100);
144+
let req = helix::search::SearchCategoriesRequest::query(query.into()).first(100);
145145
make_stream(req, token, self, std::collections::VecDeque::from)
146146
}
147147

src/helix/endpoints/bits/get_bits_leaderboard.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct GetBitsLeaderboardRequest<'a> {
5858
/// * "all" – The lifetime of the broadcaster's channel. If this is specified (or used by default), started_at is ignored.
5959
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
6060
#[serde(borrow)]
61-
pub period: Option<&'a str>,
61+
pub period: Option<Cow<'a, str>>,
6262
/// Timestamp for the period over which the returned data is aggregated. Must be in RFC 3339 format. If this is not provided, data is aggregated over the current period; e.g., the current day/week/month/year. This value is ignored if period is "all".
6363
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
6464
#[serde(borrow)]
@@ -79,9 +79,9 @@ impl<'a> GetBitsLeaderboardRequest<'a> {
7979
}
8080

8181
/// Get loaderboard for this period. Valid values: `"day"`, `"week"`, `"month"`, `"year"`, `"all"`
82-
pub fn period(self, period: &'a str) -> Self {
82+
pub fn period(self, period: impl Into<Cow<'a, str>>) -> Self {
8383
Self {
84-
period: Some(period),
84+
period: Some(period.into()),
8585
..self
8686
}
8787
}

src/helix/endpoints/channels/modify_channel_information.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ pub struct ModifyChannelInformationBody<'a> {
8787
/// Language of the channel
8888
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
8989
#[serde(skip_serializing_if = "Option::is_none", borrow)]
90-
pub broadcaster_language: Option<&'a str>,
90+
pub broadcaster_language: Option<Cow<'a, str>>,
9191
/// Title of the stream. Value must not be an empty string.
9292
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
9393
#[serde(skip_serializing_if = "Option::is_none", borrow)]
94-
pub title: Option<&'a str>,
94+
pub title: Option<Cow<'a, str>>,
9595
}
9696

9797
impl<'a> ModifyChannelInformationBody<'a> {
@@ -116,13 +116,16 @@ impl<'a> ModifyChannelInformationBody<'a> {
116116
}
117117

118118
/// Language of the channel
119-
pub fn broadcaster_language(&mut self, broadcaster_language: impl Into<&'a str>) -> &mut Self {
119+
pub fn broadcaster_language(
120+
&mut self,
121+
broadcaster_language: impl Into<Cow<'a, str>>,
122+
) -> &mut Self {
120123
self.broadcaster_language = Some(broadcaster_language.into());
121124
self
122125
}
123126

124127
/// Title of the stream. Value must not be an empty string.
125-
pub fn title(&mut self, title: impl Into<&'a str>) -> &mut Self {
128+
pub fn title(&mut self, title: impl Into<Cow<'a, str>>) -> &mut Self {
126129
self.title = Some(title.into());
127130
self
128131
}
@@ -188,10 +191,8 @@ fn test_request() {
188191
use helix::*;
189192
let req = ModifyChannelInformationRequest::broadcaster_id("0");
190193

191-
let body = ModifyChannelInformationBody {
192-
title: Some("Hello World!"),
193-
..Default::default()
194-
};
194+
let mut body = ModifyChannelInformationBody::new();
195+
body.title("Hello World!");
195196

196197
dbg!(req.create_request(body, "token", "clientid").unwrap());
197198

src/helix/endpoints/chat/send_chat_announcement.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'a> SendChatAnnouncementRequest<'a> {
9191
pub struct SendChatAnnouncementBody<'a> {
9292
/// The announcement to make in the broadcaster’s chat room. Announcements are limited to a maximum of 500 characters; announcements longer than 500 characters are truncated.
9393
#[serde(borrow)]
94-
pub message: &'a str,
94+
pub message: Cow<'a, str>,
9595
// FIXME: Enumify?
9696
/// The color used to highlight the announcement. Possible case-sensitive values are:
9797
///
@@ -109,11 +109,11 @@ pub struct SendChatAnnouncementBody<'a> {
109109
impl<'a> SendChatAnnouncementBody<'a> {
110110
/// Create a new announcement with specified color
111111
pub fn new<E>(
112-
message: &'a str,
112+
message: impl Into<Cow<'a, str>>,
113113
color: impl std::convert::TryInto<AnnouncementColor, Error = E>,
114114
) -> Result<Self, E> {
115115
Ok(Self {
116-
message,
116+
message: message.into(),
117117
color: color.try_into()?,
118118
})
119119
}

src/helix/endpoints/goals/get_creator_goals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct GetCreatorGoalsRequest<'a> {
5656
/// Retreive a single event by event ID
5757
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
5858
#[serde(borrow)]
59-
pub id: Option<&'a str>,
59+
pub id: Option<Cow<'a, str>>,
6060
}
6161

6262
impl<'a> GetCreatorGoalsRequest<'a> {

src/helix/endpoints/hypetrain/get_hypetrain_events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct GetHypeTrainEventsRequest<'a> {
6161
)]
6262
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
6363
#[serde(borrow)]
64-
pub id: Option<&'a str>,
64+
pub id: Option<Cow<'a, str>>,
6565
}
6666

6767
impl<'a> GetHypeTrainEventsRequest<'a> {

src/helix/endpoints/moderation/add_blocked_term.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ pub struct AddBlockedTermBody<'a> {
9191
/// The term must contain a minimum of 2 characters and may contain up to a maximum of 500 characters.
9292
/// Terms can use a wildcard character (*). The wildcard character must appear at the beginning or end of a word, or set of characters. For example, *foo or foo*.
9393
#[serde(borrow)]
94-
pub text: &'a str,
94+
pub text: Cow<'a, str>,
9595
}
9696

9797
impl<'a> AddBlockedTermBody<'a> {
9898
/// Create a new [`AddBlockedTermBody`]
99-
pub fn new(text: &'a str) -> Self { Self { text } }
99+
pub fn new(text: impl Into<Cow<'a, str>>) -> Self { Self { text: text.into() } }
100100
}
101101

102102
impl helix::private::SealedSerialize for AddBlockedTermBody<'_> {}

src/helix/endpoints/moderation/ban_user.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub struct BanUserBody<'a> {
101101
/// The reason the user is being banned or put in a timeout. The text is user defined and limited to a maximum of 500 characters.
102102
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
103103
#[serde(borrow)]
104-
pub reason: &'a str,
104+
pub reason: Cow<'a, str>,
105105
/// The ID of the user to ban or put in a timeout.
106106
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
107107
#[serde(borrow)]
@@ -112,12 +112,12 @@ impl<'a> BanUserBody<'a> {
112112
/// Create a new [`BanUserBody`]
113113
pub fn new(
114114
user_id: impl types::IntoCow<'a, types::UserIdRef> + 'a,
115-
reason: &'a str,
115+
reason: impl Into<Cow<'a, str>>,
116116
duration: impl Into<Option<u32>>,
117117
) -> Self {
118118
Self {
119119
duration: duration.into(),
120-
reason,
120+
reason: reason.into(),
121121
user_id: user_id.to_cow(),
122122
}
123123
}

src/helix/endpoints/moderation/check_automod_status.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub struct CheckAutoModStatusBody<'a> {
8787
/// Message text.
8888
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
8989
#[serde(borrow)]
90-
pub msg_text: &'a str,
90+
pub msg_text: Cow<'a, str>,
9191
/// User ID of the sender.
9292
#[deprecated(since = "0.7.0", note = "user_id in automod check is no longer read")]
9393
#[cfg_attr(
@@ -100,10 +100,13 @@ pub struct CheckAutoModStatusBody<'a> {
100100

101101
impl<'a> CheckAutoModStatusBody<'a> {
102102
/// Create a new [`CheckAutoModStatusBody`]
103-
pub fn new(msg_id: impl types::IntoCow<'a, types::MsgIdRef> + 'a, msg_text: &'a str) -> Self {
103+
pub fn new(
104+
msg_id: impl types::IntoCow<'a, types::MsgIdRef> + 'a,
105+
msg_text: impl Into<Cow<'a, str>>,
106+
) -> Self {
104107
Self {
105108
msg_id: msg_id.to_cow(),
106-
msg_text,
109+
msg_text: msg_text.into(),
107110
user_id: None,
108111
}
109112
}

src/helix/endpoints/points/create_custom_rewards.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ pub struct CreateCustomRewardBody<'a> {
7979
/// The title of the reward
8080
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
8181
#[serde(borrow)]
82-
pub title: &'a str,
82+
pub title: Cow<'a, str>,
8383
/// The prompt for the viewer when they are redeeming the reward
8484
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
8585
#[serde(skip_serializing_if = "Option::is_none", borrow)]
86-
pub prompt: Option<&'a str>,
86+
pub prompt: Option<Cow<'a, str>>,
8787
/// The cost of the reward
8888
pub cost: usize,
8989
/// Is the reward currently enabled, if false the reward won’t show up to viewers. Defaults true
@@ -93,7 +93,7 @@ pub struct CreateCustomRewardBody<'a> {
9393
/// Custom background color for the reward. Format: Hex with # prefix. Example: #00E5CB.
9494
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
9595
#[serde(skip_serializing_if = "Option::is_none", borrow)]
96-
pub background_color: Option<&'a str>,
96+
pub background_color: Option<Cow<'a, str>>,
9797
/// Does the user need to enter information when redeeming the reward. Defaults false
9898
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
9999
#[serde(skip_serializing_if = "Option::is_none")]
@@ -131,9 +131,9 @@ pub struct CreateCustomRewardBody<'a> {
131131
impl<'a> CreateCustomRewardBody<'a> {
132132
// FIXME: need to add more here
133133
/// Reward to create with title.
134-
pub fn new(title: &'a str, cost: usize) -> Self {
134+
pub fn new(title: impl Into<Cow<'a, str>>, cost: usize) -> Self {
135135
Self {
136-
title,
136+
title: title.into(),
137137
prompt: Default::default(),
138138
cost,
139139
is_enabled: Default::default(),

0 commit comments

Comments
 (0)