You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: mod.rs
    path of file: ./repos/smithay/src/wayland/viewporter
    
    the code of the file until where you have to start completion: //! Utilities for handling the `wp_viewporter` protocol
//!
//! ## How to use it
//!
//! ### Initialization
//!
//! To initialize this implementation, create [`ViewporterState`], store it in your `State` struct and
//! implement the required traits, as shown in this example:
//!
//! ```
//! use smithay::wayland::viewporter::ViewporterState;
//! use smithay::delegate_viewporter;
//!
//! # struct State;
//! # let mut display = wayland_server::Dis
    
pub fn ensure_viewport_valid(states: &SurfaceData, buffer_size: Size<i32, Logical>) -> bool {
    states
        .data_map
        .insert_if_missing(|| RefCell::new(Option::<ViewportMarker>::None));
    let viewport = states
        .data_map
        .get::<RefCell<Option<ViewportMarker>>>()
        .unwrap()
        .borrow();

    if let Some(viewport) = &*viewport {
        let state = states.cached_state.pending::<ViewportCachedState>();

        let buffer_rect = Rectangle::from_loc_and_size((0.0, 0.0), buffer_size.to_f64());
        let src = state.src.unwrap_or(buffer_rect);
        let valid = buffer_rect.contains_rect(src);
        if !valid {
            if let Ok(viewport) = viewport.0.upgrade() {
                viewport.post_error(
                    wp_viewport::Error::OutOfBuffer as u32,
                    "source rectangle extends outside of the content area".to_string(),
                );
            }
        }
        valid
    } else {
        true
    }
}