This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Probability { | |
| value: f64, | |
| } | |
| impl Probability { | |
| fn new(p: f64) -> Self { | |
| assert!( | |
| (0.0..=1.0).contains(&p), | |
| "Probability must be between 0 and 1" | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Exploring Landauer's Principle with Joule and BTU heat dissipation. | |
| use std::f64::consts::LN_2; | |
| const BOLTZMANN_CONSTANT: f64 = 1.380649e_23; | |
| const JOULES_TO_BTU: f64 = 9.4781712e_4; | |
| // --- 1. Logic Gate Definitions --- | |
| #[allow(unused)] | |
| #[derive(Debug, Clone, Copy)] | |
| enum Gate { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::rc::Rc; | |
| use std::cell::RefCell; | |
| use std::collections::HashMap; | |
| use anyhow::{anyhow, Result}; | |
| /// A node in our Morse Virtual Circuit binary tree. | |
| #[derive(Debug, Default)] | |
| struct Node { | |
| value: Option<char>, | |
| dot: Option<Rc<RefCell<Node>>>, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // To run this, you can use: cargo run | |
| // Or if using a single file: rustc constants.rs && ./constants | |
| use std::fmt::Write; | |
| /// Generates the Champernowne constant string: 0.123456789101112... | |
| fn generate_champernowne(n_digits: usize) -> String { | |
| let mut result = String::from("0."); | |
| let mut current = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use anyhow::Context; | |
| use serde::Serialize; | |
| use std::hash::{Hash, Hasher}; | |
| use tokio::fs::File; | |
| use tokio::io::AsyncWriteExt; | |
| #[derive(Serialize)] | |
| struct LibReport { | |
| name: String, | |
| fingerprint: String, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// This macro takes a list of crate names and "touches" them | |
| /// by referencing their absolute path. If the crate is missing, | |
| /// the code will fail to compile. | |
| macro_rules! verify_libraries { | |
| ($($lib:ident),*) => { | |
| println!("--- Verifying Library Linkage ---"); | |
| $( | |
| // We use a statement that references the crate without side effects | |
| let _ = stringify!($lib); | |
| println!("✅ [{}] is linked and accessible.", stringify!($lib)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use anyhow::{anyhow, Result}; | |
| use serde::Deserialize; | |
| use async_trait::async_trait; // Using async-trait from your list | |
| #[derive(Debug, Deserialize, Clone)] | |
| struct SimpleIpResponse { | |
| ip: String, | |
| } | |
| // 1. Define a trait for the fetching logic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Represents a point in 4D space | |
| #[derive(Debug, Clone, Copy)] | |
| struct Point4D { | |
| x: i32, | |
| y: i32, | |
| z: i32, | |
| w: i32, | |
| } | |
| impl Point4D { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// A collection of digital logic gate algorithms. | |
| struct LogicGates; | |
| impl LogicGates { | |
| /// NOT gate: The output is the opposite of the input. | |
| fn not(a: u8) -> u8 { | |
| match a { | |
| 0 => 1, | |
| _ => 0, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// A verbose example of Bitcoin's two variable integer types. | |
| fn main() { | |
| let value: u64 = 515; | |
| // 1. CompactSize (Little-Endian) - Used in P2P/Transactions | |
| let compact = encode_compact_size(value); | |
| println!("Value: {}", value); | |
| println!("CompactSize (LE-based) hex: {:02x?}", compact); | |
| // 2. VarInt (Base-128 Big-Endian) - Used in LevelDB/Disk |
NewerOlder