Skip to content

Commit

Permalink
Replace Vec parameters by IntoIterator (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
François Triquet authored and Zeyla Hellyer committed Oct 9, 2017
1 parent 7cf1e52 commit b146501
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/builder/create_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl CreateEmbed {
}

/// Adds multiple fields at once.
pub fn fields(mut self, fields: Vec<CreateEmbedField>) -> Self {
pub fn fields<It: IntoIterator<Item=CreateEmbedField>>(mut self, fields: It) -> Self {
let fields = fields
.into_iter()
.map(|m| Value::Object(m.0))
Expand Down
2 changes: 1 addition & 1 deletion src/builder/create_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl CreateMessage {
}

/// Adds a list of reactions to create after the message's sent.
pub fn reactions<R: Into<ReactionType>>(mut self, reactions: Vec<R>) -> Self {
pub fn reactions<R: Into<ReactionType>, It: IntoIterator<Item=R>>(mut self, reactions: It) -> Self {
self.1 = Some(reactions.into_iter().map(|r| r.into()).collect());

CreateMessage(self.0, self.1)
Expand Down
6 changes: 3 additions & 3 deletions src/framework/standard/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ impl Configuration {
/// client.with_framework(StandardFramework::new().configure(|c| c
/// .prefixes(vec!["!", ">", "+"])));
/// ```
pub fn prefixes(mut self, prefixes: Vec<&str>) -> Self {
self.prefixes = prefixes.iter().map(|x| x.to_string()).collect();
pub fn prefixes<T: ToString, It: IntoIterator<Item=T>>(mut self, prefixes: It) -> Self {
self.prefixes = prefixes.into_iter().map(|x| x.to_string()).collect();

self
}
Expand Down Expand Up @@ -401,7 +401,7 @@ impl Configuration {
/// client.with_framework(StandardFramework::new().configure(|c| c
/// .delimiters(vec![", ", " "])));
/// ```
pub fn delimiters(mut self, delimiters: Vec<&str>) -> Self {
pub fn delimiters<T: ToString, It: IntoIterator<Item=T>>(mut self, delimiters: It) -> Self {
self.delimiters.clear();
self.delimiters
.extend(delimiters.into_iter().map(|s| s.to_string()));
Expand Down
6 changes: 3 additions & 3 deletions src/framework/standard/create_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct CreateCommand(pub Command);

impl CreateCommand {
/// Adds multiple aliases.
pub fn batch_known_as(mut self, names: Vec<&str>) -> Self {
pub fn batch_known_as<T: ToString, It: IntoIterator<Item=T>>(mut self, names: It) -> Self {
self.0
.aliases
.extend(names.into_iter().map(|n| n.to_string()));
Expand Down Expand Up @@ -208,8 +208,8 @@ impl CreateCommand {
}

/// Sets roles that are allowed to use the command.
pub fn allowed_roles(mut self, allowed_roles: Vec<&str>) -> Self {
self.0.allowed_roles = allowed_roles.iter().map(|x| x.to_string()).collect();
pub fn allowed_roles<T: ToString, It: IntoIterator<Item=T>>(mut self, allowed_roles: It) -> Self {
self.0.allowed_roles = allowed_roles.into_iter().map(|x| x.to_string()).collect();

self
}
Expand Down
4 changes: 2 additions & 2 deletions src/framework/standard/create_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl CreateGroup {
}

/// Sets roles that are allowed to use the command.
pub fn allowed_roles(mut self, allowed_roles: Vec<&str>) -> Self {
self.0.allowed_roles = allowed_roles.iter().map(|x| x.to_string()).collect();
pub fn allowed_roles<T: ToString, It: IntoIterator<Item=T>>(mut self, allowed_roles: It) -> Self {
self.0.allowed_roles = allowed_roles.into_iter().map(|x| x.to_string()).collect();

self
}
Expand Down
4 changes: 2 additions & 2 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ pub fn remove_group_recipient(group_id: u64, user_id: u64) -> Result<()> {
/// if the file is too large to send.
///
/// [`HttpError::InvalidRequest`]: enum.HttpError.html#variant.InvalidRequest
pub fn send_files<'a, T>(channel_id: u64, files: Vec<T>, map: JsonMap) -> Result<Message>
pub fn send_files<'a, T, It: IntoIterator<Item=T>>(channel_id: u64, files: It, map: JsonMap) -> Result<Message>
where T: Into<AttachmentType<'a>> {
let uri = format!(api!("/channels/{}/messages"), channel_id);
let url = match Url::parse(&uri) {
Expand All @@ -1632,7 +1632,7 @@ pub fn send_files<'a, T>(channel_id: u64, files: Vec<T>, map: JsonMap) -> Result
let mut request = Multipart::from_request(request)?;
let mut file_num = "0".to_string();

for file in files {
for file in files.into_iter() {
match file.into() {
AttachmentType::Bytes((mut bytes, filename)) => {
request
Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl ChannelId {
/// [`GuildChannel`]: struct.GuildChannel.html
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_files<'a, F, T>(&self, files: Vec<T>, f: F) -> Result<Message>
pub fn send_files<'a, F, T, It: IntoIterator<Item=T>>(&self, files: It, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, T: Into<AttachmentType<'a>> {
let mut map = f(CreateMessage::default()).0;

Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl Group {
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn send_files<'a, F, T>(&self, files: Vec<T>, f: F) -> Result<Message>
pub fn send_files<'a, F, T, It: IntoIterator<Item=T>>(&self, files: It, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, T: Into<AttachmentType<'a>> {
self.channel_id.send_files(files, f)
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl GuildChannel {
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn send_files<'a, F, T>(&self, files: Vec<T>, f: F) -> Result<Message>
pub fn send_files<'a, F, T, It: IntoIterator<Item=T>>(&self, files: It, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, T: Into<AttachmentType<'a>> {
self.id.send_files(files, f)
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Channel {
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[cfg(feature = "model")]
#[inline]
pub fn send_files<'a, F, T>(&self, files: Vec<T>, f: F) -> Result<Message>
pub fn send_files<'a, F, T, It: IntoIterator<Item=T>>(&self, files: It, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, T: Into<AttachmentType<'a>> {
self.id().send_files(files, f)
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/private_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl PrivateChannel {
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn send_files<'a, F, T>(&self, files: Vec<T>, f: F) -> Result<Message>
pub fn send_files<'a, F, T, It: IntoIterator<Item=T>>(&self, files: It, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, T: Into<AttachmentType<'a>> {
self.id.send_files(files, f)
}
Expand Down

0 comments on commit b146501

Please sign in to comment.