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: stack_main.rs
    path of file: ./repos/persway/src/server/command_handlers/layout
    
    the code of the file until where you have to start completion: use crate::{node_ext::NodeExt, utils::get_focused_workspace};
use anyhow::Result;
use either::Either;
use swayipc_async::Connection;

pub struct StackMain {
    connection: Connection,
}

impl StackMain {
    pub async fn new() -> Result<Self> {
        let connection = Connection::new().await?;
        Ok(Self { connection })
    }

    async fn stack_focus_advance(&mut self, reverse: bool) -> Result<()> {
        let tree = self.connection.get_tree().await?;
 
    
    pub async fn stack_swap_main(&mut self) -> Result<()> {
        let tree = self.connection.get_tree().await?;
        let ws = get_focused_workspace(&mut self.connection).await?;
        let wstree = tree.find_as_ref(|n| n.id == ws.id).unwrap();

        if let Some(stack) = wstree.nodes.first() {
            if stack.nodes.len() == 0 {
                return Ok(());
            }

            let main = wstree.nodes.last().expect("main window not found");

            let focused = stack.find_as_ref(|n| n.is_window() && n.focused);
            let visible = stack
                .iter()
                .filter(|n| n.is_window() && n.visible.unwrap_or(false));
            let initial = stack.nodes.first();

            let stack_current = if let Some(focused) = focused {
                focused
            } else if visible.count() == 1 {
                stack.find_as_ref(|n| n.visible.unwrap_or(false)).unwrap()
            } else {
                initial.unwrap()
            };

            let cmd = format!(
                "[con_id={}] focus; swap container with con_id {}; [con_id={}] focus",
                main.id, stack_current.id, stack_current.id
            );
            log::debug!("stack main controller, swap visible: {}", cmd);
            self.connection.run_command(cmd).await?;
        }
        Ok(())
    }