I would like to understand "the size of values of type xyz cannot be known at compile time"

โš“ rust    ๐Ÿ“… 2025-06-04    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

Hello,

I tried to find out about my question via a quick google search but I did not find something closely related, the suggestions in similar questions also did not help. I want to understand the compiler error stated in the topic headline. Thanks!

I am following the Rust book Developing the Libraryโ€™s Functionality with Test Driven Development - The Rust Programming Language and write unit tests for the mini grep project from chapter 12.
My directory structure is:

src/
- bin/
-- lib.rs
-main.rs
test_setup/
- mod.rs
Cargo.toml
// lib.rs
mod test_setup;

#...

#[cfg(test)]
mod tests {
    use crate::Config;

    #[test]
    fn test_build_config() {
        // use the setup method generate_cmd_args() here.
        assert_eq!(Config::build(&args), Err("Not enough arguments."));
    }
}
//test_setup/mod.rs

// compiler error at [[String]]: 
// the size for values of type `[[String]]` cannot be known at compilation time
// the trait `Sized` is not implemented for `[[String]]`
fn generate_cmd_args() -> [[String]] {
        let file_path = "mypath/Rust/Tutorials/minigrep/searchfile";
        let minigrep_path = "mypath/Rust/Tutorials/minigrep/";
        let search_text = "keyword";
        let args = [[String::from(minigrep_path), String::from(file_path)]];
        args

        
}

5 posts - 2 participants

Read full topic

๐Ÿท๏ธ rust_feed