Superuser666-Sigil commited on
Commit
4cb9e7f
·
verified ·
1 Parent(s): dd0f5c7

Upload checkpoint-7000 evaluation samples

Browse files
Files changed (1) hide show
  1. checkpoint-7000/samples.jsonl +77 -0
checkpoint-7000/samples.jsonl ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"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 blocks.", "gen": "use anyhow::Result;\n\nfn main() -> Result<()> {\n let a = std::fs::File::open(\"nonexistant\")?;\n let _ = a.metadata()?;\n Ok(())\n}"}
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 blocks.", "gen": "use anyhow::anyhow;\nuse anyhow::Result;\n\nfn main() -> Result<()> {\n let s = \"this is a string\".to_string();\n let _ = s.parse::<u8>();\n Ok(())\n}"}
3
+ {"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 blocks.", "gen": "use anyhow::{bail, Result};\n\nfn main() -> Result<()> {\n // A Result type is a type that may have a value of one of two types. \n // The first type is called the \"Ok\" type. The second type is called the \"Err\" type.\n // The Err type is used for error handling.\n let result = Ok::<_, anyhow::Error>(42);\n println!(\"result is Ok: {}\", result.is_ok());\n\n // The? operator is used to convert an Err into an Ok. \n // This is used to propagate the error up the call stack.\n let result = Err::<(), anyhow::Error>(anyhow::anyhow!(\"error\"));\n println!(\"result is Err: {}\", result.is_err());\n\n // The? operator can also be used to return an Err from a function.\n // It does this by converting the Err into an Ok and returning the Ok.\n fn call_a() -> Result<(), anyhow::Error> {\n Err::<(), anyhow::Error>(anyhow::anyhow!(\"error\"))\n }\n\n let result = call_a()?;\n println!(\"result is Ok: {}\", result.is_ok());\n\n // If we have a? in a function and we want to do something before returning, \n // we can use the let Err function.\n fn call_b() -> Result<(), anyhow::Error> {\n let result = Err::<(), anyhow::Error>(anyhow::anyhow!(\"error\"));\n println!(\"result is Err: {}\", result.is_err());\n result\n }\n\n let result = call_b()?;\n println!(\"result is Ok: {}\", result.is_ok());\n\n // If we have a? in a function and we want to do something before returning, \n // we can use the let Err function.\n fn call_c() -> Result<(), anyhow::Error> {\n let result = Err::<(), anyhow::Error>(anyhow::anyhow!(\"error\"));\n println!(\"result is Err: {}\", result.is_err());\n result\n }\n\n let result = call_c()?;\n println!(\"result is Ok: {}\", result.is_ok());\n\n // If we want to catch an Err and handle it, we can use the match statement.\n fn call_d() -> Result<(), anyhow::Error> {\n let result = match Ok::<_, anyhow::Error>(42) {\n Ok(n) => Ok(n),\n Err(e) => Err(e),\n };\n println!(\"result is Ok: {}\", result.is_ok());\n result\n }\n\n let result = call_d()?;\n println!(\"result is Ok: {}\", result.is_ok());\n\n Ok(())\n}"}
4
+ {"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 blocks.", "gen": "use anyhow::Result;\n\nfn main() -> Result<()> {\n let x = 5 + 1;\n let y = x + 2;\n let z = x / 0;\n\n match z {\n Ok(_) => Ok(()),\n Err(e) => Err(e),\n }\n}"}
5
+ {"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 blocks.", "gen": "use anyhow::anyhow;\nuse anyhow::Context;\nuse anyhow::Result;\n\nfn main() -> Result<()> {\n let result = \"this is a string\".parse::<i32>().context(\"error parsing string to i32\")?;\n Ok(())\n}"}
6
+ {"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 blocks.", "gen": "use anyhow::anyhow;\nuse anyhow::bail;\nuse anyhow::Context;\nuse anyhow::ensure;\n\nfn main() -> anyhow::Result<()> {\n let number = 5;\n let number2 = 5;\n let mut number3 = 5;\n let number4 = 5;\n\n let err = anyhow!(\"Something went wrong\");\n let err2 = anyhow!(\"Something else went wrong\");\n\n let err3 = Context::new(err);\n let err4 = Context::new(err2);\n\n let err5 = err.context(\"Something went wrong\");\n let err6 = err2.context(\"Something else went wrong\");\n\n let err7 = ensure!(false, \"Something went wrong\");\n let err8 = ensure!(false, \"Something else went wrong\");\n\n let err9 = bail!(\"Something went wrong\");\n let err10 = bail!(\"Something else went wrong\");\n\n Ok(())\n}"}
7
+ {"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 blocks.", "gen": "use anyhow::Result;\nuse std::path::PathBuf;\n\nfn main() -> Result<()> {\n let path = PathBuf::from(\"non_existent_file\");\n let _ = std::fs::read_to_string(path)?;\n Ok(())\n}"}
8
+ {"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.", "gen": "use std::fs;\n\nfn main() {\n let contents = fs::read_to_string(\"test.txt\").expect(\"Something went wrong reading the file\");\n let nums: Vec<i32> = contents.lines().map(|s| s.parse::<i32>().unwrap()).collect();\n let sum = nums.into_iter().filter(|x| x % 2 == 0).sum::<i32>();\n println!(\"{}\", sum);\n}"}
9
+ {"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.", "gen": "use std::fs;\n\nfn main() {\n let file = \"data.txt\";\n let lines = fs::read_to_string(file).expect(\"file not found\");\n\n let numbers: Vec<i32> = lines.lines()\n .map(|x| x.parse().unwrap())\n .filter(|&x| x > 10)\n .collect();\n let sum: i32 = numbers.iter().sum();\n\n println!(\"Sum: {}\", sum);\n}"}
10
+ {"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.", "gen": "use std::collections::HashMap;\n\nfn main() {\n let map = vec![\"foo\", \"bar\", \"baz\", \"qux\", \"quux\", \"corge\", \"grault\", \"garply\"]\n .into_iter()\n .enumerate()\n .map(|(i, s)| (i, s.to_uppercase()))\n .collect::<HashMap<_, _>>();\n\n let sum: usize = map.iter()\n .filter(|&(_, &s)| s.starts_with(\"Q\"))\n .map(|&(_, &s)| s.len())\n .sum();\n println!(\"{}\", sum);\n}"}
11
+ {"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.", "gen": "fn main() {\n let mut sum = 0;\n let iter = (1..100).filter(|&x| x % 3 == 0 && x % 5 == 0).map(|x| x * 2);\n for n in iter {\n sum += n;\n }\n println!(\"{}\", sum);\n}"}
12
+ {"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.", "gen": "fn main() {\n let numbers = [2, 4, 6, 8, 10, 12, 14];\n let double_numbers: i32 = numbers\n .iter()\n .map(|x| x * 2)\n .filter(|x| *x < 20)\n .sum();\n println!(\"{}\", double_numbers);\n}"}
13
+ {"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.", "gen": "fn main() {\n let mut values = vec![10, 20, 30, 40, 50];\n let sum = values.iter().filter(|&x| x % 2 == 0).map(|x| x * 2).sum();\n println!(\"{}\", sum);\n}"}
14
+ {"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.", "gen": "fn main() {\n let mut numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n let numbers_even = numbers.iter().filter(|x| x % 2 == 0);\n let sum = numbers_even.clone().map(|x| x * x).sum::<i32>();\n println!(\"{}\", sum);\n}"}
15
+ {"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.", "gen": "struct Bytes32([u8; 32]);\n\nimpl FromStr for Bytes32 {\n type Err = String;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n let mut buf = [0u8; 32];\n if s.len()!= 32 {\n return Err(String::from(\"invalid length\"));\n }\n for (i, c) in s.bytes().enumerate() {\n if i >= 32 {\n return Err(String::from(\"invalid length\"));\n }\n buf[i] = c;\n }\n Ok(Bytes32(buf))\n }\n}\n\nimpl std::fmt::Display for Bytes32 {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n for &b in &self.0 {\n write!(f, \"{}\", b.to_string())?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let s = \"5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a\".to_string();\n let b = Bytes32::from_str(&s).unwrap();\n println!(\"{}\", b);\n}"}
16
+ {"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.", "gen": "// A wrapper for a 32 byte array of u8.\n#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]\npub struct Hash([u8; 32]);\n\n// Implement FromStr for Hash.\nimpl std::str::FromStr for Hash {\n type Err = String;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n if s.len()!= 32 {\n return Err(String::from(\"Input must be 32 bytes\"));\n }\n\n let mut hash = [0; 32];\n for (i, c) in s.chars().enumerate() {\n hash[i] = c as u8;\n }\n\n Ok(Hash(hash))\n }\n}\n\n// Implement Display for Hash.\nimpl std::fmt::Display for Hash {\n fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n for &c in &self.0 {\n write!(f, \"{:02x}\", c)?;\n }\n Ok(())\n }\n}"}
17
+ {"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.", "gen": "#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]\npub struct U32Bytes([u8; 32]);\n\nimpl FromStr for U32Bytes {\n type Err = String;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n if s.len()!= 32 {\n return Err(\"Length must be 32 bytes\".to_string());\n }\n let mut bytes = [0u8; 32];\n for (i, byte) in bytes.iter_mut().enumerate() {\n *byte = s.as_bytes()[i];\n }\n Ok(U32Bytes(bytes))\n }\n}\n\nimpl std::fmt::Display for U32Bytes {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n for byte in &self.0 {\n write!(f, \"{:02x}\", byte)?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let x = \"0000000000000000000000000000000000000000000000000000000000000000\".parse::<U32Bytes>().unwrap();\n println!(\"{:?}\", x);\n println!(\"{}\", x);\n}"}
18
+ {"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.", "gen": "pub struct Hash([u8; 32]);\n\nimpl FromStr for Hash {\n type Err = std::num::ParseIntError;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n let bytes = hex::decode(s).map_err(|_| Self::Err)?;\n if bytes.len()!= 32 {\n Err(Self::Err)\n } else {\n let mut hash = [0u8; 32];\n hash.copy_from_slice(&bytes);\n Ok(Hash(hash))\n }\n }\n}\n\nimpl std::fmt::Display for Hash {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n hex::encode(&self.0).fmt(f)\n }\n}"}
19
+ {"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.", "gen": "#[derive(Debug)]\nstruct U32Bytes([u8; 32]);\n\nimpl FromStr for U32Bytes {\n type Err = String;\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n match hex::decode(s) {\n Ok(bytes) => {\n if bytes.len()!= 32 {\n Err(\"Input is not 32 bytes long\".to_string())\n } else {\n Ok(U32Bytes(bytes.try_into().unwrap()))\n }\n }\n Err(_) => Err(\"Invalid hexadecimal string\".to_string()),\n }\n }\n}\n\nimpl std::fmt::Display for U32Bytes {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n write!(f, \"{}\", hex::encode(self.0))\n }\n}"}
20
+ {"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.", "gen": "struct Bech32<T>(pub T);\n\nimpl FromStr for Bech32<T> {\n type Err = String;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n if!s.starts_with(\"bc1q\") {\n return Err(String::from(\"must start with 'bc1q'\"));\n }\n\n let mut parts = s.splitn(2, ':');\n\n if parts.next().unwrap()!= \"q\" {\n return Err(String::from(\"invalid version\"));\n }\n\n let data = parts.next().unwrap();\n\n if data.len() % 2!= 0 {\n return Err(String::from(\"data must be even-length\"));\n }\n\n let mut bytes = [0; 32];\n for (i, c) in data.chars().enumerate() {\n let index = i / 2;\n let shift = (i % 2) * 5;\n let digit = match c {\n '0'..='9' => c.to_digit(10).unwrap() as u8,\n 'a'..='f' => c.to_digit(16).unwrap() as u8 + 10,\n _ => return Err(String::from(\"invalid character\")),\n };\n bytes[index] |= (digit << shift) & 0b11111;\n }\n\n Ok(Bech32(bytes))\n }\n}\n\nimpl Display for Bech32<T> {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n let mut buf = String::with_capacity(self.0.len() * 2 + 1);\n for &b in &self.0 {\n let b = b as u8;\n buf.push(if b < 10 { (b + b'0' as u8) as char } else { (b - 10 + b'a' as u8) as char });\n }\n buf.push(':');\n buf.push_str(&self.0[31].to_string());\n write!(f, \"{}\", buf)\n }\n}\n\nfn main() {\n let bech32 = Bech32([0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]);\n println!(\"{}\", bech32);\n}"}
21
+ {"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.", "gen": "struct Hash([u8; 32]);\n\nimpl FromStr for Hash {\n type Err = String;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n if s.len()!= 64 {\n return Err(\"invalid length\".to_string());\n }\n\n let mut hash = [0u8; 32];\n let mut i = 0;\n for byte in s.bytes() {\n if byte == b''{\n i += 1;\n continue;\n }\n\n hash[i / 2] |= (byte - b'0') as u8 << 4 * (i % 2);\n i += 1;\n }\n\n Ok(Hash(hash))\n }\n}\n\nimpl std::fmt::Display for Hash {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n let mut s = String::with_capacity(64);\n\n for byte in &self.0 {\n s.push_str(&format!(\"{:02x}\", byte));\n }\n\n f.write_str(&s)\n }\n}\n\nfn main() {\n let hash = \"0x1234567890abcdef0123456789abcdef\".parse::<Hash>().unwrap();\n println!(\"{}\", hash);\n}"}
22
+ {"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.", "gen": "use thiserror::Error;\n\n#[derive(Debug, Error)]\nenum MyError {\n #[error(\"error: {0}\")]\n Error(String),\n #[error(\"cause: {0}\")]\n Cause(Box<dyn std::error::Error + Send + Sync +'static>),\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::Error(msg) => write!(f, \"MyError: {}\", msg),\n Self::Cause(cause) => write!(f, \"MyError: {}\", cause),\n }\n }\n}\n\nfn main() -> Result<(), MyError> {\n let cause = std::io::Error::new(std::io::ErrorKind::NotFound, \"file not found\");\n let error = MyError::Cause(Box::new(cause));\n\n if let Err(e) = try_or_panic!(error) {\n eprintln!(\"error: {}\", e);\n }\n\n Ok(())\n}\n\nfn try_or_panic<T, E: std::error::Error + Send + Sync +'static>(\n value: Result<T, E>,\n) -> Result<T, MyError> {\n match value {\n Ok(value) => Ok(value),\n Err(err) => Err(MyError::Cause(Box::new(err))),\n }\n}\n\nfn try_or_panic_err<T, E: std::error::Error + Send + Sync +'static>(\n value: Result<T, E>,\n) -> Result<T, MyError> {\n match value {\n Ok(value) => Ok(value),\n Err(err) => Err(MyError::Error(err.to_string())),\n }\n}"}
23
+ {"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.", "gen": "use thiserror::Error;\nuse std::fmt;\n\n// A source cause for errors\n#[derive(Debug)]\npub enum Source {\n SourceA,\n SourceB,\n}\n\n// An error type\n#[derive(Debug, Error)]\n#[error(\"Error: {source}\")]\npub struct Error {\n pub source: Source,\n}\n\n// Implement Display for Error\nimpl fmt::Display for Error {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n write!(f, \"{}\", self.source)\n }\n}\n\n// A function using the? operator\nfn my_function() -> Result<(), Error> {\n let x = 5;\n\n if x < 10 {\n return Ok(());\n } else {\n return Err(Error { source: Source::SourceB });\n }\n}\n\n// A function calling my_function() with the? operator\nfn main() {\n let result = my_function();\n result.unwrap();\n}"}
24
+ {"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.", "gen": "use thiserror::Error;\n\n#[derive(thiserror::Error, Debug)]\npub enum MyError {\n #[error(\"cannot convert {0} to {1}\")]\n ConversionError(String, String),\n #[error(\"cannot read from {0}\")]\n ReadError(String),\n #[error(\"cannot write to {0}\")]\n WriteError(String),\n}\n\nimpl MyError {\n pub fn source(&self) -> Option<&(dyn std::error::Error +'static)> {\n None\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::ConversionError(a, b) => write!(f, \"cannot convert {} to {}\", a, b),\n Self::ReadError(a) => write!(f, \"cannot read from {}\", a),\n Self::WriteError(a) => write!(f, \"cannot write to {}\", a),\n }\n }\n}\n\nfn read_file(file_name: &str) -> Result<String, MyError> {\n Err(MyError::ReadError(file_name.to_string()))\n}\n\nfn convert_to_uppercase(s: String) -> Result<String, MyError> {\n Err(MyError::ConversionError(s, \"String\".to_string()))\n}\n\nfn write_file(file_name: &str, content: String) -> Result<(), MyError> {\n Err(MyError::WriteError(file_name.to_string()))\n}\n\nfn main() {\n let file_name = \"example.txt\";\n let content = \"hello world\";\n let _ = read_file(file_name)\n .and_then(|s| convert_to_uppercase(s))\n .and_then(|s| write_file(file_name, s));\n}"}
25
+ {"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.", "gen": "use std::fmt;\nuse thiserror::Error;\n\n#[derive(thiserror::Error, Debug)]\npub enum Error {\n #[error(\"Division by zero\")]\n DivisionByZero,\n #[error(\"Unknown\")]\n Unknown,\n #[error(\"Other\")]\n Other(String),\n}\n\nimpl fmt::Display for Error {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n write!(f, \"{:?}\", self)\n }\n}\n\nfn do_division(a: u32, b: u32) -> Result<u32, Error> {\n if b == 0 {\n Err(Error::DivisionByZero)\n } else {\n Ok(a / b)\n }\n}\n\nfn main() {\n let result = do_division(7, 0);\n match result {\n Ok(x) => println!(\"Result: {}\", x),\n Err(e) => println!(\"Error: {}\", e),\n }\n}"}
26
+ {"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.", "gen": "#[derive(thiserror::Error, Debug)]\nenum Error {\n #[error(\"Error in parsing {0}\")]\n ParseError(String),\n #[error(\"Error in reading file {0}\")]\n ReadError(String),\n}\n\nimpl std::fmt::Display for Error {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n match self {\n Self::ParseError(s) => write!(f, \"Error in parsing: {}\", s),\n Self::ReadError(s) => write!(f, \"Error in reading file: {}\", s),\n }\n }\n}\n\nfn main() -> Result<(), Error> {\n let s = \"42\";\n let res = u8::from_str_radix(s, 10)?;\n let file = std::fs::File::open(\"non-existent-file.txt\")?;\n Ok(())\n}"}
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.", "gen": "use thiserror::Error;\nuse std::io;\n\n#[derive(Error, Debug)]\nenum CustomError {\n #[error(\"Could not read from file: {0}\")]\n ReadFile(#[source] io::Error),\n #[error(\"Could not write to file: {0}\")]\n WriteFile(#[source] io::Error),\n}\n\nfn read_file(path: &str) -> Result<String, CustomError> {\n let contents = std::fs::read_to_string(path)?;\n Ok(contents)\n}\n\nfn write_file(path: &str, contents: &str) -> Result<(), CustomError> {\n let mut file = std::fs::File::create(path)?;\n file.write_all(contents.as_bytes())?;\n Ok(())\n}\n\nfn main() -> Result<(), CustomError> {\n let contents = read_file(\"file.txt\")?;\n write_file(\"file.txt\", &contents)?;\n Ok(())\n}"}
28
+ {"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.", "gen": "use thiserror::Error;\n\n#[derive(thiserror::Error, Debug)]\nenum Error {\n #[error(\"io error: {0}\")]\n Io(#[from] std::io::Error),\n #[error(\"not found\")]\n NotFound,\n}\n\nimpl std::fmt::Display for Error {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n use std::fmt::Display;\n write!(f, \"{:?}\", self)\n }\n}\n\nfn get_file() -> Result<(), Error> {\n let file = std::fs::File::open(\"non-existent-file\")?;\n Ok(())\n}\n\nfn main() -> Result<(), Error> {\n get_file()?;\n Ok(())\n}"}
29
+ {"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.", "gen": "// Enum for some basic animal types\nenum Animal {\n Cat,\n Dog,\n Mouse,\n}\n\nfn main() {\n // Some example animals\n let cat = Animal::Cat;\n let dog = Animal::Dog;\n let mouse = Animal::Mouse;\n\n // Example of `match` statement\n let animal = cat;\n match animal {\n Animal::Cat => println!(\"The animal is a cat\"),\n Animal::Dog => println!(\"The animal is a dog\"),\n Animal::Mouse => println!(\"The animal is a mouse\"),\n }\n\n // Example of `if let` statement\n let animal = mouse;\n if let Animal::Mouse = animal {\n println!(\"The animal is a mouse\");\n } else {\n println!(\"The animal is not a mouse\");\n }\n}"}
30
+ {"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.", "gen": "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 // Pattern matching with `match`\n let value = match map.get(\"a\") {\n Some(v) => v,\n None => &1,\n };\n\n println!(\"a = {}\", value);\n\n // Pattern matching with `if let`\n if let Some(v) = map.get(\"b\") {\n println!(\"b = {}\", v);\n }\n\n // Pattern matching with `if let`\n if let Some(v) = map.get(\"c\") {\n println!(\"c = {}\", v);\n }\n}"}
31
+ {"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.", "gen": "fn main() {\n let a = 5;\n let b = 10;\n let c = 'x';\n\n // match statement\n match a {\n 5 => println!(\"Five\"),\n 10 => println!(\"Ten\"),\n _ => println!(\"Not five or ten\"),\n }\n\n // if let statement\n if let Some(x) = Some(5) {\n println!(\"Got 5\");\n }\n if let Some(x) = Some(10) {\n println!(\"Got 10\");\n }\n if let Some(x) = Some('x') {\n println!(\"Got x\");\n }\n if let Some(x) = Some(6) {\n println!(\"Got 6\");\n }\n\n // let statements\n let a = Some(5);\n let b = Some(10);\n let c = Some('x');\n let d = Some(6);\n\n let Some(x) = a;\n let Some(y) = b;\n let Some(z) = c;\n let Some(_) = d;\n}"}
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.", "gen": "use std::io;\n\nfn main() {\n let input = \"hello\";\n\n // Match statement\n match input {\n \"hello\" => println!(\"match says hello\"),\n \"world\" => println!(\"match says world\"),\n _ => println!(\"match doesn't know what to say\"),\n }\n\n // If let statement\n if let Some(x) = Some(5) {\n println!(\"The value of x is: {}\", x);\n } else {\n println!(\"x is not some(5)\");\n }\n}"}
33
+ {"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.", "gen": "fn main() {\n let number = 1;\n\n match number {\n 1 => println!(\"One\"),\n 2 => println!(\"Two\"),\n _ => println!(\"Other\"),\n }\n\n let number = 1;\n\n if let 1 = number {\n println!(\"One\");\n } else {\n println!(\"Not one\");\n }\n}"}
34
+ {"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.", "gen": "fn main() {\n let number: i32 = 3;\n let string = \"hello world\";\n\n // Match with a single arm\n match number {\n 5 => println!(\"Five!\"),\n _ => println!(\"Not five\"),\n }\n\n // Match with multiple arms\n match number {\n 1 => println!(\"One\"),\n 2 => println!(\"Two\"),\n 3 => println!(\"Three\"),\n 4 => println!(\"Four\"),\n 5 => println!(\"Five!\"),\n _ => println!(\"Not five\"),\n }\n\n // Match with a guard\n let a = Some(5);\n match a {\n Some(x) if x == 5 => println!(\"Five!\"),\n Some(_) => println!(\"Not five\"),\n None => println!(\"None\"),\n }\n\n // Match with multiple guards\n match a {\n Some(x) if x == 5 => println!(\"Five!\"),\n Some(_) => println!(\"Not five\"),\n None => println!(\"None\"),\n }\n\n // Match with a tuple\n let tuple = (3, 5);\n match tuple {\n (1, _) => println!(\"One\"),\n (2, _) => println!(\"Two\"),\n (3, _) => println!(\"Three\"),\n (4, _) => println!(\"Four\"),\n (5, _) => println!(\"Five!\"),\n _ => println!(\"Not five\"),\n }\n\n // Match with a struct\n let struct_ = (1, \"a\", 2.0);\n match struct_ {\n (1, _, _) => println!(\"One\"),\n (2, _, _) => println!(\"Two\"),\n (3, _, _) => println!(\"Three\"),\n (4, _, _) => println!(\"Four\"),\n (5, _, _) => println!(\"Five!\"),\n _ => println!(\"Not five\"),\n }\n\n // Match with an enum\n let enum_ = Some(\"a\");\n match enum_ {\n None => println!(\"None\"),\n Some(_) => println!(\"Some\"),\n }\n\n // Match with an if let\n let option = Some(5);\n if let Some(5) = option {\n println!(\"Five!\");\n } else {\n println!(\"Not five\");\n }\n\n // Match with an if let multiple\n let option = Some(5);\n if let Some(5) = option {\n println!(\"Five!\");\n } else if let Some(4) = option {\n println!(\"Four!\");\n } else {\n println!(\"Not five or four\");\n }\n}"}
35
+ {"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.", "gen": "fn main() {\n let x = 10;\n\n match x {\n 0 => println!(\"x is zero\"),\n 1..=5 => println!(\"x is in the range 1..=5\"),\n 6..=10 => println!(\"x is in the range 6..=10\"),\n _ => println!(\"x is not between 0 and 10\"),\n }\n\n let x = 10;\n\n if let 0 = x {\n println!(\"x is zero\");\n } else if let 1..=5 = x {\n println!(\"x is in the range 1..=5\");\n } else if let 6..=10 = x {\n println!(\"x is in the range 6..=10\");\n } else {\n println!(\"x is not between 0 and 10\");\n }\n}"}
36
+ {"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.", "gen": "struct Person {\n name: String,\n age: u32,\n}\n\nimpl Person {\n fn new(name: &str, age: u32) -> Self {\n Self {\n name: name.to_string(),\n age,\n }\n }\n\n fn age_up(&mut self) {\n self.age += 1;\n }\n\n fn is_adult(&self) -> bool {\n self.age >= 18\n }\n}\n\ntrait Animal {\n fn name(&self) -> &str;\n}\n\nimpl Animal for Person {\n fn name(&self) -> &str {\n &self.name\n }\n}\n\nfn main() {\n let mut person = Person::new(\"John\", 17);\n println!(\"Person name is {}\", person.name());\n println!(\"Person is an adult: {}\", person.is_adult());\n person.age_up();\n println!(\"Person age is now {}\", person.age);\n}"}
37
+ {"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.", "gen": "struct Dog {\n name: String,\n age: u8,\n}\n\nimpl Dog {\n fn speak(&self) {\n println!(\"Woof!\");\n }\n}\n\ntrait Pet {\n fn speak(&self) -> String;\n}\n\nimpl Pet for Dog {\n fn speak(&self) -> String {\n let mut output = String::new();\n self.speak();\n output += \" Woof!\";\n output\n }\n}\n\nfn main() {\n let mut dog = Dog {\n name: String::from(\"Fido\"),\n age: 5,\n };\n dog.speak();\n println!(\"{}\", dog.speak());\n}"}
38
+ {"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.", "gen": "#[derive(Debug)]\nstruct Rectangle {\n width: i32,\n height: i32,\n}\n\nimpl Rectangle {\n fn area(&self) -> i32 {\n self.width * self.height\n }\n}\n\nimpl Clone for Rectangle {\n fn clone(&self) -> Self {\n Self {\n width: self.width,\n height: self.height,\n }\n }\n}\n\nfn main() {\n let rect1 = Rectangle { width: 10, height: 20 };\n let rect2 = rect1.clone();\n println!(\"Rect1: {:?}\", rect1);\n println!(\"Rect2: {:?}\", rect2);\n println!(\"Area: {}\", rect1.area());\n}"}
39
+ {"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.", "gen": "struct MyStruct {\n x: i32,\n y: i32,\n}\n\nimpl MyStruct {\n fn add(&self, rhs: i32) -> i32 {\n self.x + rhs\n }\n}\n\nimpl std::ops::Add<i32> for MyStruct {\n type Output = i32;\n fn add(self, rhs: i32) -> i32 {\n self.add(rhs)\n }\n}\n\nfn main() {\n let mut s = MyStruct { x: 1, y: 2 };\n let s2 = MyStruct { x: 3, y: 4 };\n assert_eq!(s.add(1), 2);\n assert_eq!(s + 2, 3);\n assert_eq!(s2 + 5, 8);\n}"}
40
+ {"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.", "gen": "#[derive(Debug)]\nstruct Rectangle {\n width: u32,\n height: u32,\n}\n\nimpl Rectangle {\n fn area(&self) -> u32 {\n self.width * self.height\n }\n}\n\nimpl Rectangle {\n fn can_hold(&self, other: &Rectangle) -> bool {\n self.width > other.width && self.height > other.height\n }\n\n fn square(size: u32) -> Rectangle {\n Rectangle { width: size, height: size }\n }\n}\n\nfn main() {\n let rect1 = Rectangle {\n width: 30,\n height: 50,\n };\n let rect2 = Rectangle {\n width: 10,\n height: 40,\n };\n let rect3 = Rectangle {\n width: 60,\n height: 45,\n };\n\n println!(\"Can rect1 hold rect2? {}\", rect1.can_hold(&rect2));\n println!(\"Can rect1 hold rect3? {}\", rect1.can_hold(&rect3));\n println!(\"Can rect2 hold rect1? {}\", rect2.can_hold(&rect1));\n println!(\"Can rect3 hold rect1? {}\", rect3.can_hold(&rect1));\n\n let sq1 = Rectangle::square(10);\n println!(\"Area of rect1: {}\", rect1.area());\n println!(\"Area of sq1: {}\", sq1.area());\n}"}
41
+ {"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.", "gen": "struct Point {\n x: i32,\n y: i32,\n}\n\nimpl Point {\n fn new(x: i32, y: i32) -> Point {\n Point { x, y }\n }\n\n fn get_distance(&self, other: &Point) -> f64 {\n ((self.x - other.x) * (self.x - other.x) + (self.y - other.y) * (self.y - other.y)).sqrt() as f64\n }\n}\n\ntrait HasArea {\n fn get_area(&self) -> i32;\n}\n\nimpl HasArea for Point {\n fn get_area(&self) -> i32 {\n (self.x * self.x + self.y * self.y).sqrt() as i32\n }\n}\n\nfn main() {\n let p1 = Point::new(2, 2);\n let p2 = Point::new(3, 3);\n println!(\"Distance between points is {}\", p1.get_distance(&p2));\n println!(\"Area of point p1 is {}\", p1.get_area());\n}"}
42
+ {"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.", "gen": "// The Shape trait\ntrait Shape {\n fn area(&self) -> f64;\n fn perimeter(&self) -> f64;\n}\n\n// A Circle struct\nstruct Circle {\n radius: f64,\n}\n\n// An implementation of the Circle struct\nimpl Circle {\n // Constructor\n fn new(radius: f64) -> Circle {\n Circle { radius }\n }\n}\n\n// An implementation of the Shape trait for the Circle struct\nimpl Shape for Circle {\n // Calculates the area of a Circle\n fn area(&self) -> f64 {\n std::f64::consts::PI * (self.radius * self.radius)\n }\n\n // Calculates the perimeter of a Circle\n fn perimeter(&self) -> f64 {\n 2.0 * std::f64::consts::PI * self.radius\n }\n}\n\n// A Square struct\nstruct Square {\n side: f64,\n}\n\n// An implementation of the Square struct\nimpl Square {\n // Constructor\n fn new(side: f64) -> Square {\n Square { side }\n }\n}\n\n// An implementation of the Shape trait for the Square struct\nimpl Shape for Square {\n // Calculates the area of a Square\n fn area(&self) -> f64 {\n self.side * self.side\n }\n\n // Calculates the perimeter of a Square\n fn perimeter(&self) -> f64 {\n 4.0 * self.side\n }\n}\n\n// The main function\nfn main() {\n // A Circle\n let circle = Circle::new(5.0);\n\n // A Square\n let square = Square::new(5.0);\n\n // Print the results\n println!(\"Circle area: {}\", circle.area());\n println!(\"Circle perimeter: {}\", circle.perimeter());\n println!(\"Square area: {}\", square.area());\n println!(\"Square perimeter: {}\", square.perimeter());\n}"}
43
+ {"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.", "gen": "use serde::{Deserialize, Serialize};\n\n#[derive(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: 30,\n };\n\n let json = serde_json::to_string(&person).unwrap();\n println!(\"{}\", json);\n\n let person2: Person = serde_json::from_str(&json).unwrap();\n println!(\"Person 2's name is {} {}\", person2.first_name, person2.last_name);\n}"}
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.", "gen": "use serde::{Deserialize, Serialize};\nuse serde_json;\n\n#[derive(Serialize, Deserialize)]\nstruct Person {\n name: String,\n age: u8,\n phone: String,\n}\n\nfn main() {\n let person = Person {\n name: \"John\".to_string(),\n age: 42,\n phone: \"123456\".to_string(),\n };\n\n let json = serde_json::to_string(&person).unwrap();\n println!(\"Serialized person as json: {}\", json);\n\n let deserialized: Person = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized json into person: {:?}\", deserialized);\n}"}
45
+ {"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.", "gen": "use serde::{Deserialize, Serialize};\n\n#[derive(Serialize, Deserialize)]\nstruct Point {\n x: f32,\n y: f32,\n}\n\nfn main() {\n let point = Point { x: 1.0, y: 2.0 };\n let serialized = serde_json::to_string(&point).unwrap();\n println!(\"Serialized: {}\", serialized);\n\n let deserialized: Point = serde_json::from_str(&serialized).unwrap();\n println!(\"Deserialized: {:?}\", deserialized);\n}"}
46
+ {"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.", "gen": "use serde_derive::{Deserialize, Serialize};\nuse serde_json;\n\n#[derive(Serialize, Deserialize)]\nstruct Book {\n title: String,\n author: String,\n price: f32,\n published: i32,\n}\n\nfn main() {\n let book = Book {\n title: String::from(\"The Name of the Wind\"),\n author: String::from(\"Patrick Rothfuss\"),\n price: 15.99,\n published: 2007,\n };\n\n let serialized_book = serde_json::to_string(&book).unwrap();\n let deserialized_book: Book = serde_json::from_str(&serialized_book).unwrap();\n\n println!(\"Original book: {:#?}\", book);\n println!(\"Serialized book: {}\", serialized_book);\n println!(\"Deserialized book: {:#?}\", deserialized_book);\n}"}
47
+ {"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.", "gen": "use serde::{Deserialize, Serialize};\n\n#[derive(Serialize, Deserialize)]\nstruct User {\n id: u32,\n username: String,\n email: String,\n active: bool,\n}\n\nfn main() {\n let user = User {\n id: 1,\n username: \"admin\".to_string(),\n email: \"[email protected]\".to_string(),\n active: true,\n };\n\n let serialized = serde_json::to_string(&user).unwrap();\n println!(\"serialized = {}\", serialized);\n\n let deserialized: User = serde_json::from_str(&serialized).unwrap();\n println!(\"deserialized = {:?}\", deserialized);\n}"}
48
+ {"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.", "gen": "use serde::{Deserialize, Serialize};\n\n#[derive(Serialize, Deserialize)]\nstruct Person {\n name: String,\n age: u8,\n addresses: Vec<String>,\n}\n\nfn main() {\n let mut person = Person {\n name: \"John\".to_string(),\n age: 30,\n addresses: vec![\"123 Main St\".to_string(), \"456 Elm St\".to_string()],\n };\n\n let serialized = serde_json::to_string(&person).unwrap();\n println!(\"Serialized Person: {}\", serialized);\n\n let deserialized_person: Person = serde_json::from_str(&serialized).unwrap();\n println!(\"Deserialized Person: {:?}\", deserialized_person);\n}"}
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.", "gen": "use serde::{Deserialize, Serialize};\n\n#[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: 32,\n };\n\n let serialized = serde_json::to_string(&person).unwrap();\n println!(\"serialized = {}\", serialized);\n\n let deserialized: Person = serde_json::from_str(&serialized).unwrap();\n println!(\"deserialized = {:?}\", deserialized);\n}"}
50
+ {"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.", "gen": "use regex::Regex;\n\nfn main() {\n let text = \"The quick brown fox jumps over the lazy dog.\";\n\n let regex = Regex::new(r\"\\bfox\\b\").unwrap();\n let new_text = regex.replace_all(&text, \"bear\").to_string();\n println!(\"{}\", new_text);\n}"}
51
+ {"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.", "gen": "use regex::Regex;\n\nfn main() {\n let text = \"Hello, world! How's it going? Goodbye, world!\";\n\n let regex = Regex::new(r\"world\").unwrap();\n let replaced = regex.replace_all(&text, \"Rustacean\");\n\n println!(\"{}\", replaced);\n}"}
52
+ {"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.", "gen": "use regex::Regex;\n\nfn main() {\n let text = \"My phone number is 1-800-555-MEOW, and I have 1,000,000,000,000,000,000,000 of them.\";\n let re = Regex::new(r\"\\d+\").unwrap();\n let replaced = re.replace_all(&text, \"x\");\n println!(\"{}\", replaced);\n}"}
53
+ {"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.", "gen": "use regex::Regex;\n\nfn main() {\n let text = \"My name is John and my name is Jane.\";\n let re = Regex::new(r\"\\b\\w+\\b\").unwrap();\n let replaced = re.replace_all(&text, \"Name\").to_string();\n println!(\"{}\", replaced);\n}"}
54
+ {"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.", "gen": "extern crate regex;\n\nuse regex::Regex;\n\nfn main() {\n let mut text = \"I have a dog. I also have a cat. The dog is cool. The cat is cute.\";\n let mut regex = Regex::new(r\"dog|cat\").unwrap();\n let new_text = regex.replace_all(&text, \"bird\");\n println!(\"{}\", new_text);\n}"}
55
+ {"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.", "gen": "use regex::Regex;\n\nfn main() {\n let re = Regex::new(r\"(\\d{3}-\\d{3}-\\d{4})\").unwrap();\n let text = \"My phone number is 123-456-7890 and my friend's phone number is 987-654-3210\";\n let new_text = re.replace_all(&text, |cap: &regex::Captures| {\n format!(\"XXX-XXX-XXXX\", XXX = cap[1])\n });\n\n println!(\"{}\", new_text);\n}"}
56
+ {"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.", "gen": "use regex::Regex;\n\nfn main() {\n let text = \"This is an example of a string with 2 words. The first word is \\\"example\\\" and the second word is \\\"string\\\".\";\n let re = Regex::new(r\"\\b\\w+\\b\").unwrap();\n let new_text = re.replace_all(&text, \"word\");\n println!(\"{}\", new_text);\n}"}
57
+ {"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.", "gen": "use chrono::prelude::*;\nuse chrono::offset::TimeZone;\nuse chrono::offset::LocalResult;\nuse chrono::format::ParseError;\n\nfn main() {\n // Example 1: Parsing a date string with no time zone information\n let date = Local.with_offset(&chrono::offset::LocalResult::Single(LocalOffset::east(4)));\n let parsed_date = date\n .parse(\"2020-01-01 12:00\")\n .expect(\"Failed to parse date\");\n\n let formatted_date = parsed_date.format(\"%Y-%m-%d\").to_string();\n println!(\"{}\", formatted_date);\n\n // Example 2: Parsing a date string with time zone information\n let date = Local.with_offset(&chrono::offset::LocalResult::Single(LocalOffset::east(4)));\n let parsed_date = date\n .parse(\"2020-01-01 12:00 EST\")\n .expect(\"Failed to parse date\");\n\n let formatted_date = parsed_date.format(\"%Y-%m-%d\").to_string();\n println!(\"{}\", formatted_date);\n}"}
58
+ {"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.", "gen": "use chrono::prelude::*;"}
59
+ {"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.", "gen": "use chrono::{DateTime, DateTime, TimeZone, Utc};\nuse chrono::format::{Pc500, StrftimeFormat, StrftimeItems};\nuse chrono::offset::TimeZone;\nuse chrono::format::{strftime, Strftime};"}
60
+ {"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.", "gen": "use chrono::format::{FormatItem, ParseError, Parsed, ParseResult};\nuse chrono::format::strftime::StrftimeItems;\nuse chrono::format::parse::ParsedLiteral;\nuse chrono::format::strftime::StrftimeItemsWithZone;\nuse chrono::format::strptime::{parse, StrftimeError};\nuse chrono::format::strptime::{ParseError as PStrptimeError, StrptimeItems};\nuse chrono::format::DateParseError;\nuse chrono::format::Fixed::Fixed;\nuse chrono::format::Item::{FixedNum, Literal};\nuse chrono::format::ParsedFixed;\nuse chrono::format::ParsedLiteral::Numeric;\nuse chrono::format::ParsedItem::{Date, Time, Timezone};\nuse chrono::format::ParsedTime::{AmPm, Era, Hour12, Hour24, Millisecond, Minute, Month, Second};\nuse chrono::format::Weekday::{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};\nuse chrono::format::Year::Year2000;\nuse chrono::prelude::*;\nuse chrono::DateTime;\n\nfn parse_date(s: &str) -> Result<DateTime<FixedOffset>, ParseError> {\n parse(s, \"%Y-%m-%d\")\n}\n\nfn parse_time(s: &str) -> Result<DateTime<FixedOffset>, ParseError> {\n parse(s, \"%H:%M:%S\")\n}\n\nfn parse_datetime(s: &str) -> Result<DateTime<FixedOffset>, ParseError> {\n parse(s, \"%Y-%m-%d %H:%M:%S\")\n}\n\nfn parse_datetime_timezone(s: &str) -> Result<DateTime<FixedOffset>, ParseError> {\n parse(s, \"%Y-%m-%d %H:%M:%S %Z\")\n}\n\nfn main() {\n let datetime = \"2014-12-24 11:30:30 UTC\";\n let date = \"2014-12-24\";\n let time = \"11:30:30\";\n\n let parsed_datetime = parse_datetime(datetime).unwrap();\n let parsed_date = parse_date(date).unwrap();\n let parsed_time = parse_time(time).unwrap();\n\n println!(\"Parsed DateTime: {:?}\", parsed_datetime);\n println!(\"Parsed Date: {:?}\", parsed_date);\n println!(\"Parsed Time: {:?}\", parsed_time);\n}"}
61
+ {"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.", "gen": "use chrono::{DateTime, Local};"}
62
+ {"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.", "gen": "use chrono::{DateTime, Datelike, Local, TimeZone, Timelike};\nuse chrono::format::Perc3;\nuse chrono::format::Item::{Fixed, Pad, Wide};\nuse chrono::format::{DateTimeFormat, Date, Item, Time};"}
63
+ {"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.", "gen": "use chrono::{DateTime, DateTime, NaiveDate, NaiveDateTime, Utc};\nuse std::time::SystemTime;\n\nfn main() {\n let d1 = DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2021, 1, 1), Utc);\n let d2 = NaiveDate::from_ymd(2021, 1, 2);\n let d3 = SystemTime::now();\n let d4 = NaiveDateTime::from_timestamp(0, 0);\n\n println!(\"{}\", d1.format(\"%a %b %e %T %Y\").to_string());\n println!(\"{}\", d2.format(\"%a %b %e %T %Y\").to_string());\n println!(\"{}\", d3.format(\"%a %b %e %T %Y\").to_string());\n println!(\"{}\", d4.format(\"%a %b %e %T %Y\").to_string());\n}"}
64
+ {"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.", "gen": "use uuid::Uuid;\n\nfn main() {\n let random_uuid = Uuid::new_v4();\n println!(\"Random UUID: {:?}\", random_uuid);\n\n let random_uuids: Vec<Uuid> = (0..10).map(|_| Uuid::new_v4()).collect();\n println!(\"Random UUIDs: {:?}\", random_uuids);\n\n let named_uuid = Uuid::parse_str(\"00000000-0000-0000-0000-000000000000\").unwrap();\n println!(\"Named UUID: {:?}\", named_uuid);\n\n let named_uuids: Vec<Uuid> = (0..10).map(|_| Uuid::parse_str(\"00000000-0000-0000-0000-000000000000\").unwrap()).collect();\n println!(\"Named UUIDs: {:?}\", named_uuids);\n}"}
65
+ {"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.", "gen": "use uuid::Uuid;\n\nfn main() {\n let a = Uuid::new_v4();\n let b = Uuid::parse_str(\"4a9a1e4c-9a86-4b7a-b6a4-9e6d3c1b9d3b\").unwrap();\n let c = Uuid::new_v5(&Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n\n println!(\"{:#?} {:#?} {:#?}\", a, b, c);\n}"}
66
+ {"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.", "gen": "use uuid::Uuid;\n\nfn main() {\n let uuid_v4 = Uuid::new_v4();\n println!(\"UUID v4: {:?}\", uuid_v4);\n\n let uuid_v5 = Uuid::new_v5(&Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n println!(\"UUID v5: {:?}\", uuid_v5);\n\n let uuid_v5_2 = Uuid::new_v5(&Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n println!(\"UUID v5: {:?}\", uuid_v5_2);\n}"}
67
+ {"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.", "gen": "use uuid::Uuid;\n\nfn main() {\n let random_uuid = Uuid::new_v4();\n let random_uuid2 = Uuid::new_v4();\n let random_uuid3 = Uuid::new_v4();\n let random_uuid4 = Uuid::new_v4();\n let random_uuid5 = Uuid::new_v4();\n let random_uuid6 = Uuid::new_v4();\n println!(\"{}, {}, {}, {}, {}, {}\", random_uuid, random_uuid2, random_uuid3, random_uuid4, random_uuid5, random_uuid6);\n}"}
68
+ {"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.", "gen": "use uuid::Uuid;\n\nfn main() {\n println!(\"UUID v4: {}\", Uuid::new_v4().to_string());\n println!(\"UUID v5: {}\", Uuid::new_v5(&Uuid::nil(), \"test\".as_bytes()).to_string());\n println!(\"UUID v5: {}\", Uuid::new_v5(&Uuid::nil(), \"test\".as_bytes()).to_string());\n}"}
69
+ {"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.", "gen": "use uuid::Uuid;\n\nfn main() {\n println!(\"UUID v1: {}\", Uuid::new_v1().to_string());\n println!(\"UUID v4: {}\", Uuid::new_v4().to_string());\n}"}
70
+ {"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.", "gen": "use uuid::Uuid;\n\nfn main() {\n let uuid_v4 = Uuid::new_v4();\n let uuid_v5 = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n println!(\"UUID v4: {}\", uuid_v4.to_string());\n println!(\"UUID v5: {}\", uuid_v5.to_string());\n}"}
71
+ {"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.", "gen": "use rand::prelude::*;\n\nfn main() {\n let mut rng = thread_rng();\n\n let my_vec: Vec<i32> = (0..100).collect();\n\n println!(\"Random items from vector: \");\n\n let n: i32 = rng.gen_range(1, 10);\n for _ in 0..n {\n let i: usize = rng.gen_range(0, my_vec.len());\n println!(\"{}\", my_vec[i]);\n }\n}"}
72
+ {"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.", "gen": "use rand::prelude::*;\n\nfn main() {\n let numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n let random_number = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number);\n\n let random_number2 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number2);\n\n let random_number3 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number3);\n\n let random_number4 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number4);\n\n let random_number5 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number5);\n\n let random_number6 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number6);\n\n let random_number7 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number7);\n\n let random_number8 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number8);\n\n let random_number9 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number9);\n\n let random_number10 = thread_rng().gen_range(0, 10);\n println!(\"Random number: {}\", random_number10);\n\n let random_item = thread_rng().gen_range(0, 10);\n let item = numbers[random_item as usize];\n println!(\"Random number: {}\", item);\n\n let random_item2 = thread_rng().gen_range(0, 10);\n let item2 = numbers[random_item2 as usize];\n println!(\"Random number: {}\", item2);\n\n let random_item3 = thread_rng().gen_range(0, 10);\n let item3 = numbers[random_item3 as usize];\n println!(\"Random number: {}\", item3);\n\n let random_item4 = thread_rng().gen_range(0, 10);\n let item4 = numbers[random_item4 as usize];\n println!(\"Random number: {}\", item4);\n\n let random_item5 = thread_rng().gen_range(0, 10);\n let item5 = numbers[random_item5 as usize];\n println!(\"Random number: {}\", item5);\n\n let random_item6 = thread_rng().gen_range(0, 10);\n let item6 = numbers[random_item6 as usize];\n println!(\"Random number: {}\", item6);\n\n let random_item7 = thread_rng().gen_range(0, 10);\n let item7 = numbers[random_item7 as usize];\n println!(\"Random number: {}\", item7);\n\n let random_item8 = thread_rng().gen_range(0, 10);\n let item8 = numbers[random_item8 as usize];\n println!(\"Random number: {}\", item8);\n\n let random_item9 = thread_rng().gen_range(0, 10);\n let item9 = numbers[random_item9 as usize];\n println!(\"Random number: {}\", item9);\n\n let random_item10 = thread_rng().gen_range(0, 10);\n let item10 = numbers[random_item10 as usize];\n println!(\"Random number: {}\", item10);\n}"}
73
+ {"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.", "gen": "use rand::prelude::*;\n\nfn main() {\n let mut rng = thread_rng();\n let numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n for _ in 0..5 {\n println!(\"{}\", numbers[rng.gen_range(0..numbers.len())]);\n }\n}"}
74
+ {"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.", "gen": "use rand::Rng;\nuse std::collections::HashSet;\n\nfn main() {\n let mut rng = rand::thread_rng();\n let mut numbers = (1..100).collect::<HashSet<i32>>();\n let mut selected: Vec<i32> = Vec::new();\n\n loop {\n let num = rng.gen_range(1..100);\n if numbers.remove(&num) {\n selected.push(num);\n }\n if selected.len() == 50 {\n break;\n }\n }\n\n println!(\"Random numbers:\");\n for num in &selected {\n println!(\"{}\", num);\n }\n}"}
75
+ {"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.", "gen": "use rand::Rng;\nuse rand::distributions::Uniform;\n\nfn main() {\n let numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n let mut rng = rand::thread_rng();\n let mut choice: usize = 0;\n loop {\n choice = rng.sample(Uniform::new_inclusive(0, numbers.len() - 1));\n println!(\"Random number is {}\", numbers[choice]);\n }\n}"}
76
+ {"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.", "gen": "use rand::Rng;\nuse std::collections::HashMap;\n\nfn main() {\n let mut rng = rand::thread_rng();\n let mut selected = HashMap::new();\n let mut items = HashMap::new();\n let mut count = 0;\n\n items.insert(\"A\", 1);\n items.insert(\"B\", 2);\n items.insert(\"C\", 3);\n items.insert(\"D\", 4);\n items.insert(\"E\", 5);\n\n loop {\n let choice = items.keys().nth(rng.gen_range(0, items.len())).unwrap();\n if selected.contains_key(choice) {\n continue;\n }\n selected.insert(choice, items[choice]);\n count += 1;\n if count == 5 {\n break;\n }\n }\n\n println!(\"Selected items: {:#?}\", selected);\n}"}
77
+ {"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.", "gen": "use rand::prelude::*;\n\nfn main() {\n let mut rng = thread_rng();\n\n let mut vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n for _ in 0..5 {\n let index: usize = rng.gen_range(0..vec.len());\n let element = vec.swap_remove(index);\n println!(\"{}\", element);\n }\n}"}