Repository: typst/typst
File: crates/typst-cli/src/world.rs (Rust)

Code before:

        // Resolve the system-global input path.
        let input = command.input_file.canonicalize().map_err(|_| {
            eco_format!(
                "input file not found (searched at {})",
                command.input_file.display(),
            )
        })?;

        // Resolve the system-global root directory.
        let root = {
            let path = command
                .root
                .as_deref()
                .or_else(|| input.parent())
                .unwrap_or(Path::new("."));
            path.canonicalize().map_err(|_| {
                eco_format!("root directory not found (searched at {})", path.display())
            })?
        };

        // Resolve the virtual path of the main file within the project root.
        let main_path = VirtualPath::within_root(&input, &root)
            .ok_or("input file must be contained in project root")?;

        // Convert the Vec<(String, String)> to a Typst Dictionary
        let inputs = command
            .plain_inputs
            .iter()
            .map(|(k, v)| (k.clone().into(), Value::Str(v.clone().into())));
        let inputs = Dict::from_iter(inputs);

        let sys_args = SysArguments { inputs };

        Ok(Self {
            workdir: std::env::current_dir().ok(),
            input,
            root,
            main: FileId::new(None, main_path),
            library: Prehashed::new(Library::build(sys_args)),
            book: Prehashed::new(searcher.book),
            fonts: searcher.fonts,
            slots: RefCell::default(),
            now: OnceCell::new(),
            export_cache: ExportCache::new(),
        })
    }

    /// The id of the main source file.
    pub fn main(&self) -> FileId {
        self.main

Review comment (suggestion):
```suggestion
        // Convert the Vec<(String, String)> to a Typst Dictionary.
```

Code after:
        // Resolve the system-global input path.
        let input = command.input.canonicalize().map_err(|_| {
            eco_format!("input file not found (searched at {})", command.input.display())
        })?;

        // Resolve the system-global root directory.
        let root = {
            let path = command
                .root
                .as_deref()
                .or_else(|| input.parent())
                .unwrap_or(Path::new("."));
            path.canonicalize().map_err(|_| {
                eco_format!("root directory not found (searched at {})", path.display())
            })?
        };

        // Resolve the virtual path of the main file within the project root.
        let main_path = VirtualPath::within_root(&input, &root)
            .ok_or("source file must be contained in project root")?;

        let library = {
            // Convert the input pairs to a dictionary.
            let inputs: Dict = command
                .inputs
                .iter()
                .map(|(k, v)| (k.as_str().into(), v.as_str().into_value()))
                .collect();

            Library::builder().with_inputs(inputs).build()
        };

        Ok(Self {
            workdir: std::env::current_dir().ok(),
            input,
            root,
            main: FileId::new(None, main_path),
            library: Prehashed::new(library),
            book: Prehashed::new(searcher.book),
            fonts: searcher.fonts,
            slots: RefCell::default(),
            now: OnceCell::new(),
            export_cache: ExportCache::new(),
        })
    }

    /// The id of the main source file.
    pub fn main(&self) -> FileId {
        self.main
    }