Skip to content

Implement IntoIterator for &QHash, &QList, &QMap, &QSet, and &QVector #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `QEventLoop` to cxx-qt-lib-extras.
- Add `QScopedMetaObjectConnectionGuard`, which is `QMetaObjectConnectionGuard` with a scoped lifetime. `QMetaObjectConnectionGuard` is now a type alias for `QScopedMetaObjectConnectionGuard<'static>`.
- Support for setting Qt log message patterns with `q_set_message_pattern` and formatting log messages ith `q_format_log_message`.
- Implement `IntoIterator` for `&QHash`, `&QList`, `&QMap`, `&QSet`, and `&QVector`.

### Removed

Expand Down
13 changes: 13 additions & 0 deletions crates/cxx-qt-lib/src/core/qhash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ where
}
}

impl<'a, T> IntoIterator for &'a QHash<T>
where
T: QHashPair,
{
type Item = (&'a T::Key, &'a T::Value);

type IntoIter = Iter<'a, T>;

fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

/// Trait implementation for a pair in a [`QHash`].
pub trait QHashPair: Sized {
type Key;
Expand Down
13 changes: 13 additions & 0 deletions crates/cxx-qt-lib/src/core/qlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,19 @@ where
}
}

impl<'a, T> IntoIterator for &'a QList<T>
where
T: QListElement,
{
type Item = &'a T;

type IntoIter = Iter<'a, T>;

fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

/// Trait implementation for an element in a [`QList`].
pub trait QListElement: Sized {
type TypeId;
Expand Down
13 changes: 13 additions & 0 deletions crates/cxx-qt-lib/src/core/qmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ where
}
}

impl<'a, T> IntoIterator for &'a QMap<T>
where
T: QMapPair,
{
type Item = (&'a T::Key, &'a T::Value);

type IntoIter = Iter<'a, T>;

fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

/// Trait implementation for a pair in a [`QMap`].
pub trait QMapPair: Sized {
type Key;
Expand Down
13 changes: 13 additions & 0 deletions crates/cxx-qt-lib/src/core/qset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ where
}
}

impl<'a, T> IntoIterator for &'a QSet<T>
where
T: QSetElement,
{
type Item = &'a T;

type IntoIter = Iter<'a, T>;

fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

/// Trait implementation for an element in a [`QSet`].
pub trait QSetElement: Sized {
type TypeId;
Expand Down
13 changes: 13 additions & 0 deletions crates/cxx-qt-lib/src/core/qvector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ where
}
}

impl<'a, T> IntoIterator for &'a QVector<T>
where
T: QVectorElement,
{
type Item = &'a T;

type IntoIter = Iter<'a, T>;

fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

/// Trait implementation for an element in a [`QVector`].
pub trait QVectorElement: Sized {
type TypeId;
Expand Down
Loading