Skip to content

Commit

Permalink
rename to lend_refs & lend_refs_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
ratmice committed Nov 26, 2023
1 parent 563c6fe commit e5f5a74
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use crate::LendingIterator;

/// A lending iterator that given an iterator, lends
/// references to the given iterator's items.
pub struct IntoLendingRefs<I: Iterator> {
pub struct LendRefs<I: Iterator> {
item: Option<I::Item>,
iter: I,
}

impl<I: Iterator> IntoLendingRefs<I> {
pub(crate) fn new(iter: I) -> IntoLendingRefs<I> {
IntoLendingRefs { item: None, iter }
impl<I: Iterator> LendRefs<I> {
pub(crate) fn new(iter: I) -> LendRefs<I> {
LendRefs { item: None, iter }
}
}

impl<I> LendingIterator for IntoLendingRefs<I>
impl<I> LendingIterator for LendRefs<I>
where
I: Iterator,
{
Expand Down Expand Up @@ -50,6 +50,6 @@ mod test {

fn test_helper() -> impl for<'a> LendingIterator<Item<'a> = &'a Foo> {
let w = W { x: Foo(0) };
std::iter::once(Foo(0)).into_lending_refs().chain(w)
std::iter::once(Foo(0)).lend_refs().chain(w)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use crate::LendingIterator;

/// A lending iterator that given an iterator, lends
/// mutable references to the given iterator's items.
pub struct IntoLendingRefsMut<I: Iterator> {
pub struct LendRefsMut<I: Iterator> {
item: Option<I::Item>,
iter: I,
}

impl<I: Iterator> IntoLendingRefsMut<I> {
pub(crate) fn new(iter: I) -> IntoLendingRefsMut<I> {
IntoLendingRefsMut { item: None, iter }
impl<I: Iterator> LendRefsMut<I> {
pub(crate) fn new(iter: I) -> LendRefsMut<I> {
LendRefsMut { item: None, iter }
}
}

impl<I: Iterator> LendingIterator for IntoLendingRefsMut<I> {
impl<I: Iterator> LendingIterator for LendRefsMut<I> {
type Item<'a> = &'a mut I::Item where Self: 'a;

fn next(&mut self) -> Option<Self::Item<'_>> {
Expand Down Expand Up @@ -51,6 +51,6 @@ mod test {

fn test_helper() -> impl for<'a> LendingIterator<Item<'a> = &'a mut Foo> {
let w = W { x: Foo(0) };
std::iter::once(Foo(0)).into_lending_refs_mut().chain(w)
std::iter::once(Foo(0)).lend_refs_mut().chain(w)
}
}
8 changes: 4 additions & 4 deletions src/to_lending/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod into_lending;
mod into_lending_refs;
mod into_lending_refs_mut;
mod lend_refs;
mod lend_refs_mut;
mod windows;
mod windows_mut;
pub use self::into_lending::IntoLending;
pub use self::into_lending_refs::IntoLendingRefs;
pub use self::into_lending_refs_mut::IntoLendingRefsMut;
pub use self::lend_refs::LendRefs;
pub use self::lend_refs_mut::LendRefsMut;
pub use self::windows::Windows;
pub use self::windows_mut::WindowsMut;
10 changes: 5 additions & 5 deletions src/traits/to_lending_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{IntoLending, IntoLendingRefs, IntoLendingRefsMut, Windows, WindowsMut};
use crate::{IntoLending, LendRefs, LendRefsMut, Windows, WindowsMut};

/// An extension trait for iterators that allows turning them into lending iterators (over windows of elements).
pub trait ToLendingIterator: IntoIterator {
Expand Down Expand Up @@ -38,20 +38,20 @@ pub trait ToLendingIterator: IntoIterator {

/// Turns this iterator into a lending iterator that lends references
/// to the iterator's items.
fn into_lending_refs(self) -> IntoLendingRefs<Self::IntoIter>
fn lend_refs(self) -> LendRefs<Self::IntoIter>
where
Self: Sized,
{
IntoLendingRefs::new(self.into_iter())
LendRefs::new(self.into_iter())
}

/// Turns this iterator into a lending iterator that lends mutable references
/// to the iterator's items.
fn into_lending_refs_mut(self) -> IntoLendingRefsMut<Self::IntoIter>
fn lend_refs_mut(self) -> LendRefsMut<Self::IntoIter>
where
Self: Sized,
{
IntoLendingRefsMut::new(self.into_iter())
LendRefsMut::new(self.into_iter())
}
}

Expand Down

0 comments on commit e5f5a74

Please sign in to comment.