Example of an automated script that does most of this: https://github.com/surpher/PactSwiftMockServer/blob/fb8148866bb05f49a0b1dcaae66c67bad1e7eca7/Support/build_rust_dependencies
curl https://sh.rustup.rs -sSf | sh| // https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f6b6cbb5fedbb3a745ee98fde30c8d06 | |
| // A basic struct that holds an array of 16-bit unsigned integers. | |
| struct Numbers([u16; 10]); | |
| // Implement the IntoIterator trait for our Numbers struct. | |
| impl<'a> IntoIterator for &'a Numbers { | |
| // We want to iterate over references to u16 values. | |
| type Item = &'a u16; | |
| // The type of the iterator we're returning. | |
| type IntoIter = std::slice::Iter<'a, u16>; |
| use std::rc::Rc; | |
| fn process_shared(data: Rc<String>, storage: &mut Vec<Rc<String>>) { | |
| storage.push(data.clone()); // Clones Rc, not String | |
| } | |
| fn main() { | |
| let shared = Rc::new("shared".to_string()); | |
| let mut storage = Vec::new(); | |
| while Rc::strong_count(&shared) < 10 { | |
| process_shared(shared.clone(), &mut storage); | |
| println!("Rc count: {}", Rc::strong_count(&shared)); |
| #[allow(dead_code)] | |
| #[derive(Debug)] | |
| enum ConfigError { | |
| MissingKey(String), | |
| ParseError(std::num::ParseIntError), | |
| } | |
| impl From<std::num::ParseIntError> for ConfigError { | |
| fn from(err: std::num::ParseIntError) -> Self { | |
| ConfigError::ParseError(err) | |
| } |
| use tokio::io::{AsyncReadExt, AsyncWriteExt}; | |
| use tokio::net::TcpListener; | |
| #[tokio::main] | |
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| let listener = TcpListener::bind("127.0.0.1:8080").await?; | |
| println!("Echo server listening on 127.0.0.1:8080"); | |
| loop { | |
| let (mut socket, addr) = listener.accept().await?; |
| use std::collections::BTreeMap; | |
| fn main() { | |
| // Let's create a nested B-tree structure: | |
| // A BTreeMap where keys are strings (e.g., "country") | |
| // and values are another BTreeMap (e.g., "city" -> population). | |
| let mut world_populations: BTreeMap<String, BTreeMap<String, u64>> = BTreeMap::new(); | |
| // Add some data for "USA" | |
| let mut usa_cities = BTreeMap::new(); | |
| usa_cities.insert("New York".to_string(), 8_468_000); |
| fn is_palindrome(n: u64) -> bool { | |
| if n < 10 { | |
| return true; // Single-digit numbers are palindromes | |
| } | |
| let s = n.to_string(); | |
| s == s.chars().rev().collect::<String>() | |
| } | |
| fn generate_palindromes_up_to(limit: u64) -> Vec<u64> { | |
| let mut palindromes = Vec::new(); |
| use tokio::io::{AsyncReadExt, AsyncWriteExt}; | |
| use tokio::net::TcpListener; | |
| #[tokio::main] | |
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| let listener = TcpListener::bind("127.0.0.1:8080").await?; | |
| println!("Echo server listening on 127.0.0.1:8080"); | |
| loop { | |
| let (mut socket, addr) = listener.accept().await?; |
Example of an automated script that does most of this: https://github.com/surpher/PactSwiftMockServer/blob/fb8148866bb05f49a0b1dcaae66c67bad1e7eca7/Support/build_rust_dependencies
curl https://sh.rustup.rs -sSf | sh| #!/bin/bash | |
| # bash_c_example.sh | |
| # Directory to store the C source file and the executable | |
| EXAMPLES_DIR="$HOME/bash_c_examples" | |
| # Ensure the directory exists, create it if not | |
| mkdir -p "$EXAMPLES_DIR" | |
| # Check if hello_world.c and hello_world executable already exist |
| use std::collections::HashMap; | |
| use std::io::{self, Read, Write}; | |
| #[derive(Debug, PartialEq)] | |
| enum GitVfsError { | |
| NotFound, | |
| AlreadyExists, | |
| InvalidOperation, | |
| } |