Superuser666-Sigil commited on
Commit
0c2c0c1
·
verified ·
1 Parent(s): 0713d5b

Upload checkpoint-5000 evaluation samples

Browse files
Files changed (1) hide show
  1. checkpoint-5000/samples.jsonl +77 -0
checkpoint-5000/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() -> anyhow::Result<()> {\n let x = \"foo\".parse::<i32>()?;\n let y = \"bar\".parse::<i32>()?;\n let z = 3 + x + y;\n let w = \"baz\".parse::<i32>()?;\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::Result;\nuse std::io;\nuse std::io::Read;\nuse std::fs::File;\n\nfn main() -> Result<()> {\n let mut file = File::open(\"nonexistent.txt\")?;\n let mut buffer = String::new();\n file.read_to_string(&mut buffer)?;\n println!(\"{}\", buffer);\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;\nuse anyhow::anyhow;\nuse anyhow::Context;\nuse anyhow::bail;\n\nfn main() -> Result<()> {\n let x = 5;\n let y = 0;\n let a = x / y;\n if a == 0 {\n bail!(\"division by zero\");\n }\n println!(\"a = {}\", a);\n Ok(())\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::Result;\n\nfn main() -> Result<()> {\n let a: Result<String, std::num::ParseIntError> = \"a\".parse::<i32>();\n let b: Result<String, std::io::Error> = std::fs::read_to_string(\"nonexistent\");\n let c: Result<(), std::env::VarError> = std::env::var(\"nonexistent\");\n let d: Result<(), anyhow::Error> = Err(anyhow::anyhow!(\"oh no\"));\n\n a?;\n b?;\n c?;\n d?;\n\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::Result;\nuse std::io;\n\nfn main() -> Result<()> {\n let x = 10;\n let y = 0;\n let z = x / y;\n\n match z {\n Ok(_) => Ok(()),\n Err(e) => Err(anyhow!(e)),\n }\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::{Context, Result};\n\nfn main() -> Result<()> {\n let result = std::env::var(\"PATH\").context(\"failed to get PATH\")?;\n println!(\"{}\", result);\n\n let result = std::env::var(\"PATH\").context(\"failed to get PATH\")?;\n println!(\"{}\", result);\n\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::File;\nuse std::io::{BufRead, BufReader};\n\nfn main() {\n let file = File::open(\"numbers.txt\").expect(\"Could not open file\");\n let numbers: Vec<i64> = BufReader::new(file)\n .lines()\n .map(|line| line.expect(\"Could not read line\").parse::<i64>().expect(\"Could not parse\"))\n .filter(|&n| n > 10)\n .collect();\n\n println!(\"{}\", numbers.iter().sum::<i64>());\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": "fn main() {\n let mut sum: u32 = 0;\n let mut numbers = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n let filtered = numbers.into_iter().filter(|&x| x % 2 == 0);\n let mapped = filtered.map(|x| x * 2);\n for num in mapped {\n sum += num;\n }\n println!(\"{}\", 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::fs;\n\nfn main() {\n let input = fs::read_to_string(\"input.txt\").unwrap();\n let numbers: Vec<i32> = input.lines()\n .map(|line| line.parse::<i32>().unwrap())\n .collect();\n let sum: i32 = numbers.iter()\n .filter(|&x| x > 0)\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": "use std::collections::HashMap;\n\nfn main() {\n let mut numbers = HashMap::new();\n numbers.insert(\"one\".to_string(), 1);\n numbers.insert(\"two\".to_string(), 2);\n numbers.insert(\"three\".to_string(), 3);\n\n let sum = numbers\n .iter()\n .filter(|(_, v) => v % 2 == 0)\n .map(|(_, v) => v)\n .sum::<i32>();\n\n println!(\"The sum of even numbers is: {}\", 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": "use std::fs;\nuse std::io::prelude::*;\nuse std::env;\n\nfn main() {\n let args: Vec<String> = env::args().collect();\n if args.len() < 2 {\n eprintln!(\"Usage: sum <file>\");\n return;\n }\n\n let file_name = &args[1];\n let contents = fs::read_to_string(file_name).unwrap();\n\n let lines = contents\n .lines()\n .map(|line| line.trim())\n .filter(|line|!line.is_empty());\n\n let sum: i32 = lines\n .map(|line| line.parse::<i32>().unwrap())\n .sum();\n\n println!(\"{}\", sum);\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": "use std::iter;\n\nfn main() {\n let numbers: Vec<i32> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];\n let sum: i32 = iter::filter(numbers.iter(), |&x| x % 2 == 0)\n .map(|x| x * 3)\n .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": "use std::collections::HashMap;\n\nfn main() {\n let numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n let map: HashMap<char, i32> = vec!['a', 'b', 'c', 'd', 'e'].into_iter().zip(1..10).collect();\n\n let sum: i32 = numbers.iter()\n .filter(|&x| map.contains_key(&x))\n .map(|x| x * map[&x])\n .sum();\n \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": "#[derive(Debug, PartialEq, Clone)]\npub struct Bytes32([u8; 32]);\n\nimpl FromStr for Bytes32 {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n let mut bytes = [0u8; 32];\n let len = s.len();\n let s = &s[0..len.min(32)];\n if len > 32 {\n Err(std::num::ParseIntError)\n } else {\n let mut s = s.as_bytes();\n for i in 0..len {\n bytes[i] = s[i];\n }\n Ok(Bytes32(bytes))\n }\n }\n}\n\nimpl std::fmt::Display for Bytes32 {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n for i in 0..32 {\n write!(f, \"{:02x}\", self.0[i])?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let x = Bytes32::from_str(\"deadbeefdeadbeefdeadbeefdeadbeef\").unwrap();\n println!(\"{:?}\", x);\n println!(\"{}\", x);\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": "pub struct U32Array(pub [u8; 32]);\n\nimpl FromStr for U32Array {\n type Err = String;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n if s.len()!= 32 {\n return Err(\"Invalid input length\".to_owned());\n }\n\n let mut bytes = [0u8; 32];\n for (i, b) in s.bytes().enumerate() {\n bytes[i] = b;\n }\n\n Ok(U32Array(bytes))\n }\n}\n\nimpl std::fmt::Display for U32Array {\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\n Ok(())\n }\n}\n\nfn main() {\n let s = \"0x00000000000000000000000000000000\";\n let a = U32Array::from_str(s).unwrap();\n\n println!(\"{}\", a);\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": "use std::fmt;\nuse std::str::FromStr;\n\n#[derive(Debug)]\npub struct U32Arr(pub [u8; 32]);\n\nimpl FromStr for U32Arr {\n type Err = String;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n let mut v: [u8; 32] = [0u8; 32];\n if s.len()!= 32 {\n return Err(\"Invalid input length\".to_string());\n }\n for (i, c) in s.bytes().enumerate() {\n v[i] = c;\n }\n Ok(U32Arr(v))\n }\n}\n\nimpl fmt::Display for U32Arr {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n write!(f, \"{}\", hex::encode(self.0))\n }\n}\n\nfn main() {\n let s = \"0123456789abcdef0123456789abcdef\".to_string();\n let arr = U32Arr::from_str(&s).unwrap();\n println!(\"{:?}\", arr);\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": "#[derive(Debug, PartialEq)]\nstruct Hash([u8; 32]);\n\nimpl FromStr for Hash {\n type Err = String;\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n if s.len()!= 32 {\n return Err(\"Hash must be 32 characters long\".to_string());\n }\n let mut h = [0; 32];\n for (i, c) in s.chars().enumerate() {\n h[i] = (c as u8 - b'0') as u8;\n }\n Ok(Hash(h))\n }\n}\n\nimpl std::fmt::Display for Hash {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n for b in &self.0 {\n write!(f, \"{}\", b as char)?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let hash = \"12345678901234567890123456789012\".parse::<Hash>().unwrap();\n println!(\"{:?}\", hash);\n println!(\"{}\", hash);\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": "pub struct HexArray(pub [u8; 32]);\n\nimpl FromStr for HexArray {\n type Err = String;\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n if s.len()!= 64 {\n Err(\"Invalid input length\".to_string())\n } else {\n let mut array = [0; 32];\n for i in 0..32 {\n let s = &s[i*2..(i+2)*2];\n array[i] = u8::from_str_radix(s, 16).unwrap();\n }\n Ok(HexArray(array))\n }\n }\n}\n\nimpl Display for HexArray {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n for i in 0..32 {\n write!(f, \"{:02x}\", self.0[i])?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let a = HexArray::from_str(\"aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899\").unwrap();\n println!(\"{}\", a);\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": "#[derive(Debug, PartialEq, Clone, Copy)]\nstruct Byte32([u8; 32]);\n\nimpl std::str::FromStr for Byte32 {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n let mut arr = [0; 32];\n let len = s\n .as_bytes()\n .iter()\n .enumerate()\n .map(|(i, &b)| {\n arr[i] = b;\n b\n })\n .take(32)\n .count();\n arr[len..].iter().for_each(|_| arr.push(0));\n Ok(Byte32(arr))\n }\n}\n\nimpl std::fmt::Display for Byte32 {\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 input = \"deadbeef\";\n let parsed = Byte32::from_str(input).unwrap();\n println!(\"{:?}\", parsed);\n println!(\"{}\", parsed);\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": "#[derive(Debug)]\nstruct Hash32([u8; 32]);\n\nimpl FromStr for Hash32 {\n type Err = String;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n let mut hash = [0; 32];\n hash[..s.len()].copy_from_slice(s.as_bytes());\n Ok(Hash32(hash))\n }\n}\n\nimpl std::fmt::Display for Hash32 {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n write!(f, \"{}\", hex::encode(&self.0))\n }\n}\n\nfn main() {\n let hash = Hash32::from_str(\"f6a8a0a8f9a2f5a2f3a4f5a6a7f8a9f2a3f4a5f6a7f8a9f3a4f5a6a7f8a9\").unwrap();\n println!(\"{:?}\", hash);\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)]\npub enum MyError {\n #[error(transparent)]\n IoError(#[from] std::io::Error),\n #[error(transparent)]\n OtherError(#[from] String),\n}\n\nfn do_some_io() -> Result<(), MyError> {\n let _ = std::fs::File::open(\"some_file.txt\")?;\n Ok(())\n}\n\nfn main() {\n if let Err(err) = do_some_io() {\n println!(\"Error: {}\", err);\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 std::fmt;\nuse thiserror::Error;\n\n#[derive(Debug, Error)]\npub enum MyError {\n #[error(\"Error reading from file: {0}\")]\n ReadFile(String),\n #[error(\"Error parsing: {0}\")]\n Parse(String),\n}\n\nstruct Foo {\n bar: String,\n}\n\nimpl fmt::Display for Foo {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n write!(f, \"{}\", self.bar)\n }\n}\n\nfn get_foo() -> Result<Foo, MyError> {\n let data = include_str!(\"data.txt\").to_string();\n\n let foo = data.parse::<Foo>()?;\n\n Ok(foo)\n}\n\nfn main() {\n let foo = get_foo().unwrap();\n println!(\"Foo = {:?}\", foo);\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": "#[derive(thiserror::Error, Debug)]\nenum Error {\n /// Custom error type that wraps another error\n Custom(Box<dyn std::error::Error + Send + Sync>),\n}\n\nimpl From<std::io::Error> for Error {\n fn from(err: std::io::Error) -> Self {\n Error::Custom(Box::new(err))\n }\n}\n\nimpl std::fmt::Display for Error {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n match self {\n Error::Custom(err) => write!(f, \"Custom error: {}\", err),\n }\n }\n}\n\nfn main() -> Result<(), Error> {\n let file = std::fs::File::open(\"non_existent_file.txt\")?;\n Ok(())\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 thiserror::Error;\n\n#[derive(Debug, Error, Display)]\npub enum MyError {\n #[error(\"Not Found\")]\n NotFound,\n #[error(\"Invalid Url\")]\n InvalidUrl,\n #[error(\"IO Error\")]\n IOError,\n #[error(\"Other\")]\n Other(String),\n}\n\nfn fetch_url(url: &str) -> Result<String, MyError> {\n if url == \"https://www.google.com\" {\n Ok(\"Google\".to_string())\n } else {\n Err(MyError::NotFound)\n }\n}\n\nfn main() -> Result<(), MyError> {\n let url = \"https://www.google.com\";\n let content = fetch_url(url)?;\n println!(\"{}\", content);\n Ok(())\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": "use thiserror::Error;\n\n#[derive(Debug, Error)]\npub enum MyError {\n #[error(\"the operation failed because {0}\")]\n OperationFailed(String),\n #[error(\"the operation failed with {0}\")]\n OperationFailedWith(Box<dyn std::error::Error + Send + Sync +'static>),\n}\n\nfn do_something() -> Result<(), MyError> {\n let v = vec![1, 2, 3];\n let s = &v[5];\n Err(MyError::OperationFailedWith(Box::new(v.into())))\n}\n\nfn main() {\n if let Err(e) = do_something() {\n eprintln!(\"error: {}\", e);\n }\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;\n\n#[derive(Debug, Error, Display)]\nenum MyError {\n // An error with a cause\n CausedBy(Box<dyn std::error::Error + Send + Sync +'static>),\n // A simple error variant\n SimpleError,\n}\n\nfn try_operation() -> Result<(), MyError> {\n let result = Err(MyError::CausedBy(Box::new(std::io::Error::new(\n std::io::ErrorKind::NotFound,\n \"Not found\",\n ))));\n Err(result?)\n}\n\nfn main() {\n if let Err(e) = try_operation() {\n eprintln!(\"{:?}\", e);\n }\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(Error, Debug)]\nenum Error {\n #[error(\"invalid data\")]\n InvalidData,\n #[error(\"IO error\")]\n Io(#[from] std::io::Error),\n #[error(\"other error\")]\n Other(#[from] Box<dyn std::error::Error + Send + Sync>),\n}\n\nfn read_file() -> Result<String, Error> {\n let s = String::from(\"some file contents\");\n Ok(s)\n}\n\nfn main() {\n let s = read_file().unwrap();\n println!(\"{}\", s);\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": "fn main() {\n let mut x = 5;\n let y = 5;\n\n let res1 = match x {\n 1 => 1,\n 2 => 2,\n _ => 3,\n };\n\n let res2 = if let 5 = y {\n 1\n } else {\n 2\n };\n\n let res3 = match x {\n ref a => *a,\n };\n\n let res4 = match y {\n ref b => *b,\n };\n\n let res5 = match x {\n _ => 4,\n };\n\n let res6 = if let _ = x {\n 4\n } else {\n 5\n };\n\n println!(\"{:?}\", res1);\n println!(\"{:?}\", res2);\n println!(\"{:?}\", res3);\n println!(\"{:?}\", res4);\n println!(\"{:?}\", res5);\n println!(\"{:?}\", res6);\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 a = 1;\n let b = 2;\n\n // Using `match`\n match a {\n 1 => println!(\"a is one\"),\n 2 => println!(\"a is two\"),\n _ => println!(\"a is something else\"),\n }\n\n // Using `if let`\n if let 1 = a {\n println!(\"a is one\");\n } else {\n println!(\"a is something else\");\n }\n\n let mut map = HashMap::new();\n map.insert(\"foo\", 1);\n map.insert(\"bar\", 2);\n\n // Using `match`\n match map.get(\"foo\") {\n Some(value) => println!(\"foo is {}\", value),\n None => println!(\"foo is not present\"),\n }\n\n // Using `if let`\n if let Some(value) = map.get(\"foo\") {\n println!(\"foo is {}\", value);\n } else {\n println!(\"foo is not present\");\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 = 3;\n\n // Using `match`\n match a {\n 1 => println!(\"One\"),\n 2 => println!(\"Two\"),\n 3 => println!(\"Three\"),\n _ => println!(\"Anything else\"),\n }\n\n // Using `if let`\n if let 1 = a {\n println!(\"One\");\n } else if let 2 = a {\n println!(\"Two\");\n } else if let 3 = a {\n println!(\"Three\");\n } else {\n println!(\"Anything else\");\n }\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": "fn main() {\n let v = vec![1, 2, 3, 4, 5];\n for i in v {\n match i {\n 1 | 3 | 5 => println!(\"odd\"),\n 2 | 4 => println!(\"even\"),\n _ => println!(\"unknown\"),\n }\n }\n \n let x = 7;\n if let 7 = x {\n println!(\"x is 7\");\n }\n \n let x = 7;\n if let Some(x) = Some(x) {\n println!(\"x is {}\", x);\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": "// The imports necessary for this example\nuse std::collections::HashMap;\nuse std::collections::HashSet;\nuse std::collections::BTreeMap;\n\nfn main() {\n // match on a single variable\n let x = 1;\n let y = \"foo\";\n let z = \"bar\";\n\n let result = match x {\n 1 => \"one\",\n 2 => \"two\",\n _ => \"unknown\",\n };\n println!(\"x is {}\", result);\n\n // match with a guard\n let result = match y {\n \"foo\" => \"y is foo\",\n \"bar\" => \"y is bar\",\n _ => \"y is neither foo nor bar\",\n };\n println!(\"y is {}\", result);\n\n // match with a tuple\n let tuple = (1, 2);\n let result = match tuple {\n (1, 2) => \"tuple is (1, 2)\",\n (3, 4) => \"tuple is (3, 4)\",\n _ => \"tuple is neither (1, 2) nor (3, 4)\",\n };\n println!(\"tuple is {}\", result);\n\n // match with a tuple struct\n struct Point { x: i32, y: i32 }\n let point = Point { x: 1, y: 2 };\n let result = match point {\n Point { x, y } => format!(\"point is ({}, {})\", x, y),\n _ => \"point is neither Point nor anything else\",\n };\n println!(\"point is {}\", result);\n\n // match with a struct\n struct S { a: i32, b: i32, c: i32 }\n let s = S { a: 1, b: 2, c: 3 };\n let result = match s {\n S { a, b, c } => format!(\"s is ({}, {}, {})\", a, b, c),\n _ => \"s is neither S nor anything else\",\n };\n println!(\"s is {}\", result);\n\n // match with a tuple struct and a wildcard\n let tuple = (1, 2, 3, 4);\n let result = match tuple {\n (1, 2, _, 4) => \"tuple is (1, 2, _, 4)\",\n (1, 2, _, _) => \"tuple is (1, 2, _, _)\",\n _ => \"tuple is neither (1, 2, _, 4) nor (1, 2, _, _)\",\n };\n println!(\"tuple is {}\", result);\n\n // match with a tuple struct and a wildcard\n let point = Point { x: 1, y: 2 };\n let result = match point {\n Point { x,.. } => \"point is Point { x,.. }\",\n _ => \"point is neither Point nor anything else\",\n };\n println!(\"point is {}\", result);\n\n // match with a struct and a wildcard\n let s = S { a: 1, b: 2, c: 3 };\n let result = match s {\n S { a,.. } => \"s is S { a,.. }\",\n _ => \"s is neither S nor anything else\",\n };\n println!(\"s is {}\", result);\n\n // match with a wildcard\n let result = match (1, 2, 3, 4) {\n (1, 2, _, 4) => \"tuple is (1, 2, _, 4)\",\n (1, 2, _, _) => \"tuple is (1, 2, _, _)\",\n _ => \"tuple is neither (1, 2, _, 4) nor (1, 2, _, _)\",\n };\n println!(\"tuple is {}\", result);\n\n // match with a wildcard\n let result = match S { a: 1, b: 2, c: 3 } {\n S { a,.. } => \"s is S { a,.. }\",\n _ => \"s is neither S nor anything else\",\n };\n println!(\"s is {}\", result);\n\n // match on a reference\n let result = match &s {\n &S { a,.. } => \"s is S { a,.. }\",\n _ => \"s is neither S nor anything else\",\n };\n println!(\"s is {}\", result);\n\n // match with a tuple struct and a reference\n let point = Point { x: 1, y: 2 };\n let result = match &point {\n &Point { x,.. } => \"point is Point { x,.. }\",\n _ => \"point is neither Point nor anything else\",\n };\n println!(\"point is {}\", result);\n\n // match with a struct and a reference\n let result = match &s {\n &S { a,.. } => \"s is S { a,.. }\",\n _ => \"s is neither S nor anything else\",\n };\n println!(\"s is {}\", result);\n\n // match with a reference and a wildcard\n let result = match &S { a: 1, b: 2, c: 3 } {\n &S { a,.. } => \"s is S { a,.. }\",\n _ => \"s is neither S nor anything else\",\n };\n println!(\"s is {}\", result);\n\n // match with a reference and a wildcard\n let result = match &S { a: 1, b: 2, c: 3 } {\n &S { a,.. } => \"s is S { a,.. }\",\n _ => \"s is neither S nor anything else\",\n };\n println!(\"s is {}\", result);\n\n // match with a reference and a tuple\n let tuple = (1, 2, 3, 4);\n let result = match &tuple {\n &(1, 2, _, 4) => \"tuple is (1, 2, _, 4)\",\n &(1, 2, _, _) => \"tuple is (1, 2, _, _)\",\n _ => \"tuple is neither (1, 2, _, 4) nor (1, 2, _, _)\",\n };\n println!(\"tuple is {}\", result);\n\n // match with a reference and a tuple\n let tuple = (1, 2, 3, 4);\n let result = match &tuple {\n &(1, 2, _, 4) => \"tuple is (1, 2, _, 4)\",\n &(1, 2, _, _) => \"tuple is (1, 2, _, _)\",\n _ => \"tuple is neither (1, 2, _, 4) nor (1, 2, _, _)\",\n };\n println!(\"tuple is {}\", result);\n\n // match on a collection\n let mut set = HashSet::from([1, 2, 3, 4, 5, 6]);\n let result = match set {\n HashSet::from([1, 2, 3, 4, 5, 6]) => \"set is HashSet::from([1, 2, 3, 4, 5, 6])\",\n HashSet::from([2, 3, 4, 5, 6, 7]) => \"set is HashSet::from([2, 3, 4, 5, 6, 7])\",\n HashSet::from([1, 2, 3, 4, 5, 6, 7]) => \"set is HashSet::from([1, 2, 3, 4, 5, 6, 7])\",\n HashSet::from([1, 2, 3, 4, 5]) => \"set is HashSet::from([1, 2, 3, 4, 5])\",\n HashSet::from([2, 3, 4, 5, 6, 7, 8]) => \"set is HashSet::from([2, 3, 4, 5, 6, 7, 8])\",\n _ => \"set is neither any of the above\",\n };\n println!(\"set is {}\", result);\n\n // match on a collection with a wildcard\n let mut map = HashMap::from([(1, 2), (3, 4), (5, 6)]);\n let result = match map {\n HashMap::from([(1, 2), (3, 4), (5, 6)]) => \"map is HashMap::from([(1, 2), (3, 4), (5, 6)])\",\n HashMap::from([(1, 2), (3, 4), (5, 6), (7, 8)]) => \"map is HashMap::from([(1, 2), (3, 4), (5, 6), (7, 8)])\",\n HashMap::from([(1, 2)]) => \"map is HashMap::from([(1, 2)])\",\n HashMap::from([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]) => \"map is HashMap::from([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)])\",\n _ => \"map is neither any of the above\",\n };\n println!(\"map is {}\", result);\n\n // match on a collection with a wildcard\n let mut map = BTreeMap::from([(1, 2), (3, 4), (5, 6)]);\n let result = match map {\n BTreeMap::from([(1, 2), (3, 4), (5, 6)]) => \"map is BTreeMap::from([(1, 2), (3, 4), (5, 6)])\",\n BTreeMap::from([(1, 2), (3, 4), (5, 6), (7, 8)]) => \"map is BTreeMap::from([(1, 2), (3, 4), (5, 6), (7, 8)])\",\n BTreeMap::from([(1, 2)]) => \"map is BTreeMap::from([(1, 2)])\",\n BTreeMap::from([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]) => \"map is BTreeMap::from([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)])\",\n _ => \"map is neither any of the above\",\n };\n println!(\"map is {}\", result);\n\n // match with an option\n let option = Some(1);\n let result = match option {\n Some(1) => \"option is Some(1)\",\n Some(2) => \"option is Some(2)\",\n _ => \"option is neither Some(1) nor Some(2)\",\n };\n println!(\"option is {}\", result);\n\n // match with an option and a wildcard\n let option = Some(1);\n let result = match option {\n Some(1) => \"option is Some(1)\",\n _ => \"option is neither Some(1) nor anything else\",\n };\n println!(\"option is {}\", result);\n\n // match with an option and a tuple\n let option = Some(1);\n let result = match option {\n Some(1) => \"option is Some(1)\",\n Some(2) => \"option is Some(2)\",\n _ => \"option is neither Some(1) nor Some(2)\",\n };\n println!(\"option is {}\", result);\n\n // match with an option and a tuple\n let option = Some(1);\n let result = match option {\n Some(1) => \"option is Some(1)\",\n Some(2) => \"option is Some(2)\",\n _ => \"option is neither Some(1) nor Some(2)\",\n };\n println!(\"option is {}\", result);\n\n // match with an option and a tuple struct\n let option = Some(1);\n let result = match option {\n Some(1) => \"option is Some(1)\",\n Some(2) => \"option is Some(2)\",\n _ => \"option is neither Some(1) nor anything else\",\n };\n println!(\"option is {}\", result);\n\n // match with an option and a struct\n let option = Some(1);\n let result = match option {\n Some(1) => \"option is Some(1)\",\n Some(2) => \"option is Some(2)\",\n _ => \"option is neither Some(1) nor anything else\",\n };\n println!(\"option is {}\", result);\n\n // match with an option and a reference\n let option = Some(1);\n let result = match &option {\n &Some(1) => \"option is Some(1)\",\n &Some(2) => \"option is Some(2)\",\n _ => \"option is neither Some(1) nor anything else\",\n };\n println!(\"option is {}\", result);\n\n // match with an option and a reference\n let option = Some(1);\n let result = match &option {\n &Some(1) => \"option is Some(1)\",\n &Some(2) => \"option is Some(2)\",\n _ => \"option is neither Some(1) nor anything else\",\n };\n println!(\"option is {}\", result);\n\n // if let\n if let Some(1) = option {\n println!(\"option is Some(1)\");\n }\n if let Some(2) = option {\n println!(\"option is Some(2)\");\n }\n if let None = option {\n println!(\"option is None\");\n }\n\n // if let with a tuple\n let tuple = (1, 2);\n if let (1, 2) = tuple {\n println!(\"tuple is (1, 2)\");\n }\n if let (3, 4) = tuple {\n println!(\"tuple is (3, 4)\");\n }\n if let (5, 6) = tuple {\n println!(\"tuple is (5, 6)\");\n }\n\n // if let with a tuple struct\n let point = Point { x: 1, y: 2 };\n if let Point { x, y } = point {\n println!(\"point is ({}, {})\", x, y);\n }\n if let Point { x: 3, y: 4 } = point {\n println!(\"point is ({}, {})\", x, y);\n }\n if let Point { x: 5, y: 6 } = point {\n println!(\"point is ({}, {})\", x, y);\n }\n\n // if let with a struct\n let s = S { a: 1, b: 2, c: 3 };\n if let S { a, b, c } = s {\n println!(\"s is ({}, {}, {})\", a, b, c);\n }\n if let S { a: 3, b: 4, c: 5 } = s {\n println!(\"s is ({}, {}, {})\", a, b, c);\n }\n if let S { a: 5, b: 6, c: 7 } = s {\n println!(\"s is ({}, {}, {})\", a, b, c);\n }\n\n // if let with a wildcard\n let tuple = (1, 2, 3, 4);\n if let (1, 2, _, 4) = tuple {\n println!(\"tuple is (1, 2, _, 4)\");\n }\n if let (1, 2, _, _) = tuple {\n println!(\"tuple is (1, 2, _, _)\");\n }\n if let (5, 6, 7, 8) = tuple {\n println!(\"tuple is (5, 6, 7, 8)\");\n }\n\n // if let with a wildcard\n let point = Point { x: 1, y: 2 };\n if let Point { x,.. } = point {\n println!(\"point is Point { x,.. }\");\n }\n if let Point { x: 3,.. } = point {\n println!(\"point is Point { x,.. }\");\n }\n if let Point { x: 5,.. } = point {\n println!(\"point is Point { x,.. }\");\n }\n\n // if let with a wildcard\n let s = S { a: 1, b: 2, c: 3 };\n if let S { a,.. } = s {\n println!(\"s is S { a,.. }\");\n }\n if let S { a: 3,.. } = s {\n println!(\"s is S { a,.. }\");\n }\n if let S { a: 5,.. } = s {\n println!(\"s is S { a,.. }\");\n }\n\n // if let with a reference\n let tuple = (1, 2, 3, 4);\n if let &(1, 2, _, 4) = tuple {\n println!(\"tuple is (1, 2, _, 4)\");\n }\n if let &(1, 2, _, _) = tuple {\n println!(\"tuple is (1, 2, _, _)\");\n }\n if let &(5, 6, 7, 8) = tuple {\n println!(\"tuple is (5, 6, 7, 8)\");\n }\n\n // if let with a reference\n let point = Point { x: 1, y: 2 };\n if let &Point { x,.. } = &point {\n println!(\"point is Point { x,.. }\");\n }\n if let &Point { x: 3,.. } = &point {\n println!(\"point is Point { x,.. }\");\n }\n if let &Point { x: 5,.. } = &point {\n println!(\"point is Point { x,.. }\");\n }\n\n // if let with a reference\n let s = S { a: 1, b: 2, c: 3 };\n if let &S { a,.. } = &s {\n println!(\"s is S { a,.. }\");\n }\n if let &S { a: 3,.. } = &s {\n println!(\"s is S { a,.. }\");\n }\n if let &S { a: 5,.. } = &s {\n println!(\"s is S { a,.. }\");\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": "use std::collections::HashMap;\n\nfn main() {\n let v = vec![1, 2, 3, 4, 5];\n\n let mut map = HashMap::new();\n for i in v {\n map.entry(i).and_modify(|v| *v += 1).or_insert(i);\n }\n\n println!(\"{:?}\", map);\n\n let mut map = HashMap::new();\n for i in v {\n if let Some(v) = map.get_mut(&i) {\n *v += 1;\n } else {\n map.insert(i, 1);\n }\n }\n\n println!(\"{:?}\", map);\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 = 3;\n\n // Pattern matching with if let\n if let Some(y) = Some(4) {\n println!(\"y = {}\", y);\n }\n\n match x {\n 1 => println!(\"x is 1\"),\n 2 => println!(\"x is 2\"),\n 3 => println!(\"x is 3\"),\n _ => println!(\"x is not 1, 2 or 3\"),\n }\n\n // Pattern matching with tuples\n let t = (1, 2, 3);\n match t {\n (1, 2, 3) => println!(\"t is (1, 2, 3)\"),\n (1, 2, 4) => println!(\"t is (1, 2, 4)\"),\n _ => println!(\"t is not (1, 2, 3) or (1, 2, 4)\"),\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 Point {\n x: f32,\n y: f32,\n}\n\nimpl Point {\n fn new(x: f32, y: f32) -> Point {\n Point { x, y }\n }\n}\n\nimpl Clone for Point {\n fn clone(&self) -> Self {\n Point::new(self.x, self.y)\n }\n}\n\nfn main() {\n let mut p = Point::new(1.0, 2.0);\n let p2 = p.clone();\n println!(\"p: ({}, {}), p2: ({}, {})\", p.x, p.y, p2.x, p2.y);\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": "#[derive(Debug)]\nstruct Point {\n x: f64,\n y: f64,\n}\n\nimpl Point {\n fn new(x: f64, y: f64) -> Self {\n Self { x, y }\n }\n}\n\nimpl Point {\n fn distance(&self, other: &Self) -> f64 {\n ((self.x - other.x).powi(2) + (self.y - other.y).powi(2)).sqrt()\n }\n\n fn get_x(&self) -> f64 {\n self.x\n }\n\n fn get_y(&self) -> f64 {\n self.y\n }\n\n fn set_x(&mut self, x: f64) {\n self.x = x;\n }\n\n fn set_y(&mut self, y: f64) {\n self.y = y;\n }\n}\n\ntrait ToPoint {\n fn to_point(&self) -> Point;\n}\n\nimpl ToPoint for Point {\n fn to_point(&self) -> Point {\n *self\n }\n}\n\nfn main() {\n let p1 = Point::new(1.0, 2.0);\n let p2 = Point::new(3.0, 4.0);\n\n println!(\"{:?}\", p1.to_point());\n println!(\"Distance: {}\", p1.distance(&p2));\n p1.set_x(5.0);\n p1.set_y(6.0);\n println!(\"x: {}, y: {}\", p1.get_x(), p1.get_y());\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": "use std::fmt;\n\n#[derive(Debug)]\nstruct Person {\n name: String,\n age: u8,\n}\n\nimpl Person {\n fn new(name: &str, age: u8) -> Self {\n Person {\n name: String::from(name),\n age,\n }\n }\n\n fn greet(&self) -> String {\n format!(\"Hi, my name is {} and I am {} years old\", self.name, self.age)\n }\n}\n\ntrait Animal {\n fn speak(&self) -> String;\n}\n\nimpl Animal for Person {\n fn speak(&self) -> String {\n format!(\"Hello, I'm a human!\")\n }\n}\n\nfn main() {\n let p = Person::new(\"John\", 42);\n println!(\"Person: {:?}\", p);\n println!(\"Person says: {}\", p.speak());\n println!(\"Person speaks: {}\", p.greet());\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": "#[derive(Debug)]\nstruct Person {\n name: String,\n age: u8,\n}\n\nimpl Person {\n fn new(name: &str, age: u8) -> Self {\n Self { name: String::from(name), age }\n }\n}\n\ntrait Printer {\n fn print(&self);\n}\n\nimpl Printer for Person {\n fn print(&self) {\n println!(\"Name: {}\", self.name);\n println!(\"Age: {}\", self.age);\n }\n}\n\nfn main() {\n let person = Person::new(\"John Doe\", 25);\n println!(\"{:?}\", person);\n person.print();\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": "struct Person {\n name: String,\n age: u8,\n}\n\nimpl Person {\n fn say_hello(&self) {\n println!(\"Hello, my name is {} and I'm {}\", self.name, self.age);\n }\n}\n\ntrait Animal {\n fn speak(&self) {\n println!(\"A sound\");\n }\n}\n\nimpl Animal for Person {\n fn speak(&self) {\n println!(\"Hello\");\n }\n}\n\nfn main() {\n let mut person = Person {\n name: \"John\".to_string(),\n age: 30,\n };\n person.speak();\n person.say_hello();\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": "use std::ops::Deref;\n\nstruct Vector {\n x: i32,\n y: i32,\n}\n\nimpl Vector {\n fn new(x: i32, y: i32) -> Vector {\n Vector { x, y }\n }\n\n fn magnitude(&self) -> f64 {\n self.x as f64 * self.x as f64 + self.y as f64 * self.y as f64\n }\n}\n\nimpl Deref for Vector {\n type Target = (i32, i32);\n\n fn deref(&self) -> &Self::Target {\n (&self.x, &self.y)\n }\n}\n\nfn main() {\n let v = Vector::new(3, 4);\n println!(\"Magnitude of vector: {}\", v.magnitude());\n println!(\"Dereferencing Vector: {:?}\", *v);\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": "pub trait Foo {\n fn print(&self);\n}\n\nstruct Bar {\n a: u32,\n b: u32,\n}\n\nimpl Foo for Bar {\n fn print(&self) {\n println!(\"a: {}, b: {}\", self.a, self.b);\n }\n}\n\nfn main() {\n let mut b = Bar { a: 1, b: 2 };\n b.print();\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(Debug, Serialize, Deserialize)]\nstruct User {\n name: String,\n age: u8,\n address: Address,\n}\n\n#[derive(Debug, Serialize, Deserialize)]\nstruct Address {\n street: String,\n city: String,\n country: String,\n}\n\nfn main() {\n let user = User {\n name: \"John\".to_string(),\n age: 30,\n address: Address {\n street: \"123 Main St\".to_string(),\n city: \"Anytown\".to_string(),\n country: \"USA\".to_string(),\n },\n };\n\n let json = serde_json::to_string(&user).unwrap();\n println!(\"JSON: {}\", json);\n\n let user_deserialized: User = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized User: {:?}\", user_deserialized);\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_derive::{Deserialize, Serialize};\nuse serde_json;\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: 20,\n };\n\n let json = serde_json::to_string(&person).unwrap();\n\n println!(\"JSON: {}\", json);\n\n let deserialized: Person = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized: {:?}\", 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};\nuse serde_json;\n\n#[derive(Debug, Serialize, Deserialize)]\nstruct Person {\n name: String,\n age: u8,\n address: Address,\n}\n\n#[derive(Debug, Serialize, Deserialize)]\nstruct Address {\n street: String,\n city: String,\n state: String,\n zip: u32,\n}\n\nfn main() {\n let person = Person {\n name: \"John\".to_string(),\n age: 30,\n address: Address {\n street: \"123 Main St\".to_string(),\n city: \"Anytown\".to_string(),\n state: \"CA\".to_string(),\n zip: 12345,\n },\n };\n\n let person_json = serde_json::to_string(&person).unwrap();\n println!(\"Person: {:#?}\", person);\n println!(\"Person JSON: {}\", person_json);\n \n let person_deserialized: Person = serde_json::from_str(&person_json).unwrap();\n println!(\"Deserialized Person: {:#?}\", person_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::{Deserialize, Serialize};\n\n#[derive(Serialize, Deserialize)]\nstruct MyStruct {\n name: String,\n value: f64,\n}\n\nfn main() {\n let data = MyStruct {\n name: \"Example\".to_string(),\n value: 5.0,\n };\n\n let json = serde_json::to_string(&data).unwrap();\n println!(\"JSON: {}\", json);\n\n let new_data: MyStruct = serde_json::from_str(&json).unwrap();\n println!(\"New data: {:?}\", new_data);\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(Debug, Serialize, Deserialize)]\nstruct Person {\n name: String,\n age: u8,\n address: Address,\n}\n\n#[derive(Debug, Serialize, Deserialize)]\nstruct Address {\n street: String,\n city: String,\n state: String,\n zip: String,\n}\n\nfn main() {\n let person = Person {\n name: String::from(\"John\"),\n age: 25,\n address: Address {\n street: String::from(\"123 Main St\"),\n city: String::from(\"Anytown\"),\n state: String::from(\"NY\"),\n zip: String::from(\"12345\"),\n },\n };\n\n let person_str = serde_json::to_string(&person).unwrap();\n println!(\"Serialized person: {}\", person_str);\n\n let deserialized_person = serde_json::from_str::<Person>(&person_str).unwrap();\n println!(\"Deserialized person: {:?}\", deserialized_person);\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 User {\n name: String,\n age: u8,\n}\n\nfn main() {\n let user = User {\n name: \"John\".to_string(),\n age: 30,\n };\n\n let serialized_user = serde_json::to_string(&user).unwrap();\n\n let deserialized_user: User = serde_json::from_str(&serialized_user).unwrap();\n\n println!(\"User: {:?}\", user);\n println!(\"Serialized: {}\", serialized_user);\n println!(\"Deserialized: {:?}\", deserialized_user);\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(Serialize, Deserialize)]\nstruct Person {\n first_name: String,\n last_name: String,\n age: u8,\n address: Address,\n}\n\n#[derive(Serialize, Deserialize)]\nstruct Address {\n street: String,\n city: String,\n country: String,\n}\n\nfn main() {\n let person = Person {\n first_name: String::from(\"John\"),\n last_name: String::from(\"Doe\"),\n age: 30,\n address: Address {\n street: String::from(\"123 Main St\"),\n city: String::from(\"New York\"),\n country: String::from(\"USA\"),\n },\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 let re = Regex::new(r\"fox\").unwrap();\n let replaced = re.replace(&text, \"cat\");\n println!(\"{}\", replaced);\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 = \"This is a simple example of text, with a word repeated several times, and a sentence with a number in it. 123. Another sentence with a number, 456.\";\n let pattern = r\"\\b\\w+\\b\";\n let replacement = \"X\";\n let re = Regex::new(pattern).unwrap();\n let new_text = re.replace_all(&text, replacement);\n println!(\"{}\", new_text);\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 = \"This is a sample text to test regex replacement.\";\n let re = Regex::new(r\"\\b\\w+\\b\").unwrap();\n let replacement = \"word\";\n let new_text = re.replace_all(&text, replacement).to_string();\n println!(\"{}\", new_text);\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 = \"This is a sentence with a few words, but the first word is not what we want\";\n let re = Regex::new(r\"^(?:\\w+)\\b\").unwrap();\n let replaced = re.replace_all(&text, \"New\");\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": "use regex::Regex;\n\nfn main() {\n let re = Regex::new(r\"\\b(\\w+) \\1\\b\").unwrap();\n let text = \"My name is John John\";\n let replaced = re.replace_all(&text, \"[$1]\");\n\n println!(\"{}\", replaced);\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 text = \"Hello, my phone number is 555-1234 and I have 2 cats. My favorite food is pizza.\";\n let re = Regex::new(r\"\\d+\").unwrap();\n let new_text = re.replace_all(&text, \"XXXXX\");\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 re = Regex::new(r\"\\d+\").unwrap();\n let text = \"My phone number is 123-456-7890 and I have another phone number 098-765-4321\";\n let new_text = re.replace_all(&text, \"number\").to_string();\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::*;\n\nfn main() {\n // Test the format function with different date formats\n let s = Local::now().format(\"%B %e, %Y\").to_string();\n println!(\"{}\", s);\n let s = Local::now().format(\"%B %e, %Y %I:%M %p\").to_string();\n println!(\"{}\", s);\n let s = Local::now().format(\"%B %e, %Y %I:%M:%S %p\").to_string();\n println!(\"{}\", s);\n\n // Test the parse function with different date formats\n let s = \"January 1, 2020\";\n let d = s.parse::<NaiveDate>().unwrap();\n println!(\"{}\", d.format(\"%B %e, %Y\"));\n\n let s = \"January 1, 2020 10:15:30 PM\";\n let d = s.parse::<NaiveDateTime>().unwrap();\n println!(\"{}\", d.format(\"%B %e, %Y %I:%M %p\"));\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::{NaiveDate, NaiveDateTime, NaiveTime, Utc};\n\nfn main() {\n // Parse a date string\n let date_string = \"2021-01-01 12:00:00\";\n let date = NaiveDate::parse_from_str(date_string, \"%Y-%m-%d %H:%M:%S\").unwrap();\n\n // Parse a datetime string\n let datetime_string = \"2021-01-01 12:00:00\";\n let datetime = NaiveDateTime::parse_from_str(datetime_string, \"%Y-%m-%d %H:%M:%S\").unwrap();\n\n // Format the date\n let formatted_date = date.format(\"%Y/%m/%d\").to_string();\n println!(\"Date: {}\", formatted_date);\n\n // Format the datetime\n let formatted_datetime = datetime.format(\"%Y/%m/%d %H:%M:%S\").to_string();\n println!(\"Datetime: {}\", formatted_datetime);\n\n // Format the datetime with a custom format\n let custom_format = \"Date: %Y/%m/%d Time: %H:%M:%S\";\n let formatted_datetime_custom = datetime.format(&custom_format).to_string();\n println!(\"Custom Format: {}\", formatted_datetime_custom);\n\n // Get the year\n let year = date.year();\n println!(\"Year: {}\", year);\n\n // Get the month\n let month = date.month();\n println!(\"Month: {}\", month);\n\n // Get the day\n let day = date.day();\n println!(\"Day: {}\", day);\n\n // Get the hour\n let hour = datetime.hour();\n println!(\"Hour: {}\", hour);\n\n // Get the minute\n let minute = datetime.minute();\n println!(\"Minute: {}\", minute);\n\n // Get the second\n let second = datetime.second();\n println!(\"Second: {}\", second);\n}"}
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, NaiveDateTime, Utc};\n\nfn main() {\n let dt = NaiveDateTime::parse_from_str(\"2020-01-01 00:00:00\", \"%Y-%m-%d %H:%M:%S\").unwrap();\n let formatted = Utc.ymd(dt.year(), dt.month(), dt.day()).to_string();\n println!(\"{}\", formatted);\n\n let dt = NaiveDateTime::parse_from_str(\"2020-01-01 00:00:00\", \"%Y-%m-%d %H:%M:%S\").unwrap();\n let formatted = Utc.ymd(dt.year(), dt.month(), dt.day()).format(\"%a %b %e %Y\").to_string();\n println!(\"{}\", formatted);\n\n let dt = NaiveDateTime::parse_from_str(\"2020-01-01 00:00:00\", \"%Y-%m-%d %H:%M:%S\").unwrap();\n let formatted = Utc.ymd(dt.year(), dt.month(), dt.day()).format(\"%A %B %e %Y\").to_string();\n println!(\"{}\", formatted);\n\n let dt = NaiveDateTime::parse_from_str(\"2020-01-01 00:00:00\", \"%Y-%m-%d %H:%M:%S\").unwrap();\n let formatted = Utc.ymd(dt.year(), dt.month(), dt.day()).format(\"%a %B %e %Y %T %:z\").to_string();\n println!(\"{}\", formatted);\n}"}
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::NaiveDateTime;\n\nfn main() {\n let date_string = \"2020-07-26 10:01:22\";\n let date = NaiveDateTime::parse_from_str(date_string, \"%Y-%m-%d %H:%M:%S\").unwrap();\n let formatted = date.format(\"%a %b %d %Y %T\").to_string();\n println!(\"{}\", formatted);\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, Datelike, Local, Timelike, Utc};\n\nfn main() {\n let date = \"2020-07-26T16:05:56Z\";\n let date = DateTime::<Utc>::parse_from_rfc3339(date).unwrap();\n let formatted = date.with_timezone(&Local).format(\"%B %e %Y\").to_string();\n println!(\"{}\", formatted);\n\n let date = \"2020-07-26T16:05:56Z\";\n let date = DateTime::<Utc>::parse_from_rfc3339(date).unwrap();\n let formatted = date.with_timezone(&Local).format(\"%B %e %Y\").to_string();\n println!(\"{}\", formatted);\n\n let date = \"2020-07-26T16:05:56Z\";\n let date = DateTime::<Utc>::parse_from_rfc3339(date).unwrap();\n let formatted = date.with_timezone(&Local).format(\"%B %e %Y\").to_string();\n println!(\"{}\", formatted);\n\n let date = \"2020-07-26T16:05:56Z\";\n let date = DateTime::<Utc>::parse_from_rfc3339(date).unwrap();\n let formatted = date.with_timezone(&Local).format(\"%B %e %Y\").to_string();\n println!(\"{}\", formatted);\n}"}
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, DateTime, Local};\nuse chrono::format::Pf;\n\nfn main() {\n let date = DateTime::parse_from_str(\"2020-01-01 12:30\", \"%Y-%m-%d %H:%M\").unwrap();\n let formatted = date.format(\"%Y/%m/%d\").to_string();\n\n let date = DateTime::parse_from_str(\"2020-01-01 12:30\", \"%Y-%m-%d %H:%M\").unwrap();\n let formatted = date.format(\"%a %b %e %Y\").to_string();\n\n let date = DateTime::parse_from_str(\"2020-01-01 12:30\", \"%Y-%m-%d %H:%M\").unwrap();\n let formatted = date.format(\"%a %b %e %Y %I:%M %p\").to_string();\n\n let date = DateTime::parse_from_str(\"2020-01-01 12:30\", \"%Y-%m-%d %H:%M\").unwrap();\n let formatted = date.format(\"%a %b %e %Y %I:%M %p %Z\").to_string();\n\n let date = DateTime::parse_from_str(\"2020-01-01 12:30\", \"%Y-%m-%d %H:%M\").unwrap();\n let formatted = date.format(\"%a %b %e %Y %I:%M %p %Z %:z\").to_string();\n\n println!(\"{}\", formatted);\n println!(\"{}\", formatted);\n println!(\"{}\", formatted);\n println!(\"{}\", formatted);\n println!(\"{}\", formatted);\n}"}
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, NaiveDate, NaiveDateTime, Utc};\n\nfn format_date(date: &str) -> String {\n let date: DateTime<Utc> = date.parse().unwrap();\n let date = NaiveDate::from_ymd(date.year(), date.month(), date.day());\n let formatted = format!(\"{}-{:02}-{:02}\", date.year(), date.month(), date.day());\n return formatted;\n}\n\nfn main() {\n let date = \"2019-01-01\";\n let formatted = format_date(date);\n println!(\"{}\", formatted);\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 uuid_v4 = Uuid::new_v4();\n let uuid_v5 = Uuid::new_v5(Uuid::NAMESPACE_OID, \"rust\");\n let uuid_v6 = Uuid::new_v6();\n let uuid_v7 = Uuid::new_v7();\n\n println!(\"v4: {:?}\", uuid_v4);\n println!(\"v5: {:?}\", uuid_v5);\n println!(\"v6: {:?}\", uuid_v6);\n println!(\"v7: {:?}\", uuid_v7);\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 random_uuid = Uuid::new_v4();\n let random_uuid_2 = Uuid::new_v4();\n let random_uuid_3 = Uuid::new_v4();\n let random_uuid_4 = Uuid::new_v4();\n let random_uuid_5 = Uuid::new_v4();\n\n println!(\"{:?}\", random_uuid);\n println!(\"{:?}\", random_uuid_2);\n println!(\"{:?}\", random_uuid_3);\n println!(\"{:?}\", random_uuid_4);\n println!(\"{:?}\", random_uuid_5);\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 random_uuid = Uuid::new_v4();\n println!(\"Random UUID: {}\", random_uuid);\n\n let v4_uuid = Uuid::new_v4();\n println!(\"V4 UUID: {}\", v4_uuid);\n\n let v5_uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n println!(\"V5 UUID: {}\", v5_uuid);\n\n let v5_uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n println!(\"V5 UUID: {}\", v5_uuid);\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 // generate a random UUID\n let random_uuid = Uuid::new_v4();\n println!(\"Random UUID: {:?}\", random_uuid);\n\n // generate a random UUID with a namespace\n let random_uuid_with_namespace = Uuid::new_v4_with_namespace(\n &Uuid::NAMESPACE_DNS,\n &Uuid::new_v4(),\n );\n println!(\"Random UUID with namespace: {:?}\", random_uuid_with_namespace);\n\n // generate a random UUID based on a string\n let random_uuid_from_string = Uuid::parse_str(\"00000000-0000-0000-0000-000000000000\");\n println!(\"Random UUID from string: {:?}\", random_uuid_from_string);\n\n // generate a random UUID based on a string with a namespace\n let random_uuid_from_string_with_namespace = Uuid::parse_str_with_namespace(\n \"00000000-0000-0000-0000-000000000000\",\n &Uuid::NAMESPACE_DNS,\n );\n println!(\"Random UUID from string with namespace: {:?}\", random_uuid_from_string_with_namespace);\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::new_v4());\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\"));\n println!(\"{}\", Uuid::parse_str(\"f47ac10b-58cc-4372-a567-0a9c71c29dd1\").unwrap());\n let mut uuid = Uuid::new_v4();\n uuid.set_version(5);\n uuid.set_variant(Uuid::Variant::RFC4122);\n uuid.set_variant(Uuid::Variant::RFC4122);\n println!(\"{}\", uuid);\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::new_v4());\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_URL, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_OID, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_URL, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_OID, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_URL, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_OID, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_URL, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_OID, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_URL, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_OID, \"rust-lang.org\"));\n println!(\"{}\", Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\"));\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 println!(\"{}\", Uuid::new_v4());\n println!(\"{}\", Uuid::new_v5(\"example.com\", \"rust\"));\n println!(\"{}\", Uuid::parse_str(\"f47ac10b-58cc-4372-a567-0a9c71e4a667\"));\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": "extern crate rand;\nuse rand::prelude::*;\n\nfn main() {\n let mut rng = rand::thread_rng();\n\n let numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];\n let random_number = rng.gen_range(1..=12);\n\n let names = vec![\"Alice\", \"Bob\", \"Charlie\", \"Dave\", \"Eve\", \"Frank\", \"George\", \"Heather\", \"Ivan\", \"Julia\", \"Kevin\", \"Lily\"];\n let random_name = rng.gen_range(0..12);\n\n let fruits = vec![\"Apple\", \"Banana\", \"Cherry\", \"Date\", \"Elderberry\", \"Fig\", \"Grape\", \"Honeydew\", \"Ice cream\", \"Jackfruit\", \"Kiwi\", \"Lemon\"];\n let random_fruit = rng.gen_range(0..12);\n\n println!(\"Random number: {}\", numbers[random_number]);\n println!(\"Random name: {}\", names[random_name]);\n println!(\"Random fruit: {}\", fruits[random_fruit]);\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 random_numbers: Vec<u32> = (1..100).collect();\n\n // Generate a random number\n let random_number = thread_rng().gen_range(0..random_numbers.len());\n\n // Select random item from vector\n let random_item = random_numbers.get(random_number as usize).unwrap();\n\n println!(\"Random number: {}\", random_number);\n println!(\"Random item: {}\", random_item);\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::distributions::Alphanumeric;\nuse rand::prelude::*;\nuse rand::Rng;\n\nfn main() {\n let mut rng = thread_rng();\n\n let mut letters = vec!['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l','m', 'n', 'o', 'p', 'q', 'r','s', 't', 'u', 'v', 'w', 'x', 'y', 'z'];\n let mut digits = vec!['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];\n let mut symbols = vec!['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '-', '_', '=', '[', ']', '{', '}', '|', ';', ':', '\"', '<', '>', ',', '.', '?', '/'];\n\n let mut password = String::new();\n let mut password_length = 10;\n\n let mut chars: Vec<char> = vec![];\n\n let mut cap = 3;\n let mut num = 0;\n\n while num < cap {\n let r = &mut rng;\n\n let char_type = r.sample(Alphanumeric);\n\n match char_type {\n 'a'...'z' => {\n chars.push(char_type);\n }\n 'A'...'Z' => {\n chars.push(char_type);\n }\n '0'...'9' => {\n chars.push(char_type);\n }\n _ => {\n chars.push(char_type);\n }\n }\n num += 1;\n }\n\n for _ in 0..password_length {\n let r = &mut rng;\n\n let char_type = r.choose(&mut letters).unwrap();\n\n password.push(*char_type);\n }\n\n for _ in 0..password_length {\n let r = &mut rng;\n\n let char_type = r.choose(&mut digits).unwrap();\n\n password.push(*char_type);\n }\n\n for _ in 0..password_length {\n let r = &mut rng;\n\n let char_type = r.choose(&mut symbols).unwrap();\n\n password.push(*char_type);\n }\n\n let password = password.chars().collect::<String>();\n let password = password.chars().collect::<Vec<char>>();\n\n let mut password = password.iter().map(|x| *x).collect::<String>();\n\n let password = password.as_str();\n\n println!(\"Random password: {}\", password);\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::prelude::*;\n\nfn main() {\n let mut rng = thread_rng();\n let mut numbers: Vec<i32> = (0..10).collect();\n\n println!(\"Random numbers: {:?}\", numbers);\n println!(\"Random number: {}\", random_item(&mut rng, &numbers));\n}\n\nfn random_item<T: Rng, U: Iterator<Item = T>>(rng: &mut T, iterator: &mut U) -> T::Item {\n iterator.choose(rng).unwrap()\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": "extern crate rand;\nuse rand::prelude::*;\nuse rand::distributions::Alphanumeric;\nuse rand::distributions::Distribution;\nuse rand::thread_rng;\n\nfn main() {\n let mut rng = thread_rng();\n let mut chars = Alphanumeric.sample_iter(&mut rng).take(10).collect::<String>();\n let random_string: String = rand::random::<String>().unwrap();\n\n let my_numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];\n let mut random_numbers: Vec<i32> = vec![];\n\n for _ in 0..5 {\n let random_index = rng.gen_range(0, my_numbers.len());\n random_numbers.push(my_numbers[random_index]);\n }\n\n println!(\"Random string: {}\", random_string);\n println!(\"Random numbers: {:?}\", random_numbers);\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;\n\nfn main() {\n let mut rng = rand::thread_rng();\n\n let mut random_number: u8 = rng.gen_range(1, 101);\n let mut random_index: usize = rng.gen_range(0, 100);\n\n let numbers: [u8; 100] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100];\n let random_item: u8 = numbers[random_index];\n \n let random_string: &str = \"Hello, World!\";\n\n println!(\"Random number: {}\", random_number);\n println!(\"Random index: {}\", random_index);\n println!(\"Random item: {}\", random_item);\n println!(\"Random string: {}\", random_string);\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::Rng;\n\nfn main() {\n let mut rng = rand::thread_rng();\n\n let random_number = rng.gen::<i32>();\n println!(\"Random number: {}\", random_number);\n\n let mut rng = rand::thread_rng();\n let random_item: &str = random_item(&[\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\"]);\n\n println!(\"Random item: {}\", random_item);\n\n let mut rng = rand::thread_rng();\n let random_item: &str = random_item(&[\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\", \"fig\", \"grape\"]);\n\n println!(\"Random item: {}\", random_item);\n\n let mut rng = rand::thread_rng();\n let random_item: &str = random_item(&[\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\", \"fig\", \"grape\", \"honeydew\", \"ice cream\"]);\n\n println!(\"Random item: {}\", random_item);\n\n let mut rng = rand::thread_rng();\n let random_item: &str = random_item(&[\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\", \"fig\", \"grape\", \"honeydew\", \"ice cream\", \"jackfruit\", \"kiwi\", \"lemon\", \"mango\", \"nectarine\", \"orange\", \"papaya\", \"quince\", \"raspberry\", \"strawberry\", \"tangerine\", \"ugli fruit\", \"victoria plum\", \"watermelon\", \"xigua\", \"yellow passion fruit\", \"zucchini\"]);\n\n println!(\"Random item: {}\", random_item);\n}\n\nfn random_item(items: &[&str]) -> &str {\n let mut rng = rand::thread_rng();\n items[rng.gen_range(0..items.len())]\n}"}