Skip to content

Commit

Permalink
Channel: Add items_owned() method
Browse files Browse the repository at this point in the history
This allows to consume the `Channel` and get the owned
vector/slice of `Items`. This can avoid the reallocation/clone
of the whole Items slice in situations where you need to pass
the owenership of the data, like when using futures.
  • Loading branch information
alatiera committed Apr 18, 2018
1 parent 129c597 commit b4a5ff5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,21 @@ impl Channel {
&mut self.items
}

/// Consume the `Channel` and return a Vector of owned `Item`s.
///
/// # Examples
///
/// ```
/// use rss::{Channel, Item};
///
/// let mut channel = Channel::default();
/// channel.set_items(vec![Item::default()]);
/// assert_eq!(channel.items_owned().len(), 1);
/// ```
pub fn items_owned(self) -> Vec<Item> {
self.items
}

/// Set the items in this channel.
///
/// # Examples
Expand Down

0 comments on commit b4a5ff5

Please sign in to comment.