diff --git a/CHANGELOG.md b/CHANGELOG.md index b6d84a55..77ae2ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - On Wayland, fixed DeviceEvents for relative mouse movement is not always produced. - Removed `derivative` crate dependency. - On Wayland, add support for set_cursor_icon. +- Use `impl Iterator` instead of `AvailableMonitorsIter` consistently. # 0.20.0 Alpha 3 (2019-08-14) diff --git a/examples/monitor_list.rs b/examples/monitor_list.rs index 55a2dde8..a6b24d29 100644 --- a/examples/monitor_list.rs +++ b/examples/monitor_list.rs @@ -4,6 +4,6 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - dbg!(window.available_monitors()); + dbg!(window.available_monitors().collect::>()); dbg!(window.primary_monitor()); } diff --git a/src/event_loop.rs b/src/event_loop.rs index a2d90d3e..0b120573 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -11,11 +11,7 @@ //! [send_event]: ./struct.EventLoopProxy.html#method.send_event use std::{error, fmt, ops::Deref, time::Instant}; -use crate::{ - event::Event, - monitor::{AvailableMonitorsIter, MonitorHandle}, - platform_impl, -}; +use crate::{event::Event, monitor::MonitorHandle, platform_impl}; /// Provides a way to retrieve events from the system and from the windows that were registered to /// the events loop. @@ -150,10 +146,10 @@ impl EventLoop { /// Returns the list of all the monitors available on the system. #[inline] pub fn available_monitors(&self) -> impl Iterator { - let data = self.event_loop.available_monitors(); - AvailableMonitorsIter { - data: data.into_iter(), - } + self.event_loop + .available_monitors() + .into_iter() + .map(|inner| MonitorHandle { inner }) } /// Returns the primary monitor of the system. diff --git a/src/monitor.rs b/src/monitor.rs index 106c3e52..a8949020 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -1,51 +1,19 @@ //! Types useful for interacting with a user's monitors. //! //! If you want to get basic information about a monitor, you can use the [`MonitorHandle`][monitor_id] -//! type. This is retreived from an [`AvailableMonitorsIter`][monitor_iter], which can be acquired -//! with: +//! type. This is retreived from one of the following methods, which return an iterator of +//! [`MonitorHandle`][monitor_id]: //! - [`EventLoop::available_monitors`][loop_get] //! - [`Window::available_monitors`][window_get]. //! //! [monitor_id]: ./struct.MonitorHandle.html -//! [monitor_iter]: ./struct.AvailableMonitorsIter.html //! [loop_get]: ../event_loop/struct.EventLoop.html#method.available_monitors //! [window_get]: ../window/struct.Window.html#method.available_monitors -use std::collections::vec_deque::IntoIter as VecDequeIter; - use crate::{ dpi::{PhysicalPosition, PhysicalSize}, platform_impl, }; -/// An iterator over all available monitors. -/// -/// Can be acquired with: -/// - [`EventLoop::available_monitors`][loop_get] -/// - [`Window::available_monitors`][window_get]. -/// -/// [loop_get]: ../event_loop/struct.EventLoop.html#method.available_monitors -/// [window_get]: ../window/struct.Window.html#method.available_monitors -// Implementation note: we retrieve the list once, then serve each element by one by one. -// This may change in the future. -#[derive(Debug)] -pub struct AvailableMonitorsIter { - pub(crate) data: VecDequeIter, -} - -impl Iterator for AvailableMonitorsIter { - type Item = MonitorHandle; - - #[inline] - fn next(&mut self) -> Option { - self.data.next().map(|id| MonitorHandle { inner: id }) - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - self.data.size_hint() - } -} - /// Describes a fullscreen video mode of a monitor. /// /// Can be acquired with: diff --git a/src/window.rs b/src/window.rs index 248c8317..a74fab01 100644 --- a/src/window.rs +++ b/src/window.rs @@ -5,7 +5,7 @@ use crate::{ dpi::{LogicalPosition, LogicalSize}, error::{ExternalError, NotSupportedError, OsError}, event_loop::EventLoopWindowTarget, - monitor::{AvailableMonitorsIter, MonitorHandle, VideoMode}, + monitor::{MonitorHandle, VideoMode}, platform_impl, }; @@ -703,11 +703,11 @@ impl Window { /// /// **iOS:** Can only be called on the main thread. #[inline] - pub fn available_monitors(&self) -> AvailableMonitorsIter { - let data = self.window.available_monitors(); - AvailableMonitorsIter { - data: data.into_iter(), - } + pub fn available_monitors(&self) -> impl Iterator { + self.window + .available_monitors() + .into_iter() + .map(|inner| MonitorHandle { inner }) } /// Returns the primary monitor of the system.