Repository: servo/servo
File: ports/servoshell/running_app_state.rs (Rust)

Code before:
        self.webviews.clear();
        self.creation_order.clear();
        self.focused_webview_id = None;
    }

    /// Returns an iterator over all webview references (in arbitrary order).
    pub fn values(&self) -> impl Iterator<Item = &WebView> {
        self.webviews.values()
    }

    pub fn len(&self) -> usize {
        self.webviews.len()
    }

    /// Returns true if the collection contains no webviews.
    #[allow(dead_code)]
    pub fn is_empty(&self) -> bool {
        self.webviews.is_empty()
    }
}

impl Default for WebViewCollection {
    fn default() -> Self {
        Self::new()
    }
}

pub struct RunningAppStateBase {
    pub(crate) webview_collection: RefCell<WebViewCollection>,

    pub(crate) webdriver_senders: RefCell<WebDriverSenders>,

    /// A [`HashMap`] of pending WebDriver events. It is the WebDriver embedder's responsibility
    /// to inform the WebDriver server when the event has been fully handled. This map is used
    /// to report back to WebDriver when that happens.
    pub(crate) pending_webdriver_events: RefCell<HashMap<InputEventId, Sender<()>>>,

    /// A [`Receiver`] for receiving commands from a running WebDriver server, if WebDriver
    /// was enabled.
    pub(crate) webdriver_receiver: Option<Receiver<WebDriverCommandMsg>>,

    /// servoshell specific preferences created during startup of the application.
    pub(crate) servoshell_preferences: ServoShellPreferences,

    /// A handle to the Servo instance.
    pub(crate) servo: Servo,

    /// Whether or not the application has achieved stable image output. This is used
    /// for the `exit_after_stable_image` option.
    pub(crate) achieved_stable_image: Rc<Cell<bool>>,
}

Review comment (refactor):
You can remove this entirely as well as `WebViewCollection::new()` and simply implement `#[derive(Default)]` on the `WebViewCollection`.

Code after:
        self.webviews.values()
    }

    pub fn len(&self) -> usize {
        self.webviews.len()
    }

    /// Returns true if the collection contains no webviews.
    #[allow(dead_code)]
    pub fn is_empty(&self) -> bool {
        self.webviews.is_empty()
    }
}

pub struct RunningAppStateBase {
    pub(crate) webview_collection: RefCell<WebViewCollection>,

    pub(crate) webdriver_senders: RefCell<WebDriverSenders>,

    /// A [`HashMap`] of pending WebDriver events. It is the WebDriver embedder's responsibility
    /// to inform the WebDriver server when the event has been fully handled. This map is used
    /// to report back to WebDriver when that happens.
    pub(crate) pending_webdriver_events: RefCell<HashMap<InputEventId, Sender<()>>>,

    /// A [`Receiver`] for receiving commands from a running WebDriver server, if WebDriver
    /// was enabled.
    pub(crate) webdriver_receiver: Option<Receiver<WebDriverCommandMsg>>,

    /// servoshell specific preferences created during startup of the application.
    pub(crate) servoshell_preferences: ServoShellPreferences,

    /// A handle to the Servo instance.
    pub(crate) servo: Servo,

    /// Whether or not the application has achieved stable image output. This is used
    /// for the `exit_after_stable_image` option.
    pub(crate) achieved_stable_image: Rc<Cell<bool>>,
}

impl RunningAppStateBase {
    pub fn new(
        servoshell_preferences: ServoShellPreferences,
        servo: Servo,
        webdriver_receiver: Option<Receiver<WebDriverCommandMsg>>,
    ) -> Self {
        Self {
            webview_collection: RefCell::default(),
            webdriver_senders: RefCell::default(),
            pending_webdriver_events: Default::default(),
            webdriver_receiver,
            servoshell_preferences,