Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: I would like to understand "the size of values of type xyz cannot be known at compile time"
I would like to understand "the size of values of type xyz cannot be known at compile time"
โ rust ๐ 2025-06-04 ๐ค surdeus ๐๏ธ 2Hello,
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
๐ท๏ธ rust_feed