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: watch.rs
    path of file: ./repos/typst/crates/typst-cli/src
    
    the code of the file until where you have to start completion: use std::collections::{HashMap, HashSet};
use std::io::{self, Write};
use std::iter;
use std::path::PathBuf;
use std::sync::mpsc::Receiver;
use std::time::{Duration, Instant};

use codespan_reporting::term::termcolor::WriteColor;
use codespan_reporting::term::{self, termcolor};
use ecow::eco_format;
use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher as _};
use same_file::is_same_file;
use typst::diag::StrResult;

use crate::args::{CompileCommand, Input};
use crate::compile::compile_once;
use crate::timings::Timer;
use crate::world::{SystemWorld, WorldCreationError};
use crate::{print_error, terminal};

/// Execute a watching compilation command.
pub fn watch(mut timer: Timer, mut command: CompileCommand) -> StrResult<()> {
    // Enter the alternate screen and handle Ctrl-C ourselves.
    terminal::out().init_exit_handler()?;
    terminal::out()
        .enter_alternate_screen()
        .map_err(|err| eco_format!("failed to enter alternate screen ({err})"))?;

    // Create a file system watcher.
    let mut watcher = Watcher::new(command.output())?;

    // Create the world that serves sources, files, and fonts.
    // Additionally, if any files do not exist, wait until they do.
    let mut world = loop {
        match SystemWorld::new(&command.common) {
            Ok(world) => break worl
    
pub fn watch(mut timer: Timer, mut command: CompileCommand) -> StrResult<()> {
    // Enter the alternate screen and handle Ctrl-C ourselves.
    terminal::out().init_exit_handler()?;
    terminal::out()
        .enter_alternate_screen()
        .map_err(|err| eco_format!("failed to enter alternate screen ({err})"))?;

    // Create a file system watcher.
    let mut watcher = Watcher::new(command.output())?;

    // Create the world that serves sources, files, and fonts.
    // Additionally, if any files do not exist, wait until they do.
    let mut world = loop {
        match SystemWorld::new(&command.common) {
            Ok(world) => break world,
            Err(
                ref err @ (WorldCreationError::InputNotFound(ref path)
                | WorldCreationError::RootNotFound(ref path)),
            ) => {
                watcher.update([path.clone()])?;
                Status::Error.print(&command).unwrap();
                print_error(&err.to_string()).unwrap();
                watcher.wait()?;
            }
            Err(err) => return Err(err.into()),
        }
    };

    // Perform initial compilation.
    timer.record(&mut world, |world| compile_once(world, &mut command, true))??;

    // Watch all dependencies of the initial compilation.
    watcher.update(world.dependencies())?;

    // Recompile whenever something relevant happens.
    loop {
        // Wait until anything relevant happens.
        watcher.wait()?;

        // Reset all dependencies.
        world.reset();

        // Recompile.
        timer.record(&mut world, |world| compile_once(world, &mut command, true))??;

        // Evict the cache.
        comemo::evict(10);

        // Adjust the file watching.
        watcher.update(world.dependencies())?;
    }
}