{"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;\n Ok(())\n}"} {"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 num = 1 / 0;\n let _ = num;\n Ok(())\n}"} {"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};\nuse std::fs;\n\nfn main() -> anyhow::Result<()> {\n let contents = fs::read_to_string(\"example.txt\")?;\n let len = contents.len();\n\n println!(\"file size: {}\", len);\n\n Ok(())\n}"} {"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;"} {"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::fs;\n\nfn main() -> Result<()> {\n let file = fs::File::open(\"non_existent_file.txt\")?;\n Ok(())\n}"} {"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::bail;\nuse anyhow::Context;\n\nfn main() -> Result<()> {\n let a = String::from(\"hello\");\n let b = a.clone();\n\n let c = a + b;\n let d = a + &b;\n\n let e = b + a;\n let f = &b + a;\n\n let g = &a + b;\n let h = &a + &b;\n\n let i = a + &b;\n let j = &a + &b;\n\n let k = b + &a;\n let l = &b + &a;\n\n let m = &b + a;\n let n = &b + &a;\n\n let o = &a + b;\n let p = &a + &b;\n\n let q = &a + &b;\n let r = &a + &b;\n\n let s = b + &a;\n let t = &b + &a;\n\n let u = &b + a;\n let v = &b + &a;\n\n let w = &a + b;\n let x = &a + &b;\n\n let y = &a + &b;\n let z = &a + &b;\n\n Ok(())\n}"} {"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, Context, Result};\nuse std::env;\nuse std::fs;\nuse std::process;\n\nfn main() -> anyhow::Result<()> {\n let mut args = env::args();\n let _ = args.next();\n let file = args.next().ok_or_else(|| anyhow!(\"missing file name\"))?;\n let contents = fs::read_to_string(&file).context(\"reading file\")?;\n println!(\"{}\", contents);\n Ok(())\n}"} {"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::env;\n\nfn main() {\n let args: Vec = env::args().collect();\n if args.len()!= 2 {\n println!(\"Usage: sum \");\n std::process::exit(1);\n }\n let filename = &args[1];\n if let Ok(lines) = std::fs::read_to_string(filename).map(Ok) {\n let numbers: Vec = lines.split_whitespace().map(|line| line.parse::().unwrap()).collect();\n let total: i64 = numbers.iter().filter(|&&n| n % 2 == 0).map(|&n| n * 2).sum();\n println!(\"{}\", total);\n } else {\n println!(\"Unable to open file\");\n std::process::exit(1);\n }\n}"} {"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 v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n let double = v.iter().map(|x| x * 2);\n let filtered = double.filter(|&x| x % 2 == 0);\n let sum = filtered.sum::();\n println!(\"{}\", sum);\n}"} {"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 map: HashMap = HashMap::new();\n map.insert(0, 1);\n map.insert(1, 2);\n map.insert(2, 3);\n map.insert(3, 4);\n map.insert(4, 5);\n\n let sum = map.iter()\n .map(|(_k, v)| *v)\n .sum::();\n\n println!(\"The sum is: {}\", sum);\n}"} {"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 v = vec![1, 2, 3, 4, 5];\n let sum: i32 = v.iter().filter(|x| x % 2 == 0).map(|x| x * x).sum();\n println!(\"{}\", sum);\n}"} {"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 = [1, 2, 3, 4, 5];\n\n let even_numbers = numbers.iter().filter(|&n| n % 2 == 0);\n let sum: u32 = even_numbers.map(|&n| n).sum();\n println!(\"{}\", sum);\n}"} {"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![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n let double_numbers: Vec = numbers.iter().map(|x| x * 2).collect();\n let sum: i32 = double_numbers.iter().filter(|&x| x % 2 == 0).sum();\n println!(\"The sum is: {}\", sum);\n}"} {"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 values: Vec = vec![1, 2, 3, 4, 5];\n\n let sum = values\n .into_iter()\n .filter(|x| *x % 2 == 0)\n .map(|x| x + 1)\n .sum::();\n\n println!(\"Sum of even numbers: {}\", sum);\n}"} {"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, Clone)]\npub struct U32x32([u8; 32]);\n\nimpl FromStr for U32x32 {\n type Err = String;\n\n fn from_str(s: &str) -> Result {\n let mut bytes = [0u8; 32];\n for (i, byte) in s.bytes().zip(bytes.iter_mut()) {\n *byte = i;\n }\n Ok(U32x32(bytes))\n }\n}\n\nimpl fmt::Display for U32x32 {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n for b in self.0.iter() {\n write!(f, \"{}\", b)?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let input = \"1234567890\".parse::().unwrap();\n println!(\"{:?}\", input);\n println!(\"{}\", input);\n}"} {"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, Clone, Copy)]\nstruct U32Array(pub [u8; 32]);\n\nimpl FromStr for U32Array {\n type Err = std::num::ParseIntError;\n\n fn from_str(s: &str) -> Result {\n if s.len()!= 32 {\n return Err(std::num::ParseIntError);\n }\n\n let mut v = [0u8; 32];\n for (i, b) in s.bytes().enumerate() {\n v[i] = b;\n }\n\n Ok(U32Array(v))\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:02x}\")?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let s = \"1234567890abcdef\";\n let arr = U32Array::from_str(s).unwrap();\n println!(\"{:?}\", arr);\n println!(\"{}\", arr);\n}"} {"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 BitVec([u8; 32]);\n\nimpl FromStr for BitVec {\n type Err = std::num::ParseIntError;\n\n fn from_str(s: &str) -> Result {\n if s.len()!= 32 {\n Err(std::num::ParseIntError)\n } else {\n let mut bits = [0u8; 32];\n for (i, c) in s.chars().enumerate() {\n bits[i] = u8::from_str_radix(&c.to_string(), 2).unwrap();\n }\n Ok(Self(bits))\n }\n }\n}\n\nimpl std::fmt::Display for BitVec {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n for bit in &self.0 {\n write!(f, \"{}\", bit)?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let bit_vec = \"1001001001010101001100000110001010101001000010000001010111101001001100100011011\"\n .parse()\n .unwrap();\n println!(\"{:?}\", bit_vec);\n println!(\"{}\", bit_vec);\n}"} {"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)]\npub struct PublicKey(pub [u8; 32]);\n\nimpl FromStr for PublicKey {\n type Err = String;\n\n fn from_str(s: &str) -> Result {\n match hex::decode(&s) {\n Ok(pubkey) => match PublicKey(pubkey) {\n Ok(pubkey) => Ok(pubkey),\n Err(_) => Err(\"Invalid public key\".to_string()),\n },\n Err(_) => Err(\"Invalid public key\".to_string()),\n }\n }\n}\n\nimpl std::fmt::Display for PublicKey {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n let mut s = String::new();\n for byte in &self.0 {\n s.push_str(&format!(\"{:02x}\", byte));\n }\n write!(f, \"{}\", s)\n }\n}"} {"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::str::FromStr;\nuse std::fmt;\n\nstruct U8Array32([u8; 32]);\n\nimpl FromStr for U8Array32 {\n type Err = String;\n\n fn from_str(s: &str) -> Result {\n let mut bytes = [0u8; 32];\n if s.len()!= 32 {\n return Err(\"String is too short to parse into 32 bytes\".to_string());\n }\n for (i, byte) in bytes.iter_mut().enumerate() {\n *byte = u8::from_str(&s[i..i+1])?;\n }\n Ok(U8Array32(bytes))\n }\n}\n\nimpl fmt::Display for U8Array32 {\n fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {\n let mut s = String::new();\n for byte in &self.0 {\n s.push_str(&byte.to_string());\n }\n write!(f, \"{}\", s)\n }\n}\n\nfn main() {\n let s = \"hello world\";\n let array = U8Array32::from_str(&s).unwrap();\n println!(\"{}\", array);\n}"} {"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::str::FromStr;\n\n#[derive(Debug)]\nstruct Hash32([u8; 32]);\n\nimpl FromStr for Hash32 {\n type Err = std::num::ParseIntError;\n\n fn from_str(s: &str) -> Result {\n let mut bytes = [0u8; 32];\n let len = u32::from_str_radix(s, 16).map_err(|_| std::num::ParseIntError {})?;\n\n if len > 32 {\n return Err(std::num::ParseIntError {});\n }\n\n let mut i = 0;\n for c in s.as_bytes() {\n if i >= len {\n break;\n }\n bytes[i] = *c;\n i += 1;\n }\n\n Ok(Hash32(bytes))\n }\n}\n\nimpl std::fmt::Display for Hash32 {\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\n Ok(())\n }\n}\n\nfn main() {\n let hash = \"b3b4b5b6b7b8b9b0b1b2b3\".parse::().unwrap();\n println!(\"{:?}\", hash);\n println!(\"{}\", hash);\n}"} {"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, Clone, Copy)]\nstruct U32Array([u8; 32]);\n\nimpl FromStr for U32Array {\n type Err = std::num::ParseIntError;\n\n fn from_str(s: &str) -> Result {\n if s.len()!= 32 {\n Err(std::num::ParseIntError::from(\"String must be 32 bytes\"))\n } else {\n let mut array = [0u8; 32];\n for (i, c) in s.bytes().enumerate() {\n if c < 0x30 || c > 0x39 {\n return Err(std::num::ParseIntError::from(\"Invalid character in string\"));\n }\n array[i] = c - 0x30;\n }\n Ok(U32Array(array))\n }\n }\n}\n\nimpl std::fmt::Display for U32Array {\n fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n for &byte in &self.0 {\n write!(f, \"{}\", byte as char)?;\n }\n Ok(())\n }\n}\n\nfn main() {\n let a = U32Array::from_str(\"00000000000000000000000000000000\").unwrap();\n println!(\"{:?}\", a);\n println!(\"{}\", a);\n}"} {"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)]\n#[error(\"IO error: {0}\")]\npub struct IOError(#[from] io::Error);\n\nfn main() {\n let file = std::fs::File::open(\"file_does_not_exist.txt\").map_err(IOError)?;\n let file = std::fs::File::open(\"file_does_not_exist.txt\")?;\n println!(\"{:?}\", file);\n}"} {"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(\"An error with {0}\")]\n Other(#[from] String),\n}\n\nfn run() -> Result<(), MyError> {\n let result = 2 + 2;\n let result = match result {\n 4 => Ok(()),\n _ => Err(MyError::Other(\"result was not 4\".to_string())),\n }?;\n Ok(())\n}\n\nfn main() {\n if let Err(e) = run() {\n println!(\"{:?}\", e);\n }\n}"} {"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": "// Define a custom error type using the `thiserror!` macro.\n#[derive(thiserror::Error, Debug)]\npub enum MyError {\n #[error(\"Could not connect to server: {0}\")]\n ServerConnection(String),\n #[error(\"Could not parse the response: {0}\")]\n ParseError(String),\n}\n\n// Implement the `Display` trait to print out a custom message when the error is printed.\nimpl std::fmt::Display for MyError {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n write!(f, \"{:?}\", self)\n }\n}\n\n// Define a custom source type to be used as a cause of the error.\n#[derive(Debug)]\npub struct Source {\n message: String,\n}\n\nimpl Source {\n pub fn new(message: impl Into) -> Self {\n Self {\n message: message.into(),\n }\n }\n}\n\n// Define a function using the `?` operator to propagate errors.\nfn connect_to_server() -> Result<(), MyError> {\n let source = Source::new(\"Could not connect to server\");\n Err(MyError::ServerConnection(source.message.clone()))\n}\n\nfn main() {\n if let Err(e) = connect_to_server() {\n println!(\"Error: {}\", e);\n }\n}"} {"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 MyError {\n #[error(\"MyError: {0}\")]\n MyError(String),\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::MyError(e) => write!(f, \"MyError: {}\", e),\n }\n }\n}\n\nfn main() {\n let result = do_something();\n match result {\n Ok(v) => println!(\"Success: {:?}\", v),\n Err(e) => println!(\"Error: {}\", e),\n }\n}\n\nfn do_something() -> Result {\n Err(MyError::MyError(\"Something went wrong\".to_string()))\n}"} {"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 MyError {\n #[error(\"invalid input\")]\n InvalidInput(#[from] std::fmt::Error),\n #[error(\"invalid value: {0}\")]\n InvalidValue(i32),\n}\n\nfn main() {\n match 1.1.parse::() {\n Ok(v) => println!(\"Parsed: {}\", v),\n Err(e) => {\n if let MyError::InvalidInput(_) = e {\n println!(\"Input error\");\n } else if let MyError::InvalidValue(v) = e {\n println!(\"Invalid value: {}\", v);\n }\n }\n }\n}"} {"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 #[error(\"not a number: {0}\")]\n NotANumber(String),\n #[error(\"not a string\")]\n NotAString,\n #[error(\"error with code: {0}\")]\n CustomError(usize),\n}\n\nfn get_number(s: &str) -> Result {\n match s.parse::() {\n Ok(num) => Ok(num),\n Err(_) => Err(MyError::NotANumber(s.to_string())),\n }\n}\n\nfn get_string(s: &str) -> Result {\n match s.to_string().as_str() {\n \"test\" => Ok(\"test\".to_string()),\n _ => Err(MyError::NotAString),\n }\n}\n\nfn get_custom_error(s: &str) -> Result<(), MyError> {\n if s == \"test\" {\n Ok(())\n } else {\n Err(MyError::CustomError(10))\n }\n}\n\nfn main() {\n let num = get_number(\"test\");\n println!(\"result: {:?}\", num);\n\n let str = get_string(\"test\");\n println!(\"result: {:?}\", str);\n\n let error = get_custom_error(\"test\");\n println!(\"result: {:?}\", error);\n}"} {"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, thiserror)]\npub enum MyError {\n #[error(\"Could not open file: {0}\")]\n FileOpen(std::io::Error),\n #[error(\"Could not read file: {0}\")]\n FileRead(std::io::Error),\n}\n\nfn main() {\n let file = std::fs::File::open(\"non-existent-file.txt\").unwrap();\n let result = std::io::Read::read_to_string(&file).map_err(MyError::FileRead).unwrap();\n println!(\"{}\", result);\n}"} {"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 // Import the necessary module\n use std::cmp::Ordering;\n\n // A list of numbers\n let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n // A for loop to print the numbers in ascending order\n for number in &numbers {\n match number.cmp(&5) {\n Ordering::Less => println!(\"{} is less than 5\", number),\n Ordering::Equal => println!(\"{} is equal to 5\", number),\n Ordering::Greater => println!(\"{} is greater than 5\", number),\n }\n }\n\n // An if let statement to print the numbers greater than 5\n if let Some(number) = numbers.iter().find(|x| x > &5) {\n println!(\"The first number greater than 5 is {}\", number);\n }\n\n // A match statement to print the sum of the numbers\n match numbers.iter().sum::() {\n 0 => println!(\"The sum is 0\"),\n _ => println!(\"The sum is not 0\"),\n }\n}"} {"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 = 1;\n\n // Matching with `match`\n match x {\n 1 => println!(\"one\"),\n 2 => println!(\"two\"),\n 3 => println!(\"three\"),\n _ => println!(\"anything\"),\n }\n\n // Matching with `if let`\n if let Some(y) = Some(2) {\n println!(\"y = {}\", y);\n }\n}"} {"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 = 1;\n let b = \"one\";\n\n let c = 2;\n let d = \"two\";\n\n // Pattern matching with match\n match a {\n 1 => println!(\"a is 1\"),\n 2 => println!(\"a is 2\"),\n _ => println!(\"a is something else\"),\n }\n\n // Pattern matching with if let\n if let 1 = a {\n println!(\"a is 1\");\n } else {\n println!(\"a is not 1\");\n }\n\n // Pattern matching with if let for reference\n let ref x = \"one\";\n if let Some(y) = x {\n println!(\"x is Some({})\", y);\n } else {\n println!(\"x is None\");\n }\n\n // Pattern matching with if let for reference with pattern binding\n if let Some(ref y) = x {\n println!(\"x is Some({})\", y);\n } else {\n println!(\"x is None\");\n }\n\n // Pattern matching with if let for tuple\n let (x, y) = (1, 2);\n if let (1, 2) = (x, y) {\n println!(\"x is 1 and y is 2\");\n } else {\n println!(\"x is not 1 and y is not 2\");\n }\n\n // Pattern matching with if let for tuple with pattern binding\n let (x, y) = (1, 2);\n if let (1, ref y) = (x, y) {\n println!(\"x is 1 and y is 2\");\n } else {\n println!(\"x is not 1 and y is not 2\");\n }\n\n // Pattern matching with match for tuple\n match (x, y) {\n (1, 2) => println!(\"x is 1 and y is 2\"),\n (1, ref y) => println!(\"x is 1 and y is {}\", y),\n _ => println!(\"x is not 1 and y is not 2\"),\n }\n\n // Pattern matching with match for tuple with pattern binding\n let (x, y) = (1, 2);\n match (x, y) {\n (1, 2) => println!(\"x is 1 and y is 2\"),\n (1, ref y) => println!(\"x is 1 and y is {}\", y),\n _ => println!(\"x is not 1 and y is not 2\"),\n }\n}"} {"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 values to be matched\n let numbers = [1, 2, 3, 4, 5, 6];\n let numbers = vec![1, 2, 3, 4, 5, 6];\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }\n\n // match with tuple pattern\n match (1, 2, 3) {\n (1, 2, 3) => println!(\"one two three\"),\n _ => println!(\"Not one two three\"),\n }"} {"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": "// This is a simple Rust program that demonstrates how to use match and if let for pattern matching.\n// It also shows the difference between the two.\n\n// The program defines a few different types and then uses them in a few match and if let statements.\n\n// The program prints the results of each match and if let to the console.\n\nfn main() {\n // Define a variable of type String\n let s = \"hello\".to_string();\n\n // match with pattern matching\n match s.as_str() {\n \"hello\" => println!(\"hello\"),\n \"world\" => println!(\"world\"),\n _ => println!(\"unknown\"),\n }\n\n // match with pattern matching and binding\n match s.as_str() {\n \"hello\" => println!(\"hello\"),\n \"world\" => println!(\"world\"),\n s => println!(\"unknown: {}\", s),\n }\n\n // if let with pattern matching and binding\n if let \"hello\" = s.as_str() {\n println!(\"hello\");\n } else if let \"world\" = s.as_str() {\n println!(\"world\");\n } else {\n println!(\"unknown\");\n }\n\n // if let with pattern matching and binding\n if let Some(s) = s.as_str().strip_suffix(\"o\") {\n println!(\"{}o\", s);\n } else {\n println!(\"no o\");\n }\n}"} {"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 = 1;\n let b = 2;\n let c = 3;\n let d = 4;\n\n // pattern matching with if let\n if let 1 = a {\n println!(\"a is 1\");\n } else if let 2 = b {\n println!(\"b is 2\");\n } else {\n println!(\"a and b are not 1 or 2\");\n }\n\n // pattern matching with match\n match a {\n 1 => println!(\"a is 1\"),\n 2 => println!(\"a is 2\"),\n 3 => println!(\"a is 3\"),\n _ => println!(\"a is not 1, 2 or 3\"),\n }\n\n // pattern matching with match\n match d {\n 1 | 2 => println!(\"d is 1 or 2\"),\n 3 => println!(\"d is 3\"),\n 4 => println!(\"d is 4\"),\n _ => println!(\"d is not 1, 2, 3 or 4\"),\n }\n}"} {"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::cmp::Ordering;\n\nfn main() {\n // match statement\n let number = 5;\n match number {\n 1 => println!(\"One\"),\n 2 => println!(\"Two\"),\n 3 => println!(\"Three\"),\n _ => println!(\"A generic value\"),\n }\n\n // if let statement\n let number = 4;\n if let 1 = number {\n println!(\"One\");\n } else {\n println!(\"Not One\");\n }\n\n // let pattern\n let number = Some(3);\n if let Some(3) = number {\n println!(\"Three\");\n }\n\n // let pattern with destructuring\n let point = (3, 4);\n match point {\n (0, 0) => println!(\"Origin\"),\n (0, y) => println!(\"On the y-axis at y = {}\", y),\n (x, 0) => println!(\"On the x-axis at x = {}\", x),\n (x, y) => println!(\"On the x-axis at x = {}, on the y-axis at y = {}\", x, y),\n }\n\n // let pattern with tuple structs\n let point = (0, 0, 0);\n match point {\n (0, 0, 0) => println!(\"Origin\"),\n (0, 0, y) => println!(\"On the z-axis at z = {}\", y),\n (0, x, 0) => println!(\"On the x-axis at x = {}\", x),\n (x, 0, 0) => println!(\"On the y-axis at y = {}\", x),\n (x, y, z) => println!(\"On the x-axis at x = {}, on the y-axis at y = {}, on the z-axis at z = {}\", x, y, z),\n }\n\n // let pattern with enum\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n Color::Green => println!(\"The color is green\"),\n Color::Red => println!(\"The color is red\"),\n }\n\n // let pattern with enum and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n Color::Green => println!(\"The color is green\"),\n Color::Red => println!(\"The color is red\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with wildcard\n let color = Color::Blue;\n match color {\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }\n\n // let pattern with tuple and wildcard\n let color = Color::Blue;\n match color {\n Color::Blue => println!(\"The color is blue\"),\n _ => println!(\"The color is not blue\"),\n }"} {"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": "// Define a struct Person\nstruct Person {\n name: String,\n age: i32,\n}\n\n// Define an impl block for Person\nimpl Person {\n // Constructor\n fn new(name: String, age: i32) -> Self {\n Self { name, age }\n }\n\n // Method to print the person's details\n fn print_details(&self) {\n println!(\"Name: {}\", self.name);\n println!(\"Age: {}\", self.age);\n }\n}\n\n// Define a trait Animal\ntrait Animal {\n fn sound(&self);\n}\n\n// Implement the trait Animal for Person\nimpl Animal for Person {\n fn sound(&self) {\n println!(\"BEEP\");\n }\n}\n\nfn main() {\n // Create a Person instance\n let person = Person::new(\"John\".to_string(), 30);\n\n // Call the constructor method\n let person2 = Person::new(\"Jane\".to_string(), 30);\n\n // Call the print_details method\n person.print_details();\n\n // Call the sound method\n person.sound();\n}"} {"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 Circle {\n radius: f64,\n}\n\nimpl Circle {\n pub fn new(radius: f64) -> Circle {\n Circle { radius }\n }\n\n pub fn area(&self) -> f64 {\n self.radius * self.radius * std::f64::consts::PI\n }\n}\n\ntrait Shape {\n fn get_area(&self) -> f64;\n}\n\nimpl Shape for Circle {\n fn get_area(&self) -> f64 {\n self.area()\n }\n}\n\nfn main() {\n let c = Circle::new(5.0);\n let area = c.get_area();\n println!(\"The area of the circle is {}\", area);\n}"} {"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": "// Define a struct\nstruct Person {\n name: String,\n age: u8,\n}\n\n// Implement a trait for the struct\nimpl Person {\n // Constructor\n pub fn new(name: String, age: u8) -> Self {\n Person { name, age }\n }\n\n // Method\n pub fn greet(&self) {\n println!(\"Hello, my name is {} and I am {} years old.\", self.name, self.age);\n }\n}\n\n// Trait\ntrait Animal {\n fn speak(&self) -> String;\n}\n\n// Implement the trait for the struct\nimpl Animal for Person {\n fn speak(&self) -> String {\n \"Hello, how are you?\".to_string()\n }\n}\n\nfn main() {\n // Create an instance of the struct\n let person = Person::new(\"John\".to_string(), 25);\n\n // Use the trait method\n println!(\"{}\", person.speak());\n\n // Use the method on the struct\n person.greet();\n}"} {"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) -> Self {\n Point { x, y }\n }\n}\n\ntrait Shape {\n fn area(&self) -> i32;\n fn perimeter(&self) -> i32;\n}\n\nimpl Shape for Point {\n fn area(&self) -> i32 {\n self.x * self.y\n }\n\n fn perimeter(&self) -> i32 {\n 2 * (self.x + self.y)\n }\n}\n\nfn main() {\n let p1 = Point::new(3, 5);\n println!(\"Area: {}\", p1.area());\n println!(\"Perimeter: {}\", p1.perimeter());\n}"} {"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: String, age: u32) -> Self {\n Self { name, age }\n }\n}\n\ntrait Greeting {\n fn greet(&self) -> String;\n}\n\nimpl Greeting for Person {\n fn greet(&self) -> String {\n format!(\"Hello, my name is {} and I am {} years old\", self.name, self.age)\n }\n}\n\nfn main() {\n let person = Person::new(\"Alice\".to_string(), 30);\n println!(\"{}\", person.greet());\n}"} {"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": "// Define a trait for the data to be printed\ntrait Printable {\n fn print(&self);\n}\n\n// Define a struct to hold the data to be printed\nstruct Data {\n name: String,\n age: i32,\n}\n\n// Implement the trait for the struct\nimpl Printable for Data {\n // Implement the `print` function for the struct\n fn print(&self) {\n println!(\"Name: {}\", self.name);\n println!(\"Age: {}\", self.age);\n }\n}\n\n// Define the main function\nfn main() {\n // Create an instance of the struct\n let data = Data {\n name: \"John\".to_string(),\n age: 25,\n };\n\n // Use the `print` function to print the data\n data.print();\n}"} {"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": "// Define a trait\ntrait HasArea {\n fn area(&self) -> f64;\n}\n\n// Define a struct\nstruct Rectangle {\n width: f64,\n height: f64,\n}\n\n// Implement the trait for Rectangle\nimpl HasArea for Rectangle {\n fn area(&self) -> f64 {\n self.width * self.height\n }\n}\n\nfn main() {\n // Create an instance of Rectangle\n let r = Rectangle { width: 2.0, height: 4.0 };\n\n // Use the trait method\n let area = r.area();\n\n println!(\"The area of the rectangle is {}\", area);\n}"} {"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::{Serialize, Deserialize};\n\n#[derive(Serialize, Deserialize)]\nstruct User {\n username: String,\n email: String,\n age: u8,\n}\n\nfn main() {\n let user = User {\n username: \"johndoe\".to_string(),\n email: \"johndoe@example.com\".to_string(),\n age: 32,\n };\n\n let user_json = serde_json::to_string(&user).unwrap();\n println!(\"User in JSON format: {}\", user_json);\n\n let deserialized_user: User = serde_json::from_str(&user_json).unwrap();\n println!(\"Deserialized User: {:?}\", deserialized_user);\n}"} {"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 json = serde_json::to_string(&user).unwrap();\n println!(\"Serialized: {}\", json);\n\n let user: User = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized: {:?}\", user);\n}"} {"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 friends: Vec,\n}\n\nfn main() {\n let person = Person {\n name: \"John\".to_string(),\n age: 25,\n friends: vec![\"Alice\".to_string(), \"Bob\".to_string()],\n };\n\n let serialized = serde_json::to_string(&person).unwrap();\n println!(\"Serialized JSON: {}\", serialized);\n\n let deserialized: Person = serde_json::from_str(&serialized).unwrap();\n println!(\"Deserialized JSON: {:?}\", deserialized);\n}"} {"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: 30,\n };\n\n let serialized = serde_json::to_string(&person).unwrap();\n println!(\"serialized JSON: {}\", serialized);\n\n let deserialized: Person = serde_json::from_str(&serialized).unwrap();\n println!(\"deserialized: {:?}\", deserialized);\n}"} {"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": "#[macro_use]\nextern crate serde_derive;\nextern crate serde_json;\n\nuse serde_json::to_string_pretty;\n\n#[derive(Debug, Serialize, Deserialize)]\nstruct Person {\n first_name: String,\n last_name: String,\n age: u8,\n}\n\nfn main() {\n let mut person = Person {\n first_name: \"John\".to_string(),\n last_name: \"Doe\".to_string(),\n age: 20,\n };\n\n println!(\"Person: {:?}\", person);\n\n let json = to_string_pretty(&person).unwrap();\n println!(\"JSON: {}\", json);\n\n let new_person: Person = serde_json::from_str(&json).unwrap();\n println!(\"New Person: {:?}\", new_person);\n}"} {"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 name: String,\n age: u8,\n}\n\nfn main() {\n let user = User {\n id: 1,\n name: \"John\".to_string(),\n age: 30,\n };\n\n let json = serde_json::to_string(&user).unwrap();\n println!(\"JSON: {}\", json);\n\n let deserialized: User = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized User: {:?}\", deserialized);\n}"} {"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": "#[derive(Debug, Serialize, Deserialize)]\nstruct Person {\n name: String,\n age: u8,\n}\n\nfn main() {\n let person = Person {\n name: \"John\".to_string(),\n age: 30,\n };\n\n let json = serde_json::to_string(&person).unwrap();\n println!(\"JSON: {}\", json);\n\n let deserialized_person: Person = serde_json::from_str(&json).unwrap();\n println!(\"Deserialized: {:?}\", deserialized_person);\n}"} {"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 // Example text\n let text = \"The quick brown fox jumps over the lazy dog.\";\n\n // Replace 'o' with '0'\n let re = Regex::new(\"o\").unwrap();\n let text = re.replace_all(&text, \"0\").to_string();\n\n println!(\"Original text: {}\", text);\n println!(\"Replaced text: {}\", text.replace(\"0\", \"o\"));\n}"} {"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 mut text = \"The quick brown fox jumps over the lazy dog. Foxes are quick animals.\";\n\n let re = Regex::new(\"fox\").unwrap();\n let new_text = re.replace_all(&text, \"cat\");\n\n println!(\"{}\", new_text);\n}"} {"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+\\b\").unwrap();\n let text = \"The quick brown fox jumps over the lazy dog. The dog barks at the fox.\";\n let text = re.replace_all(&text, \"\");\n println!(\"{}\", text);\n}"} {"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 test string with multiple words. It should be replaced.\";\n let pattern = Regex::new(r\"\\btest\\b\").unwrap();\n let replaced = pattern.replace_all(&text, \"replaced\");\n\n println!(\"{}\", replaced);\n}"} {"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 // Example text\n let text = \"This is a sample text with some 1, 2, 3 and 4 digits.\";\n\n // Regular expression pattern\n let pattern = Regex::new(r\"(\\d+)\").unwrap();\n let replacement = \"x\";\n\n // Replace all occurrences of 1, 2, 3 and 4 digits with \"x\"\n let new_text = pattern.replace_all(&text, &replacement);\n\n // Print the result\n println!(\"{}\", new_text);\n}"} {"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 pattern = \"abc\";\n let text = \"abc abc abc\";\n let re = Regex::new(pattern).unwrap();\n let text = re.replace_all(&text, \"def\");\n println!(\"{}\", text);\n}"} {"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 email address is john.doe@example.com and my phone number is 123-456-7890.\";\n let re = Regex::new(r\"(\\d{3}-\\d{3}-\\d{4})\").unwrap();\n let replacement = \"XXX-XXX-XXXX\";\n let new_text = re.replace_all(&text, replacement).to_string();\n println!(\"{}\", new_text);\n}"} {"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, Utc};\n\nfn main() {\n let date_string = \"2015-01-01 00:00:00\";\n let date = DateTime::parse_from_rfc3339(date_string).unwrap();\n let formatted = date.format(\"%A, %b %e, %Y\").to_string();\n println!(\"Date: {}\", formatted);\n \n let date_string = \"2015-01-01T00:00:00+00:00\";\n let date = DateTime::parse_from_rfc3339(date_string).unwrap();\n let formatted = date.format(\"%A, %b %e, %Y\").to_string();\n println!(\"Date: {}\", formatted);\n}"} {"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;\nuse chrono::offset::TimeZone;\nuse chrono::offset::Utc;\nuse chrono::offset::TimeZone;\nuse chrono::Local;\n\nfn main() {\n // Using Utc\n let date = \"2022-12-25 14:00:00\";\n let parsed_date = NaiveDateTime::parse_from_str(date, \"%Y-%m-%d %H:%M:%S\").unwrap();\n let formatted_date = Utc.from_utc_datetime(&parsed_date).format(\"%B %d, %Y\");\n println!(\"Using Utc: {}\", formatted_date);\n\n // Using Local\n let date = \"2022-12-25 14:00:00\";\n let parsed_date = NaiveDateTime::parse_from_str(date, \"%Y-%m-%d %H:%M:%S\").unwrap();\n let formatted_date = Local.from_utc_datetime(&parsed_date).format(\"%B %d, %Y\");\n println!(\"Using Local: {}\", formatted_date);\n}"} {"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, ParseError, Utc};\n\nfn parse_and_format(s: &str) -> Result {\n let dt: DateTime = s.parse()?;\n Ok(dt.to_rfc3339())\n}\n\nfn main() {\n let mut vec: Vec = Vec::new();\n\n vec.push(parse_and_format(\"2022-01-01\").unwrap());\n vec.push(parse_and_format(\"2022-01-01T00:00:00\").unwrap());\n vec.push(parse_and_format(\"2022-01-01T00:00:00.000000\").unwrap());\n vec.push(parse_and_format(\"2022-01-01T00:00:00.000001\").unwrap());\n vec.push(parse_and_format(\"2022-01-01T00:00:00.123456\").unwrap());\n vec.push(parse_and_format(\"2022-01-01T00:00:00.123456789\").unwrap());\n vec.push(parse_and_format(\"2022-01-01T00:00:00.123456789012\").unwrap());\n\n for s in vec {\n println!(\"{}\", s);\n }\n}"} {"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::{self, ItemFormatSpecifier};\n\nfn main() {\n let date_str = \"2021-07-07 13:37:27\";\n let date = date_str.parse::().unwrap();\n\n // Parse date with time zone\n let date_with_tz = date.with_timezone(&chrono::offset::Local);\n let parsed_date = date_str.parse::().unwrap();\n println!(\"Parsed date with time zone: {:?}\", parsed_date.with_timezone(&chrono::offset::Local));\n\n // Parse date and time\n let parsed_date_time = date_str.parse::().unwrap();\n println!(\"Parsed date and time: {:?}\", parsed_date_time);\n\n // Parse date and time with time zone\n let parsed_date_time_with_tz = date_str.parse::().unwrap();\n println!(\"Parsed date and time with time zone: {:?}\", parsed_date_time_with_tz.with_timezone(&chrono::offset::Local));\n\n // Format date with time zone\n let formatted_date = date_with_tz.format(\"%a, %b %d %Y %H:%M:%S %Z%z\").to_string();\n println!(\"Formatted date with time zone: {}\", formatted_date);\n\n // Format date and time\n let formatted_date_time = parsed_date_time.format(\"%a, %b %d %Y %H:%M:%S %Z%z\").to_string();\n println!(\"Formatted date and time: {}\", formatted_date_time);\n\n // Format date and time with time zone\n let formatted_date_time_with_tz = parsed_date_time_with_tz.format(\"%a, %b %d %Y %H:%M:%S %Z%z\").to_string();\n println!(\"Formatted date and time with time zone: {}\", formatted_date_time_with_tz);\n}"} {"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": "extern crate chrono;\n\nfn main() {\n let date = \"1978-11-25\".parse::().unwrap();\n let formatted = date.format(\"%a, %B %e, %Y\").to_string();\n println!(\"Parsed date: {:?}\", date);\n println!(\"Formatted date: {}\", formatted);\n \n let date = \"2020-05-15\".parse::().unwrap();\n let formatted = date.format(\"%a, %B %e, %Y\").to_string();\n println!(\"Parsed date: {:?}\", date);\n println!(\"Formatted date: {}\", formatted);\n}"} {"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 let date = DateTime::parse_from_rfc2822(\"Wed, 15 Apr 2020 12:30:30 +0000\").unwrap();\n println!(\"Date: {}\", date);\n\n let date = DateTime::parse_from_rfc2822(\"Wed, 15 Apr 2020 12:30:30 +0000\").unwrap();\n println!(\"Date: {}\", date.format(\"%Y-%m-%d %H:%M:%S%z\"));\n\n let date = DateTime::parse_from_rfc2822(\"Wed, 15 Apr 2020 12:30:30 +0000\").unwrap();\n println!(\"Date: {}\", date.format(\"%A, %B %d %Y %H:%M:%S%z\"));\n\n let date = DateTime::parse_from_rfc2822(\"Wed, 15 Apr 2020 12:30:30 +0000\").unwrap();\n println!(\"Date: {}\", date.format(\"%A, %B %d %Y %H:%M:%S%z\"));\n\n let date = DateTime::parse_from_rfc2822(\"Wed, 15 Apr 2020 12:30:30 +0000\").unwrap();\n println!(\"Date: {}\", date.format(\"%a %b %e %H:%M:%S%z\"));\n}"} {"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;\nuse chrono::NaiveDate;\nuse chrono::NaiveTime;\n\nfn main() {\n let date = NaiveDate::from_ymd(2020, 12, 1);\n let time = NaiveTime::from_hms(14, 10, 30);\n let datetime = NaiveDateTime::new(date, time);\n\n // Format to \"2020-12-01 14:10:30\"\n println!(\"{}\", datetime);\n\n // Format to \"2020-12-01 14:10\"\n println!(\"{}\", datetime.with_time(0));\n\n // Format to \"2020-12-01 14:10:30 UTC\"\n println!(\"{}\", datetime.with_timezone(&chrono::Utc));\n\n // Format to \"2020-12-01 14:10:30 +00:00\"\n println!(\"{}\", datetime.with_timezone(&chrono::TimeZone::offset(0)));\n\n // Format to \"2020-12-01\"\n println!(\"{}\", datetime.date());\n\n // Format to \"2020-12-01 14:10:30\"\n println!(\"{}\", datetime.time());\n\n // Format to \"2020-12-01 14:10:30 +00:00\"\n println!(\"{}\", datetime.with_timezone(&chrono::FixedOffset::east(0)).to_string());\n\n // Format to \"2020-12-01 14:10:30 +00:00\"\n println!(\"{}\", datetime.with_timezone(&chrono::FixedOffset::east(0)).to_string());\n\n // Format to \"2020-12-01 14:10:30\"\n println!(\"{}\", datetime.with_timezone(&chrono::FixedOffset::east(0)).format(\"%Y-%m-%d %H:%M:%S\"));\n}"} {"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 fixed node and clock sequence\n let fixed_uuid = Uuid::new_v4_with_timestamp_and_clock_sequence(0, 0);\n println!(\"Fixed UUID: {:?}\", fixed_uuid);\n\n // Generate a random UUID from a slice of bytes\n let bytes: [u8; 16] = [0u8; 16];\n let uuid_from_bytes = Uuid::from_bytes(bytes);\n println!(\"UUID from bytes: {:?}\", uuid_from_bytes);\n\n // Generate a random UUID from a slice of bytes with a fixed node\n let bytes: [u8; 16] = [0u8; 16];\n let uuid_from_bytes_with_node = Uuid::from_bytes_with_node(bytes, 0);\n println!(\"UUID from bytes with node: {:?}\", uuid_from_bytes_with_node);\n\n // Generate a random UUID from a string\n let uuid_from_string = Uuid::parse_str(\"6f2c3a1a-0dcd-4e7f-8b6d-7b1b7c8d9e0f\");\n println!(\"UUID from string: {:?}\", uuid_from_string);\n\n // Generate a random UUID from a string with a fixed node\n let uuid_from_string_with_node = Uuid::parse_str_with_node(\"6f2c3a1a-0dcd-4e7f-8b6d-7b1b7c8d9e0f\", 0);\n println!(\"UUID from string with node: {:?}\", uuid_from_string_with_node);\n}"} {"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 specific version\n let random_uuid = Uuid::new_v4().is_version(1);\n println!(\"Random UUID v1: {}\", random_uuid);\n\n // Generate a random UUID with a specific version and node\n let random_uuid = Uuid::new_v4().is_version(1).with_node(\"some-node\");\n println!(\"Random UUID v1 with node: {}\", random_uuid);\n\n // Generate a random UUID with a specific version, node, and clock sequence\n let random_uuid = Uuid::new_v4()\n .is_version(1)\n .with_node(\"some-node\")\n .with_clock_seq(42);\n println!(\"Random UUID v1 with node and clock sequence: {}\", random_uuid);\n\n // Generate a random UUID from a string\n let random_uuid = Uuid::parse_str(\"f3c6e3d6-8a99-4cfa-9e0a-4d2f4b9c6d65\");\n println!(\"Parsed UUID: {}\", random_uuid);\n\n // Generate a random UUID from a string with a specific version\n let random_uuid = Uuid::parse_str(\"f3c6e3d6-8a99-4cfa-9e0a-4d2f4b9c6d65\").is_version(1);\n println!(\"Parsed UUID v1: {}\", random_uuid);\n\n // Generate a random UUID from a string with a specific version and node\n let random_uuid = Uuid::parse_str(\"f3c6e3d6-8a99-4cfa-9e0a-4d2f4b9c6d65\")\n .is_version(1)\n .with_node(\"some-node\");\n println!(\"Parsed UUID v1 with node: {}\", random_uuid);\n\n // Generate a random UUID from a string with a specific version, node, and clock sequence\n let random_uuid = Uuid::parse_str(\"f3c6e3d6-8a99-4cfa-9e0a-4d2f4b9c6d65\")\n .is_version(1)\n .with_node(\"some-node\")\n .with_clock_seq(42);\n println!(\"Parsed UUID v1 with node and clock sequence: {}\", random_uuid);\n}"} {"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 = Uuid::new_v4();\n println!(\"new_v4: {}\", uuid);\n\n let uuid = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"rust-lang.org\");\n println!(\"new_v5: {}\", uuid);\n\n let uuid = Uuid::parse_str(\"7f9c2f8a-3c1b-4d0f-8d0c-1d3d8f1e8b8d\");\n println!(\"parse_str: {:?}\", uuid);\n\n let uuid = Uuid::parse_str(\"invalid-uuid\");\n match uuid {\n Ok(uuid) => println!(\"parse_str: {:?}\", uuid),\n Err(_) => println!(\"parse_str: Invalid UUID\")\n }\n\n let uuid = Uuid::parse_str(\"7f9c2f8a-3c1b-4d0f-8d0c-1d3d8f1e8b8d\");\n println!(\"parse_str: {:?}\", uuid);\n\n let uuid = Uuid::parse_str(\"invalid-uuid\");\n match uuid {\n Ok(uuid) => println!(\"parse_str: {:?}\", uuid),\n Err(_) => println!(\"parse_str: Invalid UUID\")\n }\n\n let uuid = Uuid::parse_str(\"7f9c2f8a-3c1b-4d0f-8d0c-1d3d8f1e8b8d\");\n println!(\"parse_str: {:?}\", uuid);\n\n let uuid = Uuid::parse_str(\"invalid-uuid\");\n match uuid {\n Ok(uuid) => println!(\"parse_str: {:?}\", uuid),\n Err(_) => println!(\"parse_str: Invalid UUID\")\n }\n}"} {"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 id = Uuid::new_v4();\n println!(\"Random UUID: {}\", id);\n let id = Uuid::new_v5(Uuid::NAMESPACE_URL, \"https://www.rust-lang.org/\");\n println!(\"UUID from URL: {}\", id);\n let id = Uuid::parse_str(\"c7c7f6c6-9fdd-4b1f-8e9f-b0e8c5b5f7f6\");\n match id {\n Ok(id) => println!(\"Parsed UUID: {}\", id),\n Err(e) => println!(\"Error: {}\", e),\n }\n}"} {"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 = Uuid::new_v4();\n println!(\"{}\", uuid);\n let uuid = Uuid::parse_str(\"00000000-0000-0000-0000-000000000000\");\n println!(\"{}\", uuid);\n}"} {"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::parse_str(\"2f9b9e3f-7b8c-4f0b-b2b8-1a4b7a0b4b7a\").unwrap());\n let a = Uuid::parse_str(\"2f9b9e3f-7b8c-4f0b-b2b8-1a4b7a0b4b7a\").unwrap();\n println!(\"{}\", a);\n let b = Uuid::parse_str(\"2f9b9e3f-7b8c-4f0b-b2b8-1a4b7a0b4b7a\").unwrap();\n println!(\"{}\", b);\n println!(\"{}\", Uuid::new_v4());\n let c = Uuid::new_v4();\n println!(\"{}\", c);\n println!(\"{}\", c);\n}"} {"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": "extern crate uuid;\n\nuse uuid::Uuid;\n\nfn main() {\n // Generate a random UUID\n let random_uuid = Uuid::new_v4();\n println!(\"Random UUID: {:?}\", random_uuid);\n\n // Generate a random UUID from a specific variant\n let random_uuid_v5 = Uuid::new_v5(Uuid::NAMESPACE_DNS, \"example.com\");\n println!(\"Random UUID (v5): {:?}\", random_uuid_v5);\n\n // Generate a random UUID from a specific namespace\n let random_uuid_ns = Uuid::new_v4();\n println!(\"Random UUID from Namespace: {:?}\", random_uuid_ns);\n}"} {"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 let v: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n let random_item: i32 = rng.gen_range(0, 10);\n let random_item = v[random_item as usize];\n\n println!(\"Random item: {}\", random_item);\n\n let random_item: i32 = rng.gen_range(0, 10);\n let random_item = v[random_item as usize];\n\n println!(\"Random item: {}\", random_item);\n}"} {"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::*;\nuse rand::distributions::Alphanumeric;\nuse rand::Rng;\n\nfn main() {\n let mut rng = thread_rng();\n let random_number: u32 = rng.gen_range(0..100);\n let mut random_char = String::new();\n for _ in 0..random_number {\n random_char.push(rng.sample(Alphanumeric));\n }\n\n println!(\"Random number: {}\", random_number);\n println!(\"Random char: {}\", random_char);\n}"} {"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::{Distribution, Range};\nuse rand::prelude::*;\n\nfn main() {\n // Generate a random number between 0 and 10\n let mut rng = rand::thread_rng();\n let random_number: u32 = rng.gen_range(0..10);\n println!(\"Random number: {}\", random_number);\n\n // Create a vector\n let mut numbers: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n println!(\"Random numbers: {:?}\", numbers);\n\n // Select a random number from the vector\n let random_number_from_vec: u32 = numbers\n .iter()\n .choose(&mut rng)\n .unwrap()\n .clone();\n\n println!(\"Random number from vector: {}\", random_number_from_vec);\n\n // Select a random number from 0 to 10\n let random_number_from_range: u32 = rng.sample(Range::new(0, 10));\n\n println!(\"Random number from range: {}\", random_number_from_range);\n}"} {"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 // create a vector of numbers\n let numbers = vec![1, 2, 3, 4, 5];\n\n // get a random number from 0 to 4\n let mut rng = thread_rng();\n let random_index = rng.gen_range(0..5);\n\n // select a random number from the vector\n let random_number = numbers[random_index];\n\n println!(\"Random number: {}\", random_number);\n}"} {"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 my_vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];\n\n println!(\"Random number: {}\", rng.gen::());\n println!(\"Random number between 1 and 100: {}\", rng.gen_range(1..=100));\n\n let random_element: i32 = rng.gen_range(0..my_vec.len());\n println!(\"Random element: {}\", my_vec[random_element as usize]);\n}"} {"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 let mut numbers: Vec = Vec::new();\n for _ in 0..10 {\n numbers.push(rng.gen_range(0, 100));\n }\n let max = *numbers.iter().max().unwrap();\n let min = *numbers.iter().min().unwrap();\n let range: u32 = rng.gen_range(min..=max);\n println!(\"Random number in range: {}\", range);\n let mut numbers = vec![1, 2, 3, 4, 5];\n let random_item = &numbers[rng.gen_range(0..numbers.len())];\n println!(\"Random item: {}\", random_item);\n}"} {"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 items = vec![\"apple\", \"banana\", \"orange\", \"grape\", \"strawberry\"];\n let random_item = items.choose(&mut rng);\n println!(\"{}\", random_item.unwrap());\n}"}