{"sample_index": 1, "prompt": "Create a Rust program that uses the regex crate to find and replace patterns in a string. Include `fn main()` with example text. Output only Rust code in ```rust code blocks.", "code": "use regex::Regex;\n\nfn main() {\n // Example text\n let text = \"This is a sample text with some 1, 2, 3 and 4 digits.\";\n\n // Regular expression pattern\n let pattern = Regex::new(r\"(\\d+)\").unwrap();\n let replacement = \"x\";\n\n // Replace all occurrences of 1, 2, 3 and 4 digits with \"x\"\n let new_text = pattern.replace_all(&text, &replacement);\n\n // Print the result\n println!(\"{}\", new_text);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: the trait bound `&&str: regex::Replacer` is not satisfied\n --> src/main.rs:12:47\n |\n12 | let new_text = pattern.replace_all(&text, &replacement);\n | ----------- ^^^^^^^^^^^^ the trait `for<'a, 'b> Fn(&'a regex::Captures<'b>)` is not implemented for `str`, which is required by `&&str: regex::Replacer`\n | |\n | required by a bound introduced by this call\n |\n = note: required for `&str` to implement `for<'a, 'b> FnOnce(&'a regex::Captures<'b>)`\n = note: required for `&&str` to implement `regex::Replacer`\nnote: required by a bound in `regex::Regex::replace_all`\n --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-1.12.2/src/regex/string.rs:842:31\n |\n842 | pub fn replace_all<'h, R: Replacer>(\n | ^^^^^^^^ required by this bound in `Regex::replace_all`\nhelp: consider dereferencing here\n |\n12 | le"} {"sample_index": 2, "prompt": "Write only a single Rust source file (main.rs) with a `fn main() -> anyhow::Result<()>` that demonstrates basic anyhow error handling. Do not explain; output only Rust code wrapped in ```rust code blo", "code": "use anyhow::Result;\nuse anyhow::bail;\nuse anyhow::Context;\n\nfn main() -> Result<()> {\n let a = String::from(\"hello\");\n let b = a.clone();\n\n let c = a + b;\n let d = a + &b;\n\n let e = b + a;\n let f = &b + a;\n\n let g = &a + b;\n let h = &a + &b;\n\n let i = a + &b;\n let j = &a + &b;\n\n let k = b + &a;\n let l = &b + &a;\n\n let m = &b + a;\n let n = &b + &a;\n\n let o = &a + b;\n let p = &a + &b;\n\n let q = &a + &b;\n let r = &a + &b;\n\n let s = b + &a;\n ", "error_type": "type_mismatch", "compile_error": "warning: unused import: `anyhow::bail`\n --> src/main.rs:2:5\n |\n2 | use anyhow::bail;\n | ^^^^^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nwarning: unused import: `anyhow::Context`\n --> src/main.rs:3:5\n |\n3 | use anyhow::Context;\n | ^^^^^^^^^^^^^^^\n\nerror[E0308]: mismatched types\n --> src/main.rs:9:17\n |\n9 | let c = a + b;\n | ^ expected `&str`, found `String`\n |\nhelp: consider borrowing here\n |\n9 | let c = a + &b;\n | +\n\nerror[E0308]: mismatched types\n --> src/main.rs:12:17\n |\n12 | let e = b + a;\n | ^ expected `&str`, found `String`\n |\nhelp: consider borrowing here\n |\n12 | let e = b + &a;\n | +\n\nerror[E0369]: cannot add `String` to `&String`\n --> src/main.rs:13:16\n |\n13 | let f = &b + a;\n | -- ^ - String\n | | |\n | | `+` cannot be used to concatenate a `&str` with a `String`\n | &String\n |\nhelp: remov"} {"sample_index": 4, "prompt": "Create a Rust program that generates UUIDs using the uuid crate. Include `fn main()` that generates and prints multiple UUIDs. Output only Rust code in ```rust code blocks.", "code": "use uuid::Uuid;\n\nfn main() {\n let uuid = Uuid::new_v4();\n println!(\"new_v4: {}\", uuid);\n\n let uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n println!(\"new_v5: {}\", uuid);\n\n let uuid = Uuid::parse_str(\"7f9c2f8a-3c1b-4d0f-8d0c-1d3d8f1e8b8d\");\n println!(\"parse_str: {:?}\", uuid);\n\n let uuid = Uuid::parse_str(\"invalid-uuid\");\n match uuid {\n Ok(uuid) => println!(\"parse_str: {:?}\", uuid),\n Err(_) => println!(\"parse_str: Invalid UUID\")\n }\n\n let uu", "error_type": "other", "compile_error": "error[E0599]: no function or associated item named `new_v5` found for struct `Uuid` in the current scope\n --> src/main.rs:7:22\n |\n7 | let uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n | ^^^^^^ function or associated item not found in `Uuid`\n |\nnote: if you're trying to build a new `Uuid` consider using one of the following associated functions:\n uuid::builder::::nil\n uuid::builder::::max\n uuid::builder::::from_fields\n uuid::builder::::from_fields_le\n and 11 others\n --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/uuid-1.18.1/src/builder.rs:72:5\n |\n72 | pub const fn nil() -> Self {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n98 | pub const fn max() -> Self {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n122 | pub const fn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"} {"sample_index": 5, "prompt": "Write a Rust program that uses chrono to parse a date string and format it differently. Include `fn main()` with example dates. Output only Rust code in ```rust code blocks.", "code": "use chrono::NaiveDateTime;\nuse chrono::NaiveDate;\nuse chrono::NaiveTime;\n\nfn main() {\n let date = NaiveDate::from_ymd(2020, 12, 1);\n let time = NaiveTime::from_hms(14, 10, 30);\n let datetime = NaiveDateTime::new(date, time);\n\n // Format to \"2020-12-01 14:10:30\"\n println!(\"{}\", datetime);\n\n // Format to \"2020-12-01 14:10\"\n println!(\"{}\", datetime.with_time(0));\n\n // Format to \"2020-12-01 14:10:30 UTC\"\n println!(\"{}\", datetime.with_timezone(&chrono::Utc));\n\n // Format", "error_type": "trait_error", "compile_error": "warning: use of deprecated associated function `chrono::NaiveDate::from_ymd`: use `from_ymd_opt()` instead\n --> src/main.rs:6:27\n |\n6 | let date = NaiveDate::from_ymd(2020, 12, 1);\n | ^^^^^^^^\n |\n = note: `#[warn(deprecated)]` on by default\n\nwarning: use of deprecated associated function `chrono::NaiveTime::from_hms`: use `from_hms_opt()` instead\n --> src/main.rs:7:27\n |\n7 | let time = NaiveTime::from_hms(14, 10, 30);\n | ^^^^^^^^\n\nerror[E0599]: no method named `with_time` found for struct `NaiveDateTime` in the current scope\n --> src/main.rs:14:29\n |\n14 | println!(\"{}\", datetime.with_time(0));\n | ^^^^^^^^^\n |\nhelp: there is a method `with_minute` with a similar name\n |\n14 | println!(\"{}\", datetime.with_minute(0));\n | ~~~~~~~~~~~\n\nerror[E0599]: no method named `with_timezone` found for struct `NaiveDateTime` in the current scope\n --> src/main.rs:1"} {"sample_index": 10, "prompt": "Create a small example showing a thiserror enum, Display, a source cause, and a function using the ? operator. Include `fn main()` to drive it. Output only Rust code wrapped in ```rust code blocks.", "code": "use thiserror::Error;\n\n#[derive(Debug, thiserror)]\npub enum MyError {\n #[error(\"Could not open file: {0}\")]\n FileOpen(std::io::Error),\n #[error(\"Could not read file: {0}\")]\n FileRead(std::io::Error),\n}\n\nfn main() {\n let file = std::fs::File::open(\"non-existent-file.txt\").unwrap();\n let result = std::io::Read::read_to_string(&file).map_err(MyError::FileRead).unwrap();\n println!(\"{}\", result);\n}", "error_type": "undefined_variable", "compile_error": "error: cannot find derive macro `thiserror` in this scope\n --> src/main.rs:3:17\n |\n3 | #[derive(Debug, thiserror)]\n | ^^^^^^^^^\n |\n = note: `thiserror` is in scope, but it is a crate, not a derive macro\n\nerror: cannot find attribute `error` in this scope\n --> src/main.rs:5:7\n |\n5 | #[error(\"Could not open file: {0}\")]\n | ^^^^^\n\nerror: cannot find attribute `error` in this scope\n --> src/main.rs:7:7\n |\n7 | #[error(\"Could not read file: {0}\")]\n | ^^^^^\n\nwarning: unused import: `thiserror::Error`\n --> src/main.rs:1:5\n |\n1 | use thiserror::Error;\n | ^^^^^^^^^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0061]: this function takes 2 arguments but 1 argument was supplied\n --> src/main.rs:13:18\n |\n13 | let result = std::io::Read::read_to_string(&file).map_err(MyError::FileRead).unwrap();\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------- argument #2 of type `&mut String` is missing\n |\nnote: types differ"} {"sample_index": 11, "prompt": "Create a Rust program that generates UUIDs using the uuid crate. Include `fn main()` that generates and prints multiple UUIDs. Output only Rust code in ```rust code blocks.", "code": "use uuid::Uuid;\n\nfn main() {\n // Generate a random UUID\n let random_uuid = Uuid::new_v4();\n println!(\"Random UUID: {}\", random_uuid);\n\n // Generate a random UUID with a specific version\n let random_uuid = Uuid::new_v4().is_version(1);\n println!(\"Random UUID v1: {}\", random_uuid);\n\n // Generate a random UUID with a specific version and node\n let random_uuid = Uuid::new_v4().is_version(1).with_node(\"some-node\");\n println!(\"Random UUID v1 with node: {}\", random_uuid);\n\n ", "error_type": "trait_error", "compile_error": "error[E0599]: no method named `is_version` found for struct `Uuid` in the current scope\n --> src/main.rs:9:38\n |\n9 | let random_uuid = Uuid::new_v4().is_version(1);\n | ^^^^^^^^^^\n |\nhelp: there is a method `get_version` with a similar name, but with different arguments\n --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/uuid-1.18.1/src/lib.rs:574:5\n |\n574 | pub const fn get_version(&self) -> Option {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror[E0599]: no method named `is_version` found for struct `Uuid` in the current scope\n --> src/main.rs:13:38\n |\n13 | let random_uuid = Uuid::new_v4().is_version(1).with_node(\"some-node\");\n | ^^^^^^^^^^\n |\nhelp: there is a method `get_version` with a similar name, but with different arguments\n --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/uuid-1.18.1/src/lib.rs:574:5"} {"sample_index": 14, "prompt": "Write a Rust program that uses serde to serialize and deserialize a struct to JSON. Include `fn main()` and use serde_json. Output only Rust code in ```rust code blocks.", "code": "#[derive(Debug, Serialize, Deserialize)]\nstruct Person {\n name: String,\n age: u8,\n}\n\nfn main() {\n let person = Person {\n name: \"John\".to_string(),\n age: 30,\n };\n\n let json = serde_json::to_string(&person).unwrap();\n println!(\"JSON: {}\", json);\n\n let deserialized_person: Person = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized: {:?}\", deserialized_person);\n}", "error_type": "undefined_variable", "compile_error": "error: cannot find derive macro `Serialize` in this scope\n --> src/main.rs:1:17\n |\n1 | #[derive(Debug, Serialize, Deserialize)]\n | ^^^^^^^^^\n |\nhelp: consider importing this derive macro\n |\n1 + use serde::Serialize;\n |\n\nerror: cannot find derive macro `Deserialize` in this scope\n --> src/main.rs:1:28\n |\n1 | #[derive(Debug, Serialize, Deserialize)]\n | ^^^^^^^^^^^\n |\nhelp: consider importing this derive macro\n |\n1 + use serde::Deserialize;\n |\n\nerror[E0277]: the trait bound `Person: serde::Serialize` is not satisfied\n --> src/main.rs:13:38\n |\n13 | let json = serde_json::to_string(&person).unwrap();\n | --------------------- ^^^^^^^ the trait `serde::Serialize` is not implemented for `Person`\n | |\n | required by a bound introduced by this call\n |\n = note: for local types consider adding `#[derive(serde::Serialize)]` to your `Person` type\n = note: for types f"} {"sample_index": 17, "prompt": "Write a Rust program that uses the rand crate to generate random numbers and select random items from a vector. Include `fn main()`. Output only Rust code in ```rust code blocks.", "code": "use rand::Rng;\n\nfn main() {\n let mut rng = rand::thread_rng();\n let v: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n let random_item: i32 = rng.gen_range(0, 10);\n let random_item = v[random_item as usize];\n\n println!(\"Random item: {}\", random_item);\n\n let random_item: i32 = rng.gen_range(0, 10);\n let random_item = v[random_item as usize];\n\n println!(\"Random item: {}\", random_item);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: the trait bound `{integer}: SampleRange<_>` is not satisfied\n --> src/main.rs:7:42\n |\n7 | let random_item: i32 = rng.gen_range(0, 10);\n | --------- ^ the trait `SampleRange<_>` is not implemented for `{integer}`\n | |\n | required by a bound introduced by this call\n |\n = help: the following other types implement trait `SampleRange`:\n RangeInclusive\n std::ops::Range\nnote: required by a bound in `gen_range`\n --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/rng.rs:132:12\n |\n129 | fn gen_range(&mut self, range: R) -> T\n | --------- required by a bound in this associated function\n...\n132 | R: SampleRange\n | ^^^^^^^^^^^^^^ required by this bound in `Rng::gen_range`\n\nerror[E0061]: this method takes 1 argument but 2 arguments were supplied\n --> sr"} {"sample_index": 18, "prompt": "Write a complete Rust program with `fn main()` that demonstrates pattern matching with `match` and `if let`. Include necessary imports. Output only code in ```rust code blocks.", "code": "use std::cmp::Ordering;\n\nfn main() {\n // match statement\n let number = 5;\n match number {\n 1 => println!(\"One\"),\n 2 => println!(\"Two\"),\n 3 => println!(\"Three\"),\n _ => println!(\"A generic value\"),\n }\n\n // if let statement\n let number = 4;\n if let 1 = number {\n println!(\"One\");\n } else {\n println!(\"Not One\");\n }\n\n // let pattern\n let number = Some(3);\n if let Some(3) = number {\n println!(\"Three\");\n }\n\n // le", "error_type": "other", "compile_error": "error: this file contains an unclosed delimiter\n --> src/main.rs:604:6\n |\n3 | fn main() {\n | - unclosed delimiter\n...\n604 | }\n | ^\n\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 19, "prompt": "Create a Rust program that generates UUIDs using the uuid crate. Include `fn main()` that generates and prints multiple UUIDs. Output only Rust code in ```rust code blocks.", "code": "use uuid::Uuid;\n\nfn main() {\n let uuid = Uuid::new_v4();\n println!(\"{}\", uuid);\n let uuid = Uuid::parse_str(\"00000000-0000-0000-0000-000000000000\");\n println!(\"{}\", uuid);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: `Result` doesn't implement `std::fmt::Display`\n --> src/main.rs:7:20\n |\n7 | println!(\"{}\", uuid);\n | ^^^^ `Result` cannot be formatted with the default formatter\n |\n = help: the trait `std::fmt::Display` is not implemented for `Result`\n = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead\n = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)\n\nFor more information about this error, try `rustc --explain E0277`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 21, "prompt": "Create a Rust program that generates UUIDs using the uuid crate. Include `fn main()` that generates and prints multiple UUIDs. Output only Rust code in ```rust code blocks.", "code": "extern crate uuid;\n\nuse uuid::Uuid;\n\nfn main() {\n // Generate a random UUID\n let random_uuid = Uuid::new_v4();\n println!(\"Random UUID: {:?}\", random_uuid);\n\n // Generate a random UUID from a specific variant\n let random_uuid_v5 = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"example.com\");\n println!(\"Random UUID (v5): {:?}\", random_uuid_v5);\n\n // Generate a random UUID from a specific namespace\n let random_uuid_ns = Uuid::new_v4();\n println!(\"Random UUID from Namespace: {:?}\", ra", "error_type": "other", "compile_error": "error[E0599]: no function or associated item named `new_v5` found for struct `Uuid` in the current scope\n --> src/main.rs:11:32\n |\n11 | let random_uuid_v5 = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"example.com\");\n | ^^^^^^ function or associated item not found in `Uuid`\n |\nnote: if you're trying to build a new `Uuid` consider using one of the following associated functions:\n uuid::builder::::nil\n uuid::builder::::max\n uuid::builder::::from_fields\n uuid::builder::::from_fields_le\n and 11 others\n --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/uuid-1.18.1/src/builder.rs:72:5\n |\n72 | pub const fn nil() -> Self {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n98 | pub const fn max() -> Self {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n122 | pub const fn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^"} {"sample_index": 24, "prompt": "Write a Rust program that uses serde to serialize and deserialize a struct to JSON. Include `fn main()` and use serde_json. Output only Rust code in ```rust code blocks.", "code": "#[macro_use]\nextern crate serde_derive;\nextern crate serde_json;\n\nuse serde_json::to_string_pretty;\n\n#[derive(Debug, Serialize, Deserialize)]\nstruct Person {\n first_name: String,\n last_name: String,\n age: u8,\n}\n\nfn main() {\n let mut person = Person {\n first_name: \"John\".to_string(),\n last_name: \"Doe\".to_string(),\n age: 20,\n };\n\n println!(\"Person: {:?}\", person);\n\n let json = to_string_pretty(&person).unwrap();\n println!(\"JSON: {}\", json);\n\n let new", "error_type": "undefined_variable", "compile_error": "error[E0463]: can't find crate for `serde_derive`\n --> src/main.rs:2:1\n |\n2 | extern crate serde_derive;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate\n\nerror: cannot find derive macro `Serialize` in this scope\n --> src/main.rs:7:17\n |\n7 | #[derive(Debug, Serialize, Deserialize)]\n | ^^^^^^^^^\n |\nhelp: consider importing this derive macro\n |\n5 + use serde::Serialize;\n |\n\nerror: cannot find derive macro `Deserialize` in this scope\n --> src/main.rs:7:28\n |\n7 | #[derive(Debug, Serialize, Deserialize)]\n | ^^^^^^^^^^^\n |\nhelp: consider importing this derive macro\n |\n5 + use serde::Deserialize;\n |\n\nerror[E0277]: the trait bound `Person: serde::Serialize` is not satisfied\n --> src/main.rs:23:33\n |\n23 | let json = to_string_pretty(&person).unwrap();\n | ---------------- ^^^^^^^ the trait `serde::Serialize` is not implemented for `Person`\n | |\n | required by a bound introdu"} {"sample_index": 26, "prompt": "Write a Rust program that uses serde to serialize and deserialize a struct to JSON. Include `fn main()` and use serde_json. Output only Rust code in ```rust code blocks.", "code": "use serde::{Deserialize, Serialize};\n\n#[derive(Serialize, Deserialize)]\nstruct User {\n name: String,\n age: u8,\n}\n\nfn main() {\n let user = User {\n name: \"John\".to_string(),\n age: 30,\n };\n\n let json = serde_json::to_string(&user).unwrap();\n println!(\"Serialized: {}\", json);\n\n let user: User = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized: {:?}\", user);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: `User` doesn't implement `Debug`\n --> src/main.rs:19:36\n |\n19 | println!(\"Deserialized: {:?}\", user);\n | ^^^^ `User` cannot be formatted using `{:?}`\n |\n = help: the trait `Debug` is not implemented for `User`\n = note: add `#[derive(Debug)]` to `User` or manually `impl Debug for User`\n = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)\nhelp: consider annotating `User` with `#[derive(Debug)]`\n |\n4 + #[derive(Debug)]\n5 | struct User {\n |\n\nFor more information about this error, try `rustc --explain E0277`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 27, "prompt": "Create a small example showing a thiserror enum, Display, a source cause, and a function using the ? operator. Include `fn main()` to drive it. Output only Rust code wrapped in ```rust code blocks.", "code": "use thiserror::Error;\nuse std::io;\n\n#[derive(Error, Debug)]\n#[error(\"IO error: {0}\")]\npub struct IOError(#[from] io::Error);\n\nfn main() {\n let file = std::fs::File::open(\"file_does_not_exist.txt\").map_err(IOError)?;\n let file = std::fs::File::open(\"file_does_not_exist.txt\")?;\n println!(\"{:?}\", file);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)\n --> src/main.rs:9:79\n |\n8 | fn main() {\n | --------- this function should return `Result` or `Option` to accept `?`\n9 | let file = std::fs::File::open(\"file_does_not_exist.txt\").map_err(IOError)?;\n | ^ cannot use the `?` operator in a function that returns `()`\n |\n = help: the trait `FromResidual>` is not implemented for `()`\nhelp: consider adding return type\n |\n8 ~ fn main() -> Result<(), Box> {\n9 | let file = std::fs::File::open(\"file_does_not_exist.txt\").map_err(IOError)?;\n10| let file = std::fs::File::open(\"file_does_not_exist.txt\")?;\n11| println!(\"{:?}\", file);\n12+ Ok(())\n |\n\nerror[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another ty"} {"sample_index": 28, "prompt": "Write a complete Rust program with `fn main()` that demonstrates pattern matching with `match` and `if let`. Include necessary imports. Output only code in ```rust code blocks.", "code": "fn main() {\n let a = 1;\n let b = \"one\";\n\n let c = 2;\n let d = \"two\";\n\n // Pattern matching with match\n match a {\n 1 => println!(\"a is 1\"),\n 2 => println!(\"a is 2\"),\n _ => println!(\"a is something else\"),\n }\n\n // Pattern matching with if let\n if let 1 = a {\n println!(\"a is 1\");\n } else {\n println!(\"a is not 1\");\n }\n\n // Pattern matching with if let for reference\n let ref x = \"one\";\n if let Some(y) = x {\n println!(", "error_type": "type_mismatch", "compile_error": "error[E0308]: mismatched types\n --> src/main.rs:24:12\n |\n24 | if let Some(y) = x {\n | ^^^^^^^ - this expression has type `&&str`\n | |\n | expected `str`, found `Option<_>`\n |\n = note: expected type `str`\n found enum `Option<_>`\n\nerror[E0308]: mismatched types\n --> src/main.rs:31:12\n |\n31 | if let Some(ref y) = x {\n | ^^^^^^^^^^^ - this expression has type `&&'static str`\n | |\n | expected `str`, found `Option<_>`\n |\n = note: expected type `str`\n found enum `Option<_>`\n\nFor more information about this error, try `rustc --explain E0308`.\nerror: could not compile `template_app` (bin \"template_app\") due to 2 previous errors\n"} {"sample_index": 30, "prompt": "Create a small example showing a thiserror enum, Display, a source cause, and a function using the ? operator. Include `fn main()` to drive it. Output only Rust code wrapped in ```rust code blocks.", "code": "use thiserror::Error;\n\n#[derive(thiserror::Error, Debug)]\npub enum MyError {\n #[error(\"An error with {0}\")]\n Other(#[from] String),\n}\n\nfn run() -> Result<(), MyError> {\n let result = 2 + 2;\n let result = match result {\n 4 => Ok(()),\n _ => Err(MyError::Other(\"result was not 4\".to_string())),\n }?;\n Ok(())\n}\n\nfn main() {\n if let Err(e) = run() {\n println!(\"{:?}\", e);\n }\n}", "error_type": "other", "compile_error": "warning: unused import: `thiserror::Error`\n --> src/main.rs:1:5\n |\n1 | use thiserror::Error;\n | ^^^^^^^^^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0599]: the method `as_dyn_error` exists for reference `&String`, but its trait bounds were not satisfied\n --> src/main.rs:6:13\n |\n6 | Other(#[from] String),\n | ^^^^ method cannot be called on `&String` due to unsatisfied trait bounds\n |\n = note: the following trait bounds were not satisfied:\n `String: std::error::Error`\n which is required by `String: AsDynError<'_>`\n `&String: std::error::Error`\n which is required by `&String: AsDynError<'_>`\n `str: Sized`\n which is required by `str: AsDynError<'_>`\n `str: std::error::Error`\n which is required by `str: AsDynError<'_>`\n\nwarning: unused variable: `result`\n --> src/main.rs:11:9\n |\n11 | let result = match result {\n | ^^^^^^ help: if this is intentional, p"} {"sample_index": 31, "prompt": "Create a Rust program that generates UUIDs using the uuid crate. Include `fn main()` that generates and prints multiple UUIDs. Output only Rust code in ```rust code blocks.", "code": "use uuid::Uuid;\n\nfn main() {\n let id = Uuid::new_v4();\n println!(\"Random UUID: {}\", id);\n let id = Uuid::new_v5(Uuid::NAMESPACE_URL, \"https://www.rust-lang.org/\");\n println!(\"UUID from URL: {}\", id);\n let id = Uuid::parse_str(\"c7c7f6c6-9fdd-4b1f-8e9f-b0e8c5b5f7f6\");\n match id {\n Ok(id) => println!(\"Parsed UUID: {}\", id),\n Err(e) => println!(\"Error: {}\", e),\n }\n}", "error_type": "other", "compile_error": "error[E0599]: no function or associated item named `new_v5` found for struct `Uuid` in the current scope\n --> src/main.rs:6:20\n |\n6 | let id = Uuid::new_v5(Uuid::NAMESPACE_URL, \"https://www.rust-lang.org/\");\n | ^^^^^^ function or associated item not found in `Uuid`\n |\nnote: if you're trying to build a new `Uuid` consider using one of the following associated functions:\n uuid::builder::::nil\n uuid::builder::::max\n uuid::builder::::from_fields\n uuid::builder::::from_fields_le\n and 11 others\n --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/uuid-1.18.1/src/builder.rs:72:5\n |\n72 | pub const fn nil() -> Self {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n98 | pub const fn max() -> Self {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n122 | pub const fn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"} {"sample_index": 32, "prompt": "Define a newtype wrapper for [u8; 32] and implement FromStr and Display. Provide a small `fn main()` that parses and prints it. Output only Rust code in ```rust code blocks.", "code": "#[derive(Debug, PartialEq, Eq, Clone, Copy)]\nstruct U32Array([u8; 32]);\n\nimpl FromStr for U32Array {\n type Err = std::num::ParseIntError;\n\n fn from_str(s: &str) -> Result {\n if s.len()!= 32 {\n Err(std::num::ParseIntError::from(\"String must be 32 bytes\"))\n } else {\n let mut array = [0u8; 32];\n for (i, c) in s.bytes().enumerate() {\n if c < 0x30 || c > 0x39 {\n return Err(std::num::ParseIntError::", "error_type": "undefined_variable", "compile_error": "error[E0405]: cannot find trait `FromStr` in this scope\n --> src/main.rs:4:6\n |\n4 | impl FromStr for U32Array {\n | ^^^^^^^ not found in this scope\n |\nhelp: consider importing this trait\n |\n1 + use std::str::FromStr;\n |\n\nFor more information about this error, try `rustc --explain E0405`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 33, "prompt": "Write a Rust program that uses chrono to parse a date string and format it differently. Include `fn main()` with example dates. Output only Rust code in ```rust code blocks.", "code": "use chrono::format::{self, ItemFormatSpecifier};\n\nfn main() {\n let date_str = \"2021-07-07 13:37:27\";\n let date = date_str.parse::().unwrap();\n\n // Parse date with time zone\n let date_with_tz = date.with_timezone(&chrono::offset::Local);\n let parsed_date = date_str.parse::().unwrap();\n println!(\"Parsed date with time zone: {:?}\", parsed_date.with_timezone(&chrono::offset::Local));\n\n // Parse date and time\n let parsed_date_time ", "error_type": "other", "compile_error": "error[E0432]: unresolved import `chrono::format::ItemFormatSpecifier`\n --> src/main.rs:1:28\n |\n1 | use chrono::format::{self, ItemFormatSpecifier};\n | ^^^^^^^^^^^^^^^^^^^ no `ItemFormatSpecifier` in `format`\n\nwarning: unused import: `self`\n --> src/main.rs:1:22\n |\n1 | use chrono::format::{self, ItemFormatSpecifier};\n | ^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0599]: no method named `with_timezone` found for struct `NaiveDateTime` in the current scope\n --> src/main.rs:8:29\n |\n8 | let date_with_tz = date.with_timezone(&chrono::offset::Local);\n | ^^^^^^^^^^^^^\n |\nhelp: there is a method `with_second` with a similar name\n |\n8 | let date_with_tz = date.with_second(&chrono::offset::Local);\n | ~~~~~~~~~~~\n\nerror[E0599]: no method named `with_timezone` found for struct `NaiveDateTime` in the current scope\n --> src/main.rs:10:62\n |\n10 | printl"} {"sample_index": 35, "prompt": "Write a Rust program that uses serde to serialize and deserialize a struct to JSON. Include `fn main()` and use serde_json. Output only Rust code in ```rust code blocks.", "code": "use serde::{Deserialize, Serialize};\n\n#[derive(Serialize, Deserialize)]\nstruct Person {\n name: String,\n age: u8,\n friends: Vec,\n}\n\nfn main() {\n let person = Person {\n name: \"John\".to_string(),\n age: 25,\n friends: vec![\"Alice\".to_string(), \"Bob\".to_string()],\n };\n\n let serialized = serde_json::to_string(&person).unwrap();\n println!(\"Serialized JSON: {}\", serialized);\n\n let deserialized: Person = serde_json::from_str(&serialized).unwrap();\n p", "error_type": "trait_error", "compile_error": "error[E0277]: `Person` doesn't implement `Debug`\n --> src/main.rs:21:41\n |\n21 | println!(\"Deserialized JSON: {:?}\", deserialized);\n | ^^^^^^^^^^^^ `Person` cannot be formatted using `{:?}`\n |\n = help: the trait `Debug` is not implemented for `Person`\n = note: add `#[derive(Debug)]` to `Person` or manually `impl Debug for Person`\n = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)\nhelp: consider annotating `Person` with `#[derive(Debug)]`\n |\n4 + #[derive(Debug)]\n5 | struct Person {\n |\n\nFor more information about this error, try `rustc --explain E0277`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 37, "prompt": "Write a complete Rust program with `fn main()` that demonstrates pattern matching with `match` and `if let`. Include necessary imports. Output only code in ```rust code blocks.", "code": "fn main() {\n // Import the necessary module\n use std::cmp::Ordering;\n\n // A list of numbers\n let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n // A for loop to print the numbers in ascending order\n for number in &numbers {\n match number.cmp(&5) {\n Ordering::Less => println!(\"{} is less than 5\", number),\n Ordering::Equal => println!(\"{} is equal to 5\", number),\n Ordering::Greater => println!(\"{} is greater than 5\", number),\n }\n }\n", "error_type": "type_mismatch", "compile_error": "error[E0308]: mismatched types\n --> src/main.rs:18:55\n |\n18 | if let Some(number) = numbers.iter().find(|x| x > &5) {\n | ^^ expected `&&_`, found `&{integer}`\n |\n = note: expected reference `&&_`\n found reference `&{integer}`\n\nFor more information about this error, try `rustc --explain E0308`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 39, "prompt": "Write a Rust program that uses chrono to parse a date string and format it differently. Include `fn main()` with example dates. Output only Rust code in ```rust code blocks.", "code": "use chrono::NaiveDateTime;\nuse chrono::offset::TimeZone;\nuse chrono::offset::Utc;\nuse chrono::offset::TimeZone;\nuse chrono::Local;\n\nfn main() {\n // Using Utc\n let date = \"2022-12-25 14:00:00\";\n let parsed_date = NaiveDateTime::parse_from_str(date, \"%Y-%m-%d %H:%M:%S\").unwrap();\n let formatted_date = Utc.from_utc_datetime(&parsed_date).format(\"%B %d, %Y\");\n println!(\"Using Utc: {}\", formatted_date);\n\n // Using Local\n let date = \"2022-12-25 14:00:00\";\n let parsed_date = Nai", "error_type": "other", "compile_error": "error[E0252]: the name `TimeZone` is defined multiple times\n --> src/main.rs:4:5\n |\n2 | use chrono::offset::TimeZone;\n | ------------------------ previous import of the trait `TimeZone` here\n3 | use chrono::offset::Utc;\n4 | use chrono::offset::TimeZone;\n | ^^^^^^^^^^^^^^^^^^^^^^^^ `TimeZone` reimported here\n |\n = note: `TimeZone` must be defined only once in the type namespace of this module\n\nwarning: unused import: `chrono::offset::TimeZone`\n --> src/main.rs:4:5\n |\n4 | use chrono::offset::TimeZone;\n | ^^^^^^^^^^^^^^^^^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nFor more information about this error, try `rustc --explain E0252`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error; 1 warning emitted\n"} {"sample_index": 42, "prompt": "Create a small example showing a thiserror enum, Display, a source cause, and a function using the ? operator. Include `fn main()` to drive it. Output only Rust code wrapped in ```rust code blocks.", "code": "use thiserror::Error;\n\n#[derive(Debug, Error, Display)]\nenum MyError {\n #[error(\"not a number: {0}\")]\n NotANumber(String),\n #[error(\"not a string\")]\n NotAString,\n #[error(\"error with code: {0}\")]\n CustomError(usize),\n}\n\nfn get_number(s: &str) -> Result {\n match s.parse::() {\n Ok(num) => Ok(num),\n Err(_) => Err(MyError::NotANumber(s.to_string())),\n }\n}\n\nfn get_string(s: &str) -> Result {\n match s.to_string().as_str() {\n ", "error_type": "undefined_variable", "compile_error": "error: cannot find derive macro `Display` in this scope\n --> src/main.rs:3:24\n |\n3 | #[derive(Debug, Error, Display)]\n | ^^^^^^^\n\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 44, "prompt": "Write a Rust program that uses serde to serialize and deserialize a struct to JSON. Include `fn main()` and use serde_json. Output only Rust code in ```rust code blocks.", "code": "use serde::{Serialize, Deserialize};\n\n#[derive(Serialize, Deserialize)]\nstruct User {\n username: String,\n email: String,\n age: u8,\n}\n\nfn main() {\n let user = User {\n username: \"johndoe\".to_string(),\n email: \"johndoe@example.com\".to_string(),\n age: 32,\n };\n\n let user_json = serde_json::to_string(&user).unwrap();\n println!(\"User in JSON format: {}\", user_json);\n\n let deserialized_user: User = serde_json::from_str(&user_json).unwrap();\n println!(\"Dese", "error_type": "trait_error", "compile_error": "error[E0277]: `User` doesn't implement `Debug`\n --> src/main.rs:21:41\n |\n21 | println!(\"Deserialized User: {:?}\", deserialized_user);\n | ^^^^^^^^^^^^^^^^^ `User` cannot be formatted using `{:?}`\n |\n = help: the trait `Debug` is not implemented for `User`\n = note: add `#[derive(Debug)]` to `User` or manually `impl Debug for User`\n = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)\nhelp: consider annotating `User` with `#[derive(Debug)]`\n |\n4 + #[derive(Debug)]\n5 | struct User {\n |\n\nFor more information about this error, try `rustc --explain E0277`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 45, "prompt": "Create a small example showing a thiserror enum, Display, a source cause, and a function using the ? operator. Include `fn main()` to drive it. Output only Rust code wrapped in ```rust code blocks.", "code": "#[derive(thiserror::Error, Debug)]\nenum MyError {\n #[error(\"invalid input\")]\n InvalidInput(#[from] std::fmt::Error),\n #[error(\"invalid value: {0}\")]\n InvalidValue(i32),\n}\n\nfn main() {\n match 1.1.parse::() {\n Ok(v) => println!(\"Parsed: {}\", v),\n Err(e) => {\n if let MyError::InvalidInput(_) = e {\n println!(\"Input error\");\n } else if let MyError::InvalidValue(v) = e {\n println!(\"Invalid value: {}\", v);\n ", "error_type": "other", "compile_error": "error[E0689]: can't call method `parse` on ambiguous numeric type `{float}`\n --> src/main.rs:10:15\n |\n10 | match 1.1.parse::() {\n | ^^^^^\n |\nhelp: you must specify a concrete type for this numeric value, like `f32`\n |\n10 | match 1.1_f32.parse::() {\n | ~~~~~~~\n\nFor more information about this error, try `rustc --explain E0689`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 48, "prompt": "Write a complete Rust program with `fn main()` that demonstrates pattern matching with `match` and `if let`. Include necessary imports. Output only code in ```rust code blocks.", "code": "fn main() {\n // let values to be matched\n let numbers = [1, 2, 3, 4, 5, 6];\n let numbers = vec![1, 2, 3, 4, 5, 6];\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, ", "error_type": "other", "compile_error": "error: this file contains an unclosed delimiter\n --> src/main.rs:508:6\n |\n1 | fn main() {\n | - unclosed delimiter\n...\n508 | }\n | ^\n\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 50, "prompt": "Write only Rust code for a program that uses iterators with map/filter to compute a sum. Include `fn main()` and necessary imports. No explanations. Wrap code in ```rust code blocks.", "code": "fn main() {\n let v = vec![1, 2, 3, 4, 5];\n let sum: i32 = v.iter().filter(|x| x % 2 == 0).map(|x| x * x).sum();\n println!(\"{}\", sum);\n}", "error_type": "other", "compile_error": "error[E0369]: cannot calculate the remainder of `&&{integer}` divided by `{integer}`\n --> src/main.rs:3:42\n |\n3 | let sum: i32 = v.iter().filter(|x| x % 2 == 0).map(|x| x * x).sum();\n | - ^ - {integer}\n | |\n | &&{integer}\n |\nhelp: `%` can be used on `&{integer}` if you dereference the left-hand side\n |\n3 | let sum: i32 = v.iter().filter(|x| *x % 2 == 0).map(|x| x * x).sum();\n | +\n\nFor more information about this error, try `rustc --explain E0369`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 51, "prompt": "Write only Rust code for a program that uses iterators with map/filter to compute a sum. Include `fn main()` and necessary imports. No explanations. Wrap code in ```rust code blocks.", "code": "use std::env;\n\nfn main() {\n let args: Vec = env::args().collect();\n if args.len()!= 2 {\n println!(\"Usage: sum \");\n std::process::exit(1);\n }\n let filename = &args[1];\n if let Ok(lines) = std::fs::read_to_string(filename).map(Ok) {\n let numbers: Vec = lines.split_whitespace().map(|line| line.parse::().unwrap()).collect();\n let total: i64 = numbers.iter().filter(|&&n| n % 2 == 0).map(|&n| n * 2).sum();\n println!(\"{}\", total)", "error_type": "other", "compile_error": "error[E0599]: no method named `split_whitespace` found for enum `Result` in the current scope\n --> src/main.rs:11:39\n |\n11 | let numbers: Vec = lines.split_whitespace().map(|line| line.parse::().unwrap()).collect();\n | ^^^^^^^^^^^^^^^^ method not found in `Result`\n |\nnote: the method `split_whitespace` exists on the type `String`\n --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/str/mod.rs:965:5\nhelp: consider using `Result::expect` to unwrap the `String` value, panicking if the value is a `Result::Err`\n |\n11 | let numbers: Vec = lines.expect(\"REASON\").split_whitespace().map(|line| line.parse::().unwrap()).collect();\n | +++++++++++++++++\n\nFor more information about this error, try `rustc --explain E0599`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 52, "prompt": "Create a Rust program that generates UUIDs using the uuid crate. Include `fn main()` that generates and prints multiple UUIDs. Output only Rust code in ```rust code blocks.", "code": "use uuid::Uuid;\n\nfn main() {\n // Generate a random UUID\n let random_uuid = Uuid::new_v4();\n println!(\"Random UUID: {:?}\", random_uuid);\n\n // Generate a random UUID with a fixed node and clock sequence\n let fixed_uuid = Uuid::new_v4_with_timestamp_and_clock_sequence(0, 0);\n println!(\"Fixed UUID: {:?}\", fixed_uuid);\n\n // Generate a random UUID from a slice of bytes\n let bytes: [u8; 16] = [0u8; 16];\n let uuid_from_bytes = Uuid::from_bytes(bytes);\n println!(\"UUID from b", "error_type": "other", "compile_error": "error[E0599]: no function or associated item named `new_v4_with_timestamp_and_clock_sequence` found for struct `Uuid` in the current scope\n --> src/main.rs:9:28\n |\n9 | let fixed_uuid = Uuid::new_v4_with_timestamp_and_clock_sequence(0, 0);\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `Uuid`\n |\nnote: if you're trying to build a new `Uuid` consider using one of the following associated functions:\n uuid::builder::::nil\n uuid::builder::::max\n uuid::builder::::from_fields\n uuid::builder::::from_fields_le\n and 11 others\n --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/uuid-1.18.1/src/builder.rs:72:5\n |\n72 | pub const fn nil() -> Self {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n98 | pub const fn max() -> Self {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n122 | pub const fn from_fields(d1: u32, d2: u16, d3: u16"} {"sample_index": 53, "prompt": "Write a Rust program that uses serde to serialize and deserialize a struct to JSON. Include `fn main()` and use serde_json. Output only Rust code in ```rust code blocks.", "code": "use serde::{Deserialize, Serialize};\n\n#[derive(Serialize, Deserialize)]\nstruct User {\n id: u32,\n name: String,\n age: u8,\n}\n\nfn main() {\n let user = User {\n id: 1,\n name: \"John\".to_string(),\n age: 30,\n };\n\n let json = serde_json::to_string(&user).unwrap();\n println!(\"JSON: {}\", json);\n\n let deserialized: User = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized User: {:?}\", deserialized);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: `User` doesn't implement `Debug`\n --> src/main.rs:21:41\n |\n21 | println!(\"Deserialized User: {:?}\", deserialized);\n | ^^^^^^^^^^^^ `User` cannot be formatted using `{:?}`\n |\n = help: the trait `Debug` is not implemented for `User`\n = note: add `#[derive(Debug)]` to `User` or manually `impl Debug for User`\n = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)\nhelp: consider annotating `User` with `#[derive(Debug)]`\n |\n4 + #[derive(Debug)]\n5 | struct User {\n |\n\nFor more information about this error, try `rustc --explain E0277`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"}