{"sample_index": 2, "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::io;\nuse std::io::prelude::*;\n\nfn main() {\n println!(\"Enter a number: \");\n let mut line = String::new();\n io::stdin().read_line(&mut line)\n .expect(\"Failed to read line\");\n let num: i32 = match line.trim().parse() {\n Ok(num) => num,\n Err(_) => {\n println!(\"Not a number!\");\n return;\n }\n };\n\n let result = if let Ok(num) = line.trim().parse() {\n if num == 1 {\n println!(\"One\");\n } else if num == 2 {\n ", "error_type": "type_mismatch", "compile_error": "error[E0277]: can't compare `()` with `i32`\n --> src/main.rs:18:16\n |\n18 | if num == 1 {\n | ^^ no implementation for `() == i32`\n |\n = help: the trait `PartialEq` is not implemented for `()`\n = help: the trait `PartialEq` is implemented for `()`\n = help: for that trait implementation, expected `()`, found `i32`\n\nerror[E0277]: can't compare `()` with `i32`\n --> src/main.rs:20:23\n |\n20 | } else if num == 2 {\n | ^^ no implementation for `() == i32`\n |\n = help: the trait `PartialEq` is not implemented for `()`\n = help: the trait `PartialEq` is implemented for `()`\n = help: for that trait implementation, expected `()`, found `i32`\n\nerror[E0277]: can't compare `()` with `i32`\n --> src/main.rs:22:23\n |\n22 | } else if num == 3 {\n | ^^ no implementation for `() == i32`\n |\n = help: the trait `PartialEq` is not implemented for `()`\n = help: the trait `PartialEq` i"} {"sample_index": 3, "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 println!(\"v4: {:#}\", Uuid::new_v4());\n println!(\"v5: {:#}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\"));\n println!(\"v5: {:#}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\").to_hyphenated().to_string());\n println!(\"v5: {:#}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\").to_hyphenated());\n println!(\"v5: {:#}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\").to_string());\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:5:32\n |\n5 | println!(\"v5: {:#}\", 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": 4, "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::prelude::*;\nuse chrono::format::PcDateTime;\n\nfn main() {\n let date = Local.ymd(2020, 1, 1).and_hms(10, 11, 12);\n let date = Local.ymd(2020, 1, 1).and_hms_milli(10, 11, 12, 13);\n let date = Local.ymd(2020, 1, 1).and_hms_micro(10, 11, 12, 13, 14);\n let date = Local.ymd(2020, 1, 1).and_hms_nano(10, 11, 12, 13, 14, 15);\n\n println!(\"Local time: {}\", date.format(\"%Y-%m-%d %H:%M:%S\"));\n println!(\"Local time: {}\", date.format(\"%Y-%m-%d %H:%M:%S%.f\"));\n println!(\"Local ti", "error_type": "other", "compile_error": "error[E0432]: unresolved import `chrono::format::PcDateTime`\n --> src/main.rs:2:5\n |\n2 | use chrono::format::PcDateTime;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `PcDateTime` in `format`\n\nwarning: use of deprecated method `chrono::TimeZone::ymd`: use `with_ymd_and_hms()` instead\n --> src/main.rs:5:22\n |\n5 | let date = Local.ymd(2020, 1, 1).and_hms(10, 11, 12);\n | ^^^\n |\n = note: `#[warn(deprecated)]` on by default\n\nwarning: use of deprecated method `chrono::Date::::and_hms`: Use and_hms_opt() instead\n --> src/main.rs:5:38\n |\n5 | let date = Local.ymd(2020, 1, 1).and_hms(10, 11, 12);\n | ^^^^^^^\n\nwarning: use of deprecated method `chrono::TimeZone::ymd`: use `with_ymd_and_hms()` instead\n --> src/main.rs:6:22\n |\n6 | let date = Local.ymd(2020, 1, 1).and_hms_milli(10, 11, 12, 13);\n | ^^^\n\nwarning: use of deprecated method `chrono::Date::::and_hms_milli`: Use and_hms_milli_opt() instead\n -"} {"sample_index": 7, "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 MyStruct {\n a: i32,\n b: String,\n}\n\nfn main() {\n let s = MyStruct { a: 42, b: \"hello\".to_string() };\n\n let serialized = serde_json::to_string(&s).unwrap();\n println!(\"serialized = {}\", serialized);\n\n let deserialized: MyStruct = serde_json::from_str(&serialized).unwrap();\n println!(\"deserialized = {:?}\", deserialized);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: `MyStruct` doesn't implement `Debug`\n --> src/main.rs:16:37\n |\n16 | println!(\"deserialized = {:?}\", deserialized);\n | ^^^^^^^^^^^^ `MyStruct` cannot be formatted using `{:?}`\n |\n = help: the trait `Debug` is not implemented for `MyStruct`\n = note: add `#[derive(Debug)]` to `MyStruct` or manually `impl Debug for MyStruct`\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 `MyStruct` with `#[derive(Debug)]`\n |\n4 + #[derive(Debug)]\n5 | struct MyStruct {\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": 11, "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::{anyhow, Context, Result};\nuse std::path::PathBuf;\n\nfn main() -> anyhow::Result<()> {\n let path = PathBuf::from(\"/tmp/file.txt\");\n let file = std::fs::File::open(path).context(\"Failed to open file\")?;\n let _ = file.read_to_string().context(\"Failed to read file\")?;\n Ok(())\n}", "error_type": "other", "compile_error": "warning: unused imports: `Result` and `anyhow`\n --> src/main.rs:1:14\n |\n1 | use anyhow::{anyhow, Context, Result};\n | ^^^^^^ ^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0599]: no method named `read_to_string` found for struct `File` in the current scope\n --> src/main.rs:7:18\n |\n7 | let _ = file.read_to_string().context(\"Failed to read file\")?;\n | ^^^^^^^^^^^^^^\n --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/io/mod.rs:904:8\n |\n = note: the method is available for `File` here\n |\n = help: items from traits can only be used if the trait is in scope\nhelp: there is a method `read_to_end` with a similar name, but with different arguments\n --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/io/mod.rs:861:5\nhelp: trait `Read` which provides `read_to_string` is implemented but not in scope; perhaps you want to import it\n |\n1 + use std::io::Read;\n |\n\nFor more information about this"} {"sample_index": 12, "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::prelude::*;\n\nfn main() {\n let random_number = thread_rng().gen_range(1, 10);\n let mut random_numbers: Vec = Vec::new();\n\n for i in 0..random_number {\n random_numbers.push(i);\n }\n\n println!(\"Random number: {}\", random_number);\n println!(\"Random numbers: {:?}\", random_numbers);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: the trait bound `{integer}: SampleRange<_>` is not satisfied\n --> src/main.rs:4:48\n |\n4 | let random_number = thread_rng().gen_range(1, 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"} {"sample_index": 13, "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": "use std::str::FromStr;\nuse std::fmt;\n\nnewtype MyVec([u8; 32]);\n\nimpl FromStr for MyVec {\n type Err = String;\n fn from_str(s: &str) -> Result {\n let mut vec = [0; 32];\n if s.len()!= 32 {\n return Err(\"Input string is not 32 bytes long\".to_string());\n }\n for (i, c) in s.chars().enumerate() {\n vec[i] = c as u8;\n }\n Ok(MyVec(vec))\n }\n}\n\nimpl fmt::Display for MyVec {\n fn fmt(&self, f: &mut fmt::Formatter) -> f", "error_type": "type_mismatch", "compile_error": "error: expected one of `!` or `::`, found `MyVec`\n --> src/main.rs:4:9\n |\n4 | newtype MyVec([u8; 32]);\n | ^^^^^ expected one of `!` or `::`\n\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 15, "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);\n \n // Generate a random UUID with a specific version\n let random_uuid_v5 = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n println!(\"{}\", random_uuid_v5);\n \n // Generate a random UUID with a specific version and namespace\n let random_uuid_v6 = Uuid::new_v6(Uuid::NAMESPACE_DNS);\n println!(\"{}\", random_uuid_v6);\n \n // Generate a random", "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:9:32\n |\n9 | let random_uuid_v5 = 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": 16, "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::{DateTime, Local};\nuse chrono::format::{Item, ParseResult, ParseWeekday, ParseYear};\n\nfn parse_date(date: &str) -> Option> {\n match date.parse::() {\n Ok(dt) => Some(dt),\n Err(_) => None,\n }\n}\n\nfn format_date(dt: &DateTime, format: &str) -> String {\n dt.format(format).to_string()\n}\n\nfn main() {\n // Example 1\n let date = \"2022-08-12 11:12:13\";\n let date = parse_date(date).unwrap();\n let formatted = format_date(&date, \"%a ", "error_type": "type_mismatch", "compile_error": "error[E0432]: unresolved imports `chrono::format::ParseWeekday`, `chrono::format::ParseYear`\n --> src/main.rs:2:41\n |\n2 | use chrono::format::{Item, ParseResult, ParseWeekday, ParseYear};\n | ^^^^^^^^^^^^ ^^^^^^^^^ no `ParseYear` in `format`\n | |\n | no `ParseWeekday` in `format`\n\nwarning: unused imports: `Item` and `ParseResult`\n --> src/main.rs:2:22\n |\n2 | use chrono::format::{Item, ParseResult, ParseWeekday, ParseYear};\n | ^^^^ ^^^^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0277]: the trait bound `Local: FromStr` is not satisfied\n --> src/main.rs:5:16\n |\n5 | match date.parse::() {\n | ^^^^^ the trait `FromStr` is not implemented for `Local`\n |\n = help: the following other types implement trait `FromStr`:\n DateTime\n DateTime\n DateTi"} {"sample_index": 17, "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 random_uuid = Uuid::new_v4();\n println!(\"Random UUID: {}\", random_uuid);\n\n let random_uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"https://www.rust-lang.org/\");\n println!(\"Random UUID: {}\", random_uuid);\n\n let random_uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"https://www.rust-lang.org\");\n println!(\"Random UUID: {}\", random_uuid);\n\n let random_uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"https://www.rust-lang.org/\");\n println!(\"Random UUID: {}\", ", "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:29\n |\n7 | let random_uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"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": 18, "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::collections::HashMap;\n\nfn main() {\n let mut map = HashMap::new();\n map.insert(\"a\", 1);\n map.insert(\"b\", 2);\n map.insert(\"c\", 3);\n\n let total = map.values().filter(|v| **v > 1).map(|v| v + 1).sum();\n\n println!(\"total: {}\", total);\n}", "error_type": "other", "compile_error": "error[E0283]: type annotations needed\n --> src/main.rs:9:9\n |\n9 | let total = map.values().filter(|v| **v > 1).map(|v| v + 1).sum();\n | ^^^^^ --- type must be known at this point\n |\n = note: cannot satisfy `_: Sum`\n = help: the following types implement trait `Sum`:\n `Duration` implements `Sum<&'a Duration>`\n `Duration` implements `Sum`\n `Option` implements `Sum>`\n `Result` implements `Sum>`\n `Simd` implements `Sum<&'a Simd>`\n `Simd` implements `Sum`\n `Simd` implements `Sum<&'a Simd>`\n `Simd` implements `Sum`\n and 72 others\nnote: required by a bound in `std::iter::Iterator::sum`\n --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/iter/traits/iterator.rs:3572:5\nhelp: consider giving `total` an explicit type\n |\n9 | le"} {"sample_index": 19, "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::{DateTime, Local, NaiveDateTime, Utc};\n\nfn main() {\n let local_now = Local::now();\n let utc_now = Utc::now();\n let naive_now = NaiveDateTime::from_timestamp(0, 0);\n\n let local_now_str = local_now.to_rfc3339();\n let utc_now_str = utc_now.to_rfc3339();\n let naive_now_str = naive_now.to_rfc3339();\n\n println!(\"Local now: {}\", local_now_str);\n println!(\"UTC now: {}\", utc_now_str);\n println!(\"Naive now: {}\", naive_now_str);\n}", "error_type": "other", "compile_error": "warning: unused import: `DateTime`\n --> src/main.rs:1:14\n |\n1 | use chrono::{DateTime, Local, NaiveDateTime, Utc};\n | ^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nwarning: use of deprecated associated function `chrono::NaiveDateTime::from_timestamp`: use `DateTime::from_timestamp` instead\n --> src/main.rs:6:36\n |\n6 | let naive_now = NaiveDateTime::from_timestamp(0, 0);\n | ^^^^^^^^^^^^^^\n |\n = note: `#[warn(deprecated)]` on by default\n\nerror[E0599]: no method named `to_rfc3339` found for struct `NaiveDateTime` in the current scope\n --> src/main.rs:10:35\n |\n10 | let naive_now_str = naive_now.to_rfc3339();\n | ^^^^^^^^^^ method not found in `NaiveDateTime`\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; 2 warnings emitted\n"} {"sample_index": 20, "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}\n\nfn main() {\n let person = Person {\n name: \"John\".to_string(),\n age: 30,\n };\n\n let serialized = serde_json::to_string(&person).unwrap();\n println!(\"serialized person = {}\", serialized);\n\n let deserialized: Person = serde_json::from_str(&serialized).unwrap();\n println!(\"deserialized person = {:?}\", deserialized);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: `Person` doesn't implement `Debug`\n --> src/main.rs:19:44\n |\n19 | println!(\"deserialized person = {:?}\", 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": 21, "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::{bail, Context, Result};\n\nfn main() -> Result<()> {\n let err = \"Error\".to_string();\n let err2 = \"Another error\".to_string();\n let res = \"Result\".to_string();\n\n match 1 + 1 {\n 1 => bail!(err),\n _ => Ok(()),\n }?;\n\n Ok(())\n}", "error_type": "other", "compile_error": "warning: unused import: `Context`\n --> src/main.rs:1:20\n |\n1 | use anyhow::{bail, Context, Result};\n | ^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0282]: type annotations needed\n --> src/main.rs:10:14\n |\n10 | _ => Ok(()),\n | ^^ cannot infer type of the type parameter `E` declared on the enum `Result`\n |\nhelp: consider specifying the generic arguments\n |\n10 | _ => Ok::<(), E>(()),\n | +++++++++\n\nerror[E0283]: type annotations needed\n --> src/main.rs:10:14\n |\n10 | _ => Ok(()),\n | ^^ cannot infer type of the type parameter `E` declared on the enum `Result`\n11 | }?;\n | - type must be known at this point\n |\n = note: multiple `impl`s satisfying `anyhow::Error: From<_>` found in the following crates: `anyhow`, `core`:\n - impl From for anyhow::Error\n where E: std::error::Error, E: Send, E: Sync, E: 'static;\n - impl,\n },\n}\n\nimpl std::fmt::Display for MyError {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n match self {\n Self::Error1 => write!(f, \"error 1\"),\n Self::Error2 { source } => write!(f, \"error 2: {}\", source),\n }\n }\n}\n\nfn run() -> Result<(), MyE", "error_type": "type_mismatch", "compile_error": "error: expected `;`, found `Err`\n --> src/main.rs:28:7\n |\n28 | }?\n | ^ help: add `;` here\n29 | Err(MyError::Error2 {\n | --- unexpected token\n\nerror[E0119]: conflicting implementations of trait `std::fmt::Display` for type `MyError`\n --> src/main.rs:1:10\n |\n1 | #[derive(thiserror::Error, Debug)]\n | ^^^^^^^^^^^^^^^^ conflicting implementation for `MyError`\n...\n12 | impl std::fmt::Display for MyError {\n | ---------------------------------- first implementation here\n |\n = note: this error originates in the derive macro `thiserror::Error` (in Nightly builds, run with -Z macro-backtrace for more info)\n\nFor more information about this error, try `rustc --explain E0119`.\nerror: could not compile `template_app` (bin \"template_app\") due to 2 previous errors\n"} {"sample_index": 28, "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)]\nstruct Hash32([u8; 32]);\n\nimpl FromStr for Hash32 {\n type Err = &'static str;\n\n fn from_str(s: &str) -> Result {\n if s.len()!= 32 {\n Err(\"Invalid hash length\")\n } else {\n let mut bytes = [0u8; 32];\n for (i, byte) in bytes.iter_mut().enumerate() {\n *byte = s.as_bytes()[i].into();\n }\n Ok(Hash32(bytes))\n }\n }\n}\n\nimpl std::fmt::Display for Hash32 {\n fn fmt(&self, f", "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 Hash32 {\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": 29, "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::{DateTime, DateTime, Local};\nuse chrono::format::PST;\n\nfn main() {\n let date = \"2021-04-01\";\n let parsed_date: DateTime = DateTime::parse_from_rfc3339(date).unwrap();\n let formatted_date = parsed_date.with_timezone(&PST).format(\"%A, %B %e, %Y %r\");\n println!(\"Date: {}\", formatted_date);\n\n let date = \"2021-03-01T12:00:00Z\";\n let parsed_date: DateTime = DateTime::parse_from_rfc3339(date).unwrap();\n let formatted_date = parsed_date.with_timezone(&PST).", "error_type": "type_mismatch", "compile_error": "error[E0252]: the name `DateTime` is defined multiple times\n --> src/main.rs:1:24\n |\n1 | use chrono::{DateTime, DateTime, Local};\n | -------- ^^^^^^^^--\n | | |\n | | `DateTime` reimported here\n | | help: remove unnecessary import\n | previous import of the type `DateTime` here\n |\n = note: `DateTime` must be defined only once in the type namespace of this module\n\nerror[E0432]: unresolved import `chrono::format::PST`\n --> src/main.rs:2:5\n |\n2 | use chrono::format::PST;\n | ^^^^^^^^^^^^^^^^^^^ no `PST` in `format`\n\nwarning: unused import: `DateTime`\n --> src/main.rs:1:24\n |\n1 | use chrono::{DateTime, DateTime, Local};\n | ^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0308]: mismatched types\n --> src/main.rs:6:40\n |\n6 | let parsed_date: DateTime = DateTime::parse_from_rfc3339(date).unwrap();\n | --------------"} {"sample_index": 31, "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;\n\n#[macro_use]\nextern crate serde_json;\n\nuse serde_json::Result;\n\n#[derive(Serialize, Deserialize, Debug)]\nstruct Person {\n name: String,\n age: u8,\n occupation: String,\n salary: f64,\n}\n\nfn main() -> Result<()> {\n let person = Person {\n name: \"John\".to_string(),\n age: 30,\n occupation: \"Software Developer\".to_string(),\n salary: 60000.0,\n };\n\n let json = serde_json::to_string(&person)?;\n println!(\"JSON: {}\", ", "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:9:10\n |\n9 | #[derive(Serialize, Deserialize, Debug)]\n | ^^^^^^^^^\n |\nhelp: consider importing this derive macro\n |\n7 + use serde::Serialize;\n |\n\nerror: cannot find derive macro `Deserialize` in this scope\n --> src/main.rs:9:21\n |\n9 | #[derive(Serialize, Deserialize, Debug)]\n | ^^^^^^^^^^^\n |\nhelp: consider importing this derive macro\n |\n7 + use serde::Deserialize;\n |\n\nwarning: unused `#[macro_use]` import\n --> src/main.rs:4:1\n |\n4 | #[macro_use]\n | ^^^^^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0277]: the trait bound `Person: serde::Serialize` is not satisfied\n --> src/main.rs:25:38\n |\n25 | let json = serde_json::to_string(&person)?;\n | --------------------- ^^"} {"sample_index": 32, "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::collections::HashMap;\n\nfn main() {\n let some_map = Some(HashMap::new());\n\n // Pattern matching with `match`\n match some_map {\n Some(map) => {\n println!(\"Matched Some: {:?}\", map);\n },\n None => {\n println!(\"Matched None\");\n },\n }\n\n // Pattern matching with `if let`\n if let Some(map) = some_map {\n println!(\"if let matched Some: {:?}\", map);\n } else {\n println!(\"if let matched None\");\n }\n}", "error_type": "other", "compile_error": "error[E0282]: type annotations needed\n --> src/main.rs:4:25\n |\n4 | let some_map = Some(HashMap::new());\n | ^^^^^^^^^^^^ cannot infer type of the type parameter `K` declared on the struct `HashMap`\n |\nhelp: consider specifying the generic arguments\n |\n4 | let some_map = Some(HashMap::::new());\n | ++++++++\n\nFor more information about this error, try `rustc --explain E0282`.\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 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::prelude::*;\nuse rand::Rng;\n\nfn main() {\n let mut rng = thread_rng();\n let mut random_number: u8 = rng.gen_range(1, 101);\n let mut random_number2: u8 = rng.gen_range(1, 101);\n let mut random_number3: u8 = rng.gen_range(1, 101);\n let mut random_number4: u8 = rng.gen_range(1, 101);\n\n let mut vec: Vec = Vec::new();\n vec.push(random_number);\n vec.push(random_number2);\n vec.push(random_number3);\n vec.push(random_number4);\n\n let random_item = rng.gen_range", "error_type": "trait_error", "compile_error": "error[E0277]: the trait bound `{integer}: SampleRange<_>` is not satisfied\n --> src/main.rs:6:47\n |\n6 | let mut random_number: u8 = rng.gen_range(1, 101);\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 we"} {"sample_index": 38, "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::fmt;\n\n#[derive(Error, Debug)]\nenum MyError {\n #[error(\"invalid input\")]\n InvalidInput,\n #[error(\"out of bounds\")]\n OutOfBounds,\n}\n\nimpl fmt::Display for MyError {\n fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {\n write!(f, \"{:?}\", self)\n }\n}\n\nfn process_input(input: &[u32]) -> Result<(), MyError> {\n let len = input.len();\n let idx = 2;\n\n if idx < len {\n Ok(())\n } else {\n Err(MyError::OutOfBounds)\n }\n}\n\nfn", "error_type": "other", "compile_error": "error[E0119]: conflicting implementations of trait `std::fmt::Display` for type `MyError`\n --> src/main.rs:4:10\n |\n4 | #[derive(Error, Debug)]\n | ^^^^^ conflicting implementation for `MyError`\n...\n12 | impl fmt::Display for MyError {\n | ----------------------------- first implementation here\n |\n = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)\n\nFor more information about this error, try `rustc --explain E0119`.\nerror: could not compile `template_app` (bin \"template_app\") due to 1 previous error\n"} {"sample_index": 39, "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, Display)]\nenum MyError {\n DivisionByZero,\n NegativeInput,\n StringEmpty,\n}\n\nimpl From for MyError {\n fn from(_: std::num::TryFromIntError) -> Self {\n MyError::DivisionByZero\n }\n}\n\nfn main() -> Result<(), MyError> {\n let result = try {\n let x = -1;\n let y = 0;\n if y == 0 {\n return Err(MyError::DivisionByZero);\n }\n Ok(x / y)\n } catch |e| {\n eprintln!(\"Error: ", "error_type": "undefined_variable", "compile_error": "error: keyword `catch` cannot follow a `try` block\n --> src/main.rs:22:7\n |\n22 | } catch |e| {\n | ^^^^^\n |\n = help: try using `match` on the result of the `try` block instead\n\nerror: cannot find derive macro `Display` in this scope\n --> src/main.rs:1:35\n |\n1 | #[derive(thiserror::Error, Debug, Display)]\n | ^^^^^^^\n\nerror[E0277]: `MyError` doesn't implement `std::fmt::Display`\n --> src/main.rs:2:6\n |\n2 | enum MyError {\n | ^^^^^^^ `MyError` cannot be formatted with the default formatter\n |\n = help: the trait `std::fmt::Display` is not implemented for `MyError`\n = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead\nnote: required by a bound in `std::error::Error`\n --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/error.rs:29:1\n\nFor more information about this error, try `rustc --explain E0277`.\nerror: could not compile `template_app` (bin \"template_app\") due to 3 previ"} {"sample_index": 40, "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::iter;\nuse std::ops::RangeInclusive;\n\nfn main() {\n let a: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n let b: Vec = (1..=10).collect();\n\n let sum_a: i32 = a.iter().filter(|&x| x % 2 == 0).sum();\n let sum_b: i32 = b.filter(|x| *x % 2 == 0).sum();\n\n assert_eq!(sum_a, sum_b);\n}", "error_type": "other", "compile_error": "warning: unused import: `std::iter`\n --> src/main.rs:1:5\n |\n1 | use std::iter;\n | ^^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nwarning: unused import: `std::ops::RangeInclusive`\n --> src/main.rs:2:5\n |\n2 | use std::ops::RangeInclusive;\n | ^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror[E0599]: no method named `filter` found for struct `Vec` in the current scope\n --> src/main.rs:9:24\n |\n9 | let sum_b: i32 = b.filter(|x| *x % 2 == 0).sum();\n | ^^^^^^ `Vec` is not an iterator\n |\nhelp: call `.into_iter()` first\n |\n9 | let sum_b: i32 = b.into_iter().filter(|x| *x % 2 == 0).sum();\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; 2 warnings emitted\n"} {"sample_index": 41, "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;\n\nuse serde_json::{json, Value};\n\n#[derive(Debug, Serialize, Deserialize)]\nstruct User {\n name: String,\n age: u8,\n email: String,\n}\n\nfn main() {\n let user = User {\n name: \"John\".to_string(),\n age: 30,\n email: \"john@example.com\".to_string(),\n };\n\n let json_user = serde_json::to_string(&user).unwrap();\n println!(\"JSON: {}\", json_user);\n\n let user_deserialized: User = serde_json::from_str(&json_user).unwrap();\n p", "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:6:17\n |\n6 | #[derive(Debug, Serialize, Deserialize)]\n | ^^^^^^^^^\n |\nhelp: consider importing this derive macro\n |\n4 + use serde::Serialize;\n |\n\nerror: cannot find derive macro `Deserialize` in this scope\n --> src/main.rs:6:28\n |\n6 | #[derive(Debug, Serialize, Deserialize)]\n | ^^^^^^^^^^^\n |\nhelp: consider importing this derive macro\n |\n4 + use serde::Deserialize;\n |\n\nwarning: unused imports: `Value` and `json`\n --> src/main.rs:4:18\n |\n4 | use serde_json::{json, Value};\n | ^^^^ ^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\nerror[E0277]: the trait bound `User: serde::Serialize` is not satisfied\n --> src/main.rs:20:43\n |\n20 | let json_user = serde_json::to_string"} {"sample_index": 44, "prompt": "Create a Rust program with a struct, an impl block, and a trait implementation. Include `fn main()` to demonstrate usage. Output only code in ```rust code blocks.", "code": "struct Point {\n x: i32,\n y: i32,\n}\n\nimpl Point {\n fn new(x: i32, y: i32) -> Self {\n Self { x, y }\n }\n\n fn distance_from_origin(&self) -> f64 {\n (self.x.pow(2) + self.y.pow(2)).sqrt() as f64\n }\n}\n\ntrait Colorful {\n fn color(&self) -> &'static str;\n}\n\nimpl Colorful for Point {\n fn color(&self) -> &'static str {\n if self.distance_from_origin() < 5.0 {\n \"red\"\n } else {\n \"blue\"\n }\n }\n}\n\nfn main() {\n let p1 = Point:", "error_type": "other", "compile_error": "error[E0599]: no method named `sqrt` found for type `i32` in the current scope\n --> src/main.rs:12:41\n |\n12 | (self.x.pow(2) + self.y.pow(2)).sqrt() as f64\n | ^^^^ method not found in `i32`\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": 45, "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 some_option: Option = Some(\"hello\".to_string());\n let none_option: Option = None;\n let some_string = String::from(\"hello\");\n\n // match\n match some_option {\n Some(value) => {\n println!(\"Got value: {}\", value);\n }\n None => {\n println!(\"Got nothing\");\n }\n }\n\n // if let\n if let Some(value) = some_option {\n println!(\"Got value: {}\", value);\n } else {\n println!(\"Got nothing\");\n ", "error_type": "type_mismatch", "compile_error": "error[E0308]: mismatched types\n --> src/main.rs:32:9\n |\n31 | match some_string {\n | ----------- this expression has type `String`\n32 | \"hello\" => {\n | ^^^^^^^ expected `String`, found `&str`\n\nerror[E0308]: mismatched types\n --> src/main.rs:35:9\n |\n31 | match some_string {\n | ----------- this expression has type `String`\n...\n35 | \"world\" => {\n | ^^^^^^^ expected `String`, found `&str`\n\nerror[E0308]: mismatched types\n --> src/main.rs:44:12\n |\n44 | if let \"hello\" = &some_string {\n | ^^^^^^^ ------------ this expression has type `&String`\n | |\n | expected `&String`, found `&str`\n |\n = note: expected reference `&String`\n found reference `&'static str`\n\nFor more information about this error, try `rustc --explain E0308`.\nerror: could not compile `template_app` (bin \"template_app\") due to 3 previous errors\n"} {"sample_index": 49, "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}\n\nfn main() {\n let person = Person {\n name: \"John\".to_string(),\n age: 30,\n };\n\n let serialized = serde_json::to_string(&person).unwrap();\n println!(\"serialized person = {}\", serialized);\n\n let deserialized: Person = serde_json::from_str(&serialized).unwrap();\n println!(\"deserialized person = {:#?}\", deserialized);\n}", "error_type": "trait_error", "compile_error": "error[E0277]: `Person` doesn't implement `Debug`\n --> src/main.rs:19:45\n |\n19 | println!(\"deserialized person = {:#?}\", 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"}