Initial commit
This commit is contained in:
parent
45389da9c4
commit
bf3bc4b035
15
Cargo.toml
Normal file
15
Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "periodic_table"
|
||||
version = "0.5.0"
|
||||
authors = ["Victor Koenders <victor.koenders@gmail.com>"]
|
||||
readme = "readme.md"
|
||||
description = "Library that provides a list of elements in the periodic table"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/trangar/periodic_table"
|
||||
edition = "2021"
|
||||
rust-version = "1.62.1"
|
||||
|
||||
[build-dependencies]
|
||||
askama = "0.12"
|
||||
csv = "1.1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
137
build.rs
Normal file
137
build.rs
Normal file
@ -0,0 +1,137 @@
|
||||
#![deny(clippy::pedantic, clippy::indexing_slicing)]
|
||||
#![allow(clippy::unnecessary_wraps)]
|
||||
|
||||
use askama::Template;
|
||||
use serde::Deserialize;
|
||||
use std::{env, error::Error, fs::File, io::Write, path::Path};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all(deserialize = "camelCase"))]
|
||||
struct Record {
|
||||
atomic_number: String,
|
||||
atomic_group: String,
|
||||
symbol: String,
|
||||
name: String,
|
||||
atomic_mass: String,
|
||||
cpk_hex_color: String,
|
||||
electronic_configuration: String,
|
||||
electronegativity: String,
|
||||
atomic_radius: String,
|
||||
ion_radius: String,
|
||||
van_del_waals_radius: String,
|
||||
ionization_energy: String,
|
||||
electron_affinity: String,
|
||||
oxidation_states: String,
|
||||
standard_state: String,
|
||||
bonding_type: String,
|
||||
melting_point: String,
|
||||
boiling_point: String,
|
||||
density: String,
|
||||
group_block: String,
|
||||
year_discovered: String,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "elements.rs", escape = "none")]
|
||||
struct Data {
|
||||
elements: Vec<Record>,
|
||||
}
|
||||
|
||||
mod filters {
|
||||
/// Return the string with the first character in uppercase
|
||||
fn uppercase(string: &str) -> String {
|
||||
format!(
|
||||
"{}{}",
|
||||
string.chars().next().unwrap().to_uppercase(),
|
||||
string.get(1..).unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
/// Return the string surrounded with double quotes
|
||||
pub fn str(string: &str) -> askama::Result<String> {
|
||||
Ok(format!("\"{string}\""))
|
||||
}
|
||||
|
||||
/// Return the literal wrapped in an option
|
||||
pub fn option(string: &str) -> askama::Result<String> {
|
||||
Ok(if string.is_empty() {
|
||||
String::from("None")
|
||||
} else {
|
||||
format!("Some({string})")
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the literal wrapped in an option as an f32
|
||||
pub fn option_f32(string: &str) -> askama::Result<String> {
|
||||
Ok(if string.is_empty() {
|
||||
String::from("None")
|
||||
} else {
|
||||
format!("Some({string}_f32)")
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the literal wrapped in an option as a `IonRadius`
|
||||
pub fn option_ion_radius(string: &str) -> askama::Result<String> {
|
||||
Ok(if string.is_empty() {
|
||||
String::from("None")
|
||||
} else {
|
||||
let mut parts = string.split(' ');
|
||||
let first = parts.next().unwrap().trim();
|
||||
let second = parts.next().unwrap().trim();
|
||||
format!("Some(IonRadius {{ radius: {first}_f32, variation: \"{second}\", }})",)
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the literal wrapped in an option as a State
|
||||
pub fn option_state(string: &str) -> askama::Result<String> {
|
||||
Ok(if string.is_empty() {
|
||||
String::from("None")
|
||||
} else {
|
||||
format!("Some(State::{})", uppercase(string))
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the literal as a Year
|
||||
pub fn year(string: &str) -> askama::Result<String> {
|
||||
Ok(if string == "Ancient" {
|
||||
String::from("Year::Ancient")
|
||||
} else {
|
||||
format!("Year::Known({string})")
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the literal as a Vector
|
||||
pub fn slice(string: &str) -> askama::Result<String> {
|
||||
Ok(format!("&[{string}]"))
|
||||
}
|
||||
|
||||
/// Print the variable in a suitable way for the documentation
|
||||
pub fn doc(string: &str) -> askama::Result<String> {
|
||||
if string.trim().is_empty() {
|
||||
Ok("*unknown*".to_string())
|
||||
} else {
|
||||
Ok(format!("`{string}`"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate the lib.txt file with an element list
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let out_dir = env::var("OUT_DIR")?;
|
||||
let dest_path = Path::new(&out_dir).join("elements.rs");
|
||||
|
||||
// create CSV reader
|
||||
let mut reader = csv::ReaderBuilder::new()
|
||||
.trim(csv::Trim::All)
|
||||
.from_path("data.csv")?;
|
||||
|
||||
// get elements
|
||||
let elements = reader.deserialize().collect::<Result<Vec<Record>, _>>()?;
|
||||
|
||||
// render template
|
||||
let mut f = File::create(dest_path)?;
|
||||
let data = Data { elements };
|
||||
writeln!(f, "{}", data.render()?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
119
data.csv
Normal file
119
data.csv
Normal file
@ -0,0 +1,119 @@
|
||||
atomicNumber,atomicGroup, symbol, name, atomicMass, cpkHexColor, electronicConfiguration, electronegativity, atomicRadius, ionRadius, vanDelWaalsRadius, ionizationEnergy, electronAffinity, oxidationStates, standardState, bondingType, meltingPoint, boilingPoint,density, groupBlock, yearDiscovered
|
||||
1,1, H , Hydrogen, 1.00794(4),FFFFFF,1s1 ,2.2,37,,120,1312,-73,"-1, 1",gas,diatomic,14,20,0.0000899,nonmetal,1766
|
||||
2,18, He , Helium, 4.002602(2),D9FFFF,1s2 ,,32,,140,2372,0,,gas,atomic,,4,0.0001785,noble gas,1868
|
||||
3,1, Li , Lithium, 6.941(2),CC80FF,[He] 2s1 ,0.98,134,76 (+1),182,520,-60,1,solid,metallic,454,1615,0.535,alkali metal,1817
|
||||
4,2, Be , Beryllium, 9.012182(3),C2FF00,[He] 2s2 ,1.57,90,45 (+2),,900,0,2,solid,metallic,1560,2743,1.848,alkaline earth metal,1798
|
||||
5,13, B , Boron, 10.811(7),FFB5B5,[He] 2s2 2p1 ,2.04,82,27 (+3),,801,-27,"1, 2, 3",solid,covalent network,2348,4273,2.46,metalloid,1807
|
||||
6,14, C , Carbon, 12.0107(8),909090,[He] 2s2 2p2 ,2.55,77,16 (+4),170,1087,-154,"-4, -3, -2, -1, 1, 2, 3, 4",solid,covalent network,3823,4300,2.26,nonmetal,Ancient
|
||||
7,15, N , Nitrogen, 14.0067(2),3050F8,[He] 2s2 2p3 ,3.04,75,146 (-3),155,1402,-7,"-3, -2, -1, 1, 2, 3, 4, 5",gas,diatomic,63,77,0.001251,nonmetal,1772
|
||||
8,16, O , Oxygen, 15.9994(3),FF0D0D,[He] 2s2 2p4 ,3.44,73,140 (-2),152,1314,-141,"-2, -1, 1, 2",gas,diatomic,55,90,0.001429,nonmetal,1774
|
||||
9,17, F , Fluorine, 18.9984032(5),9E+051,[He] 2s2 2p5 ,3.98,71,133 (-1),147,1681,-328,-1,gas,atomic,54,85,0.001696,halogen,1670
|
||||
10,18, Ne , Neon, 20.1797(6),B3E3F5,[He] 2s2 2p6 ,,69,,154,2081,0,,gas,atomic,25,27,0.0009,noble gas,1898
|
||||
11,1, Na , Sodium, 22.98976928(2),AB5CF2,[Ne] 3s1 ,0.93,154,102 (+1),227,496,-53,"-1, 1",solid,metallic,371,1156,0.968,alkali metal,1807
|
||||
12,2, Mg , Magnesium, 24.3050(6),8AFF00,[Ne] 3s2 ,1.31,130,72 (+2),173,738,0,"1, 2",solid,metallic,923,1363,1.738,alkaline earth metal,1808
|
||||
13,13, Al , Aluminum, 26.9815386(8),BFA6A6,[Ne] 3s2 3p1 ,1.61,118,53.5 (+3),,578,-43,"1, 3",solid,metallic,933,2792,2.7,metal,Ancient
|
||||
14,14, Si , Silicon, 28.0855(3),F0C8A0,[Ne] 3s2 3p2 ,1.9,111,40 (+4),210,787,-134,"-4, -3, -2, -1, 1, 2, 3, 4",solid,metallic,1687,3173,2.33,metalloid,1854
|
||||
15,15, P , Phosphorus, 30.973762(2),FF8000,[Ne] 3s2 3p3 ,2.19,106,44 (+3),180,1012,-72,"-3, -2, -1, 1, 2, 3, 4, 5",solid,covalent network,317,554,1.823,nonmetal,1669
|
||||
16,16, S , Sulfur, 32.065(5),FFFF30,[Ne] 3s2 3p4 ,2.58,102,184 (-2),180,1000,-200,"-2, -1, 1, 2, 3, 4, 5, 6",solid,covalent network,388,718,1.96,nonmetal,Ancient
|
||||
17,17, Cl , Chlorine, 35.453(2),1FF01F,[Ne] 3s2 3p5 ,3.16,99,181 (-1),175,1251,-349,"-1, 1, 2, 3, 4, 5, 6, 7",gas,covalent network,172,239,0.003214,halogen,1774
|
||||
18,18, Ar , Argon, 39.948(1),80D1E3,[Ne] 3s2 3p6 ,,97,,188,1521,0,,gas,atomic,84,87,0.001784,noble gas,1894
|
||||
19,1, K , Potassium, 39.0983(1),8F40D4,[Ar] 4s1 ,0.82,196,138 (+1),275,419,-48,1,solid,metallic,337,1032,0.856,alkali metal,1807
|
||||
20,2, Ca , Calcium, 40.078(4),3DFF00,[Ar] 4s2 ,1,174,100 (+2),,590,-2,2,solid,metallic,1115,1757,1.55,alkaline earth metal,Ancient
|
||||
21,3, Sc , Scandium, 44.955912(6),E6E6E6,[Ar] 3d1 4s2 ,1.36,144,74.5 (+3),,633,-18,"1, 2, 3",solid,metallic,1814,3103,2.985,transition metal,1876
|
||||
22,4, Ti , Titanium, 47.867(1),BFC2C7,[Ar] 3d2 4s2 ,1.54,136,86 (+2),,659,-8,"-1, 2, 3, 4",solid,metallic,1941,3560,4.507,transition metal,1791
|
||||
23,5, V , Vanadium, 50.9415(1),A6A6AB,[Ar] 3d3 4s2 ,1.63,125,79 (+2),,651,-51,"-1, 2, 3, 4",solid,metallic,2183,3680,6.11,transition metal,1803
|
||||
24,6, Cr , Chromium, 51.9961(6),8A99C7,[Ar] 3d5 4s1 ,1.66,127,80 (+2*),,653,-64,"-2, -1, 1, 2, 3, 4, 5, 6",solid,metallic,2180,2944,7.14,transition metal,Ancient
|
||||
25,7, Mn , Manganese, 54.938045(5),9C7AC7,[Ar] 3d5 4s2 ,1.55,139,67 (+2),,717,0,"-3, -2, -1, 1, 2, 3, 4, 5, 6, 7",solid,metallic,1519,2334,7.47,transition metal,1774
|
||||
26,8, Fe , Iron, 55.845(2),E06633,[Ar] 3d6 4s2 ,1.83,125,78 (+2*),,763,-16,"-2, -1, 1, 2, 3, 4, 5, 6",solid,metallic,1811,3134,7.874,transition metal,Ancient
|
||||
27,9, Co , Cobalt, 58.933195(5),F090A0,[Ar] 3d7 4s2 ,1.88,126,74.5 (+2*),,760,-64,"-1, 1, 2, 3, 4, 5",solid,metallic,1768,3200,8.9,transition metal,Ancient
|
||||
28,10, Ni , Nickel, 58.6934(4),50D050,[Ar] 3d8 4s2 ,1.91,121,69 (+2),163,737,-112,"-1, 1, 2, 3, 4",solid,metallic,1728,3186,8.908,transition metal,1751
|
||||
29,11, Cu , Copper, 63.546(3),C88033,[Ar] 3d10 4s1 ,1.9,138,77 (+1),140,746,-118,"1, 2, 3, 4",solid,metallic,1358,3200,8.92,transition metal,Ancient
|
||||
30,12, Zn , Zinc, 65.38(2),7D80B0,[Ar] 3d10 4s2 ,1.65,131,74 (+2),139,906,0,2,solid,metallic,693,1180,7.14,transition metal,1746
|
||||
31,13, Ga , Gallium, 69.723(1),C28F8F,[Ar] 3d10 4s2 4p1 ,1.81,126,62 (+3),187,579,-29,"1, 2, 3",solid,metallic,303,2477,5.904,metal,1875
|
||||
32,14, Ge , Germanium, 72.64(1),668F8F,[Ar] 3d10 4s2 4p2 ,2.01,122,73 (+2),,762,-119,"-4, 1, 2, 3, 4",solid,metallic,1211,3093,5.323,metalloid,1886
|
||||
33,15, As , Arsenic, 74.92160(2),BD80E3,[Ar] 3d10 4s2 4p3 ,2.18,119,58 (+3),185,947,-78,"-3, 2, 3, 5",solid,metallic,1090,887,5.727,metalloid,Ancient
|
||||
34,16, Se , Selenium, 78.96(3),FFA100,[Ar] 3d10 4s2 4p4 ,2.55,116,198 (-2),190,941,-195,"-2, 2, 4, 6",solid,metallic,494,958,4.819,nonmetal,1817
|
||||
35,17, Br , Bromine, 79.904(1),A62929,[Ar] 3d10 4s2 4p5 ,2.96,114,196 (-1),185,1140,-325,"-1, 1, 3, 4, 5, 7",liquid,covalent network,266,332,3.12,halogen,1826
|
||||
36,18, Kr , Krypton, 83.798(2),5CB8D1,[Ar] 3d10 4s2 4p6 ,,110,,202,1351,0,2,gas,atomic,116,120,0.00375,noble gas,1898
|
||||
37,1, Rb , Rubidium, 85.4678(3),702EB0,[Kr] 5s1 ,0.82,211,152 (+1),,403,-47,1,solid,metallic,312,961,1.532,alkali metal,1861
|
||||
38,2, Sr , Strontium, 87.62(1),00FF00,[Kr] 5s2 ,0.95,192,118 (+2),,550,-5,2,solid,metallic,1050,1655,2.63,alkaline earth metal,1790
|
||||
39,3, Y , Yttrium, 88.90585(2),94FFFF,[Kr] 4d1 5s2 ,1.22,162,90 (+3),,600,-30,"1, 2, 3",solid,metallic,1799,3618,4.472,transition metal,1794
|
||||
40,4, Zr , Zirconium, 91.224(2),94E0E0,[Kr] 4d2 5s2 ,1.33,148,72 (+4),,640,-41,"1, 2, 3, 4",solid,metallic,2128,4682,6.511,transition metal,1789
|
||||
41,5, Nb , Niobium, 92.90638(2),73C2C9,[Kr] 4d4 5s1 ,1.6,137,72 (+3),,652,-86,"-1, 2, 3, 4, 5",solid,metallic,2750,5017,8.57,transition metal,1801
|
||||
42,6, Mo , Molybdenum, 95.96(2),54B5B5,[Kr] 4d5 5s1 ,2.16,145,69 (+3),,684,-72,"-2, -1, 1, 2, 3, 4, 5, 6",solid,metallic,2896,4912,10.28,transition metal,1778
|
||||
43,7, Tc , Technetium, [98],3B9E9E,[Kr] 4d5 5s2 ,1.9,156,64.5 (+4),,702,-53,"-3, -1, 1, 2, 3, 4, 5, 6, 7",solid,metallic,2430,4538,11.5,transition metal,1937
|
||||
44,8, Ru , Ruthenium, 101.07(2),248F8F,[Kr] 4d7 5s1 ,2.2,126,68 (+3),,710,-101,"-2, 1, 2, 3, 4, 5, 6, 7, 8",solid,metallic,2607,4423,12.37,transition metal,1827
|
||||
45,9, Rh , Rhodium, 102.90550(2),0A7D8C,[Kr] 4d8 5s1 ,2.28,135,66.5 (+3),,720,-110,"-1, 1, 2, 3, 4, 5, 6",solid,metallic,2237,3968,12.45,transition metal,1803
|
||||
46,10, Pd , Palladium, 106.42(1),6985,[Kr] 4d10 ,2.2,131,59 (+1),163,804,-54,"2, 4",solid,metallic,1828,3236,12.023,transition metal,1803
|
||||
47,11, Ag , Silver, 107.8682(2),C0C0C0,[Kr] 4d10 5s1 ,1.93,153,115 (+1),172,731,-126,"1, 2, 3",solid,metallic,1235,2435,10.49,transition metal,Ancient
|
||||
48,12, Cd , Cadmium, 112.411(8),FFD98F,[Kr] 4d10 5s2 ,1.69,148,95 (+2),158,868,0,2,solid,metallic,594,1040,8.65,transition metal,1817
|
||||
49,13, In , Indium, 114.818(3),A67573,[Kr] 4d10 5s2 5p1 ,1.78,144,80 (+3),193,558,-29,"1, 2, 3",solid,metallic,430,2345,7.31,metal,1863
|
||||
50,14, Sn , Tin, 118.710(7),668080,[Kr] 4d10 5s2 5p2 ,1.96,141,112 (+2),217,709,-107,"-4, 2, 4",solid,metallic,505,2875,7.31,metal,Ancient
|
||||
51,15, Sb , Antimony, 121.760(1),9E63B5,[Kr] 4d10 5s2 5p3 ,2.05,138,76 (+3),,834,-103,"-3, 3, 5",solid,metallic,904,1860,6.697,metalloid,Ancient
|
||||
52,16, Te , Tellurium, 127.60(3),D47A00,[Kr] 4d10 5s2 5p4 ,2.1,135,221 (-2),206,869,-190,"-2, 2, 4, 5, 6",solid,metallic,723,1261,6.24,metalloid,1782
|
||||
53,17, I , Iodine, 126.90447(3),940094,[Kr] 4d10 5s2 5p5 ,2.66,133,220 (-1),198,1008,-295,"-1, 1, 3, 5, 7",solid,covalent network,387,457,4.94,halogen,1811
|
||||
54,18, Xe , Xenon, 131.293(6),429EB0,[Kr] 4d10 5s2 5p6 ,,130,48 (+8),216,1170,0,"2, 4, 6, 8",gas,atomic,161,165,0.0059,noble gas,1898
|
||||
55,1, Cs , Cesium, 132.9054519(2),57178F,[Xe] 6s1 ,0.79,225,167 (+1),,376,-46,1,solid,metallic,302,944,1.879,alkali metal,1860
|
||||
56,2, Ba , Barium, 137.327(7),00C900,[Xe] 6s2 ,0.89,198,135 (+2),,503,-14,2,solid,metallic,1000,2143,3.51,alkaline earth metal,1808
|
||||
57,3, La , Lanthanum, 138.90547(7),70D4FF,[Xe] 5d1 6s2 ,1.1,169,103.2 (+3),,538,-48,"2, 3",solid,metallic,1193,3737,6.146,lanthanoid,1839
|
||||
58,, Ce , Cerium, 140.116(1),FFFFC7,[Xe] 4f1 5d1 6s2 ,1.12,,102 (+3),,534,-50,"2, 3, 4",solid,metallic,1071,3633,6.689,lanthanoid,1803
|
||||
59,, Pr , Praseodymium, 140.90765(2),D9FFC7,[Xe] 4f3 6s2 ,1.13,,99 (+3),,527,-50,"2, 3, 4",solid,metallic,1204,3563,6.64,lanthanoid,1885
|
||||
60,, Nd , Neodymium, 144.242(3),C7FFC7,[Xe] 4f4 6s2 ,1.14,,129 (+2),,533,-50,"2, 3",solid,metallic,1294,3373,7.01,lanthanoid,1885
|
||||
61,, Pm , Promethium, [145],A3FFC7,[Xe] 4f5 6s2 ,1.13,,97 (+3),,540,-50,3,solid,metallic,1373,3273,7.264,lanthanoid,1947
|
||||
62,, Sm , Samarium, 150.36(2),8FFFC7,[Xe] 4f6 6s2 ,1.17,,122 (+2),,545,-50,"2, 3",solid,metallic,1345,2076,7.353,lanthanoid,1853
|
||||
63,, Eu , Europium, 151.964(1),61FFC7,[Xe] 4f7 6s2 ,1.2,,117 (+2),,547,-50,"2, 3",solid,metallic,1095,1800,5.244,lanthanoid,1901
|
||||
64,, Gd , Gadolinium, 157.25(3),45FFC7,[Xe] 4f7 5d1 6s2 ,1.2,,93.8 (+3),,593,-50,"1, 2, 3",solid,metallic,1586,3523,7.901,lanthanoid,1880
|
||||
65,, Tb , Terbium, 158.92535(2),30FFC7,[Xe] 4f9 6s2 ,1.2,,92.3 (+3),,566,-50,"1, 3, 4",solid,metallic,1629,3503,8.219,lanthanoid,1843
|
||||
66,, Dy , Dysprosium, 162.500(1),1FFFC7,[Xe] 4f10 6s2 ,1.22,,107 (+2),,573,-50,"2, 3",solid,metallic,1685,2840,8.551,lanthanoid,1886
|
||||
67,, Ho , Holmium, 164.93032(2),00FF9C,[Xe] 4f11 6s2 ,1.23,,90.1 (+3),,581,-50,3,solid,metallic,1747,2973,8.795,lanthanoid,1878
|
||||
68,, Er , Erbium, 167.259(3),0,[Xe] 4f12 6s2 ,1.24,,89 (+3),,589,-50,3,solid,metallic,1770,3141,9.066,lanthanoid,1842
|
||||
69,, Tm , Thulium, 168.93421(2),00D452,[Xe] 4f13 6s2 ,1.25,,103 (+2),,597,-50,"2, 3",solid,metallic,1818,2223,9.321,lanthanoid,1879
|
||||
70,, Yb , Ytterbium, 173.054(5),00BF38,[Xe] 4f14 6s2 ,1.1,,102 (+2),,603,-50,"2, 3",solid,metallic,1092,1469,6.57,lanthanoid,1878
|
||||
71,, Lu , Lutetium, 174.9668(1),00AB24,[Xe] 4f14 5d1 6s2 ,1.27,160,86.1 (+3),,524,-50,3,solid,metallic,1936,3675,9.841,lanthanoid,1907
|
||||
72,4, Hf , Hafnium, 178.49(2),4DC2FF,[Xe] 4f14 5d2 6s2 ,1.3,150,71 (+4),,659,0,"2, 3, 4",solid,metallic,2506,4876,13.31,transition metal,1923
|
||||
73,5, Ta , Tantalum, 180.94788(2),4DA6FF,[Xe] 4f14 5d3 6s2 ,1.5,138,72 (+3),,761,-31,"-1, 2, 3, 4, 5",solid,metallic,3290,5731,16.65,transition metal,1802
|
||||
74,6, W , Tungsten, 183.84(1),2194D6,[Xe] 4f14 5d4 6s2 ,2.36,146,66 (+4),,770,-79,"-2, -1, 1, 2, 3, 4, 5, 6",solid,metallic,3695,5828,19.25,transition metal,1783
|
||||
75,7, Re , Rhenium, 186.207(1),267DAB,[Xe] 4f14 5d5 6s2 ,1.9,159,63 (+4),,760,-15,"-3, -1, 1, 2, 3, 4, 5, 6, 7",solid,metallic,3459,5869,21.02,transition metal,1925
|
||||
76,8, Os , Osmium, 190.23(3),266696,[Xe] 4f14 5d6 6s2 ,2.2,128,63 (+4),,840,-106,"-2, -1, 1, 2, 3, 4, 5, 6, 7, 8",solid,metallic,3306,5285,22.61,transition metal,1803
|
||||
77,9, Ir , Iridium, 192.217(3),175487,[Xe] 4f14 5d7 6s2 ,2.2,137,68 (+3),,880,-151,"-3, -1, 1, 2, 3, 4, 5, 6",solid,metallic,2739,4701,22.65,transition metal,1803
|
||||
78,10, Pt , Platinum, 195.084(9),D0D0E0,[Xe] 4f14 5d9 6s1 ,2.28,128,86 (+2),175,870,-205,"2, 4, 5, 6",solid,metallic,2041,4098,21.09,transition metal,Ancient
|
||||
79,11, Au , Gold, 196.966569(4),FFD123,[Xe] 4f14 5d10 6s1 ,2.54,144,137 (+1),166,890,-223,"-1, 1, 2, 3, 5",solid,metallic,1337,3129,19.3,transition metal,Ancient
|
||||
80,12, Hg , Mercury, 200.59(2),B8B8D0,[Xe] 4f14 5d10 6s2 ,2,149,119 (+1),155,1007,0,"1, 2, 4",liquid,metallic,234,630,13.534,transition metal,Ancient
|
||||
81,13, Tl , Thallium, 204.3833(2),A6544D,[Xe] 4f14 5d10 6s2 6p1 ,2.04,148,150 (+1),196,589,-19,"1, 3",solid,metallic,577,1746,11.85,metal,1861
|
||||
82,14, Pb , Lead, 207.2(1),575961,[Xe] 4f14 5d10 6s2 6p2 ,2.33,147,119 (+2),202,716,-35,"-4, 2, 4",solid,metallic,601,2022,11.34,metal,Ancient
|
||||
83,15, Bi , Bismuth, 208.98040(1),9E4FB5,[Xe] 4f14 5d10 6s2 6p3 ,2.02,146,103 (+3),,703,-91,"-3, 3, 5",solid,metallic,544,1837,9.78,metal,Ancient
|
||||
84,16, Po , Polonium, [209],AB5C00,[Xe] 4f14 5d10 6s2 6p4 ,2,,94 (+4),,812,-183,"-2, 2, 4, 6",solid,metallic,527,1235,9.196,metalloid,1898
|
||||
85,17, At , Astatine, [210],754F45,[Xe] 4f14 5d10 6s2 6p5 ,2.2,,62 (+7),,920,-270,"-1, 1, 3, 5",solid,covalent network,575,,,halogen,1940
|
||||
86,18, Rn , Radon, [222],428296,[Xe] 4f14 5d10 6s2 6p6 ,,145,,,1037,,2,gas,atomic,202,211,0.00973,noble gas,1900
|
||||
87,1, Fr , Francium, [223],420066,[Rn] 7s1 ,0.7,,180 (+1),,380,,1,solid,metallic,,,,alkali metal,1939
|
||||
88,2, Ra , Radium, [226],007D00,[Rn] 7s2 ,0.9,,148 (+2),,509,,2,solid,metallic,973,2010,5,alkaline earth metal,1898
|
||||
89,3, Ac , Actinium, [227],70ABFA,[Rn] 6d1 7s2 ,1.1,,112 (+3),,499,,3,solid,metallic,1323,3473,10.07,actinoid,1899
|
||||
90,, Th , Thorium, 232.03806(2),00BAFF,[Rn] 6d2 7s2 ,1.3,,94 (+4),,587,,"2, 3, 4",solid,metallic,2023,5093,11.724,actinoid,1828
|
||||
91,, Pa , Protactinium, 231.03588(2),00A1FF,[Rn] 5f2 6d1 7s2 ,1.5,,104 (+3),,568,,"3, 4, 5",solid,metallic,1845,4273,15.37,actinoid,1913
|
||||
92,, U , Uranium, 238.02891(3),008FFF,[Rn] 5f3 6d1 7s2 ,1.38,,102.5 (+3),186,598,,"3, 4, 5, 6",solid,metallic,1408,4200,19.05,actinoid,1789
|
||||
93,, Np , Neptunium, [237],0080FF,[Rn] 5f4 6d1 7s2 ,1.36,,110 (+2),,605,,"3, 4, 5, 6, 7",solid,metallic,917,4273,20.45,actinoid,1940
|
||||
94,, Pu , Plutonium, [244],006BFF,[Rn] 5f6 7s2 ,1.28,,100 (+3),,585,,"3, 4, 5, 6, 7",solid,metallic,913,3503,19.816,actinoid,1940
|
||||
95,, Am , Americium, [243],545CF2,[Rn] 5f7 7s2 ,1.3,,126 (+2),,578,,"2, 3, 4, 5, 6",solid,metallic,1449,2284,,actinoid,1944
|
||||
96,, Cm , Curium, [247],785CE3,[Rn] 5f7 6d1 7s2 ,1.3,,97 (+3),,581,,"3, 4",solid,metallic,1618,3383,13.51,actinoid,1944
|
||||
97,, Bk , Berkelium, [247],8A4FE3,[Rn] 5f9 7s2 ,1.3,,96 (+3),,601,,"3, 4",solid,metallic,1323,,14.78,actinoid,1949
|
||||
98,, Cf , Californium, [251],A136D4,[Rn] 5f10 7s2 ,1.3,,95 (+3),,608,,"2, 3, 4",solid,metallic,1173,,15.1,actinoid,1950
|
||||
99,, Es , Einsteinium, [252],B31FD4,[Rn] 5f11 7s2 ,1.3,,,,619,,"2, 3",solid,,1133,,,actinoid,1952
|
||||
100,, Fm , Fermium, [257],B31FBA,[Rn] 5f12 7s2 ,1.3,,,,627,,"2, 3",,,1800,,,actinoid,1952
|
||||
101,, Md , Mendelevium, [258],B30DA6,[Rn] 5f13 7s2 ,1.3,,,,635,,"2, 3",,,1100,,,actinoid,1955
|
||||
102,, No , Nobelium, [259],BD0D87,[Rn] 5f14 7s2 ,1.3,,,,642,,"2, 3",,,1100,,,actinoid,1957
|
||||
103,, Lr , Lawrencium, [262],C70066,[Rn] 5f14 7s2 7p1 ,1.3,,,,,,3,,,1900,,,transition metal,1961
|
||||
104,4, Rf , Rutherfordium, [267],CC0059,[Rn] 5f14 6d2 7s2 ,,,,,,,4,,,,,,transition metal,1969
|
||||
105,5, Db , Dubnium, [268],D1004F,[Rn] 5f14 6d3 7s2 ,,,,,,,,,,,,,transition metal,1967
|
||||
106,6, Sg , Seaborgium, [271],D90045,[Rn] 5f14 6d4 7s2 ,,,,,,,,,,,,,transition metal,1974
|
||||
107,7, Bh , Bohrium, [272],E00038,[Rn] 5f14 6d5 7s2 ,,,,,,,,,,,,,transition metal,1976
|
||||
108,8, Hs , Hassium, [270],E6002E,[Rn] 5f14 6d6 7s2 ,,,,,,,,,,,,,transition metal,1984
|
||||
109,9, Mt , Meitnerium, [276],EB0026,[Rn] 5f14 6d7 7s2 ,,,,,,,,,,,,,transition metal,1982
|
||||
110,10, Ds , Darmstadtium, [281],,[Rn] 5f14 6d9 7s1 ,,,,,,,,,,,,,transition metal,1994
|
||||
111,11, Rg , Roentgenium, [280],,[Rn] 5f14 6d10 7s1 ,,,,,,,,,,,,,transition metal,1994
|
||||
112,12, Cn , Copernicium, [285],,[Rn] 5f14 6d10 7s2 ,,,,,,,,,,,,,transition metal,1996
|
||||
113,13, Nh , Nihonium, [284],,[Rn] 5f14 6d10 7s2 7p1 ,,,,,,,,,,,,,post-transition metal,2003
|
||||
114,14, Fl , Flerovium, [289],,[Rn] 5f14 6d10 7s2 7p2 ,,,,,,,,,,,,,post-transition metal,1998
|
||||
115,15, Mc , Moscovium, [288],,[Rn] 5f14 6d10 7s2 7p3 ,,,,,,,,,,,,,post-transition metal,2003
|
||||
116,16, Lv , Livermorium, [293],,[Rn] 5f14 6d10 7s2 7p4 ,,,,,,,,,,,,,post-transition metal,2000
|
||||
117,17, Ts , Tennessine, [294],,[Rn] 5f14 6d10 7s2 7p5 ,,,,,,,,,,,,,post-transition metal,2010
|
||||
118,18, Og , Oganesson, [294] ,,[Rn] 5f14 6d10 7s2 7p6 ,,,,,,,,,,,,,noble gas,2002
|
||||
|
8
readme.md
Normal file
8
readme.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Periodic Table
|
||||
|
||||

|
||||
|
||||
This library provides a list of elements in the periodic table. For more info, see the [docs](https://docs.rs/periodic_table)
|
||||
|
||||
The data is provided from `data.csv` which was shamelessly borrowed from [https://github.com/andrejewski/periodic-table](https://github.com/andrejewski/periodic-table)
|
||||
|
||||
45
src/element.rs
Normal file
45
src/element.rs
Normal file
@ -0,0 +1,45 @@
|
||||
/// Contains the information of a single element
|
||||
#[derive(Debug)]
|
||||
pub struct Element {
|
||||
pub atomic_number: u32,
|
||||
pub atomic_group: Option<u32>,
|
||||
pub symbol: &'static str,
|
||||
pub name: &'static str,
|
||||
pub atomic_mass: &'static str,
|
||||
pub cpk_hex_color: &'static str,
|
||||
pub electronic_configuration: &'static str,
|
||||
pub electronegativity: Option<f32>,
|
||||
pub atomic_radius: Option<u32>,
|
||||
pub ion_radius: Option<IonRadius>,
|
||||
pub van_del_waals_radius: Option<u32>,
|
||||
pub ionization_energy: Option<u32>,
|
||||
pub electron_affinity: Option<i32>,
|
||||
pub oxidation_states: &'static [i32],
|
||||
pub standard_state: Option<State>,
|
||||
pub bonding_type: &'static str,
|
||||
pub melting_point: Option<u32>,
|
||||
pub boiling_point: Option<u32>,
|
||||
pub density: Option<f32>,
|
||||
pub group_block: &'static str,
|
||||
pub year_discovered: Year,
|
||||
}
|
||||
|
||||
/// The three possible states
|
||||
#[derive(Debug)]
|
||||
pub enum State {
|
||||
Solid,
|
||||
Liquid,
|
||||
Gas,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IonRadius {
|
||||
pub radius: f32,
|
||||
pub variation: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Year {
|
||||
Ancient,
|
||||
Known(u16),
|
||||
}
|
||||
25
src/lib.rs
Normal file
25
src/lib.rs
Normal file
@ -0,0 +1,25 @@
|
||||
#![deny(clippy::pedantic, clippy::indexing_slicing)]
|
||||
#![allow(clippy::unreadable_literal)]
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
|
||||
pub use element::{Element, IonRadius, State, Year};
|
||||
|
||||
mod element;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/elements.rs"));
|
||||
|
||||
/// Return a list of elements in the periodic table.
|
||||
///
|
||||
/// Note that this is 0-indexed, so to get H/Hydrogen with atomic number 1, you actually need to fetch index `0`.
|
||||
///
|
||||
/// ```
|
||||
/// let hydrogen = periodic_table::periodic_table()[0];
|
||||
/// assert_eq!(hydrogen.symbol, "H");
|
||||
/// assert_eq!(hydrogen.name, "Hydrogen");
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn periodic_table() -> &'static [&'static Element] {
|
||||
PERIODIC_TABLE
|
||||
}
|
||||
16
src/test.rs
Normal file
16
src/test.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use crate::periodic_table;
|
||||
|
||||
#[test]
|
||||
fn test_length() {
|
||||
let elements = periodic_table();
|
||||
assert!(elements.len() > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hydrogen() {
|
||||
let elements = periodic_table();
|
||||
let hydrogen = elements.get(0).unwrap();
|
||||
assert_eq!("H", hydrogen.symbol);
|
||||
assert_eq!(1, hydrogen.atomic_number);
|
||||
assert_eq!("Hydrogen", hydrogen.name);
|
||||
}
|
||||
60
templates/elements.rs
Normal file
60
templates/elements.rs
Normal file
@ -0,0 +1,60 @@
|
||||
/// The list of elements in the periodic table.
|
||||
static PERIODIC_TABLE: &[&Element] = &[
|
||||
{% for e in elements %}
|
||||
&elements::{{ e.symbol|uppercase }},
|
||||
{% endfor %}
|
||||
];
|
||||
|
||||
/// Elements that can be looked up from their symbol
|
||||
pub mod elements {
|
||||
use super::{Element, IonRadius, State, Year};
|
||||
|
||||
{% for e in elements %}
|
||||
/// {{ e.name }} ({{ e.symbol }}, #{{ e.atomic_number }})
|
||||
///
|
||||
/// - `atomic_number`: {{ e.atomic_number|doc }}
|
||||
/// - `symbol`: {{ e.symbol|doc }}
|
||||
/// - `name`: {{ e.name|doc }}
|
||||
/// - `atomic_mass`: {{ e.atomic_mass|doc }}
|
||||
/// - `cpk_hex_color`: {{ e.cpk_hex_color|doc }}
|
||||
/// - `electronic_configuration`: {{ e.electronic_configuration|doc }}
|
||||
/// - `electronegativity`: {{ e.electronegativity|doc }}
|
||||
/// - `atomic_radius`: {{ e.atomic_radius|doc }}
|
||||
/// - `ion_radius`: {{ e.ion_radius|doc }}
|
||||
/// - `van_del_waals_radius`: {{ e.van_del_waals_radius|doc }}
|
||||
/// - `ionization_energy`: {{ e.ionization_energy|doc }}
|
||||
/// - `electron_affinity`: {{ e.electron_affinity|doc }}
|
||||
/// - `oxidation_states`: {{ e.oxidation_states|doc }}
|
||||
/// - `standard_state`: {{ e.standard_state|doc }}
|
||||
/// - `bonding_type`: {{ e.bonding_type|doc }}
|
||||
/// - `melting_point`: {{ e.melting_point|doc }}
|
||||
/// - `boiling_point`: {{ e.boiling_point|doc }}
|
||||
/// - `density`: {{ e.density|doc }}
|
||||
/// - `group_block`: {{ e.group_block|doc }}
|
||||
/// - `year_discovered`: {{ e.year_discovered|doc }}
|
||||
pub static {{ e.symbol|uppercase }}: Element = Element {
|
||||
atomic_number: {{ e.atomic_number }},
|
||||
atomic_group: {{ e.atomic_group|option }},
|
||||
symbol: {{ e.symbol|str }},
|
||||
name: {{ e.name|str }},
|
||||
atomic_mass: {{ e.atomic_mass|str }},
|
||||
cpk_hex_color: {{ e.cpk_hex_color|str }},
|
||||
electronic_configuration: {{ e.electronic_configuration|str }},
|
||||
electronegativity: {{ e.electronegativity|option_f32 }},
|
||||
atomic_radius: {{ e.atomic_radius|option }},
|
||||
ion_radius: {{ e.ion_radius|option_ion_radius }},
|
||||
van_del_waals_radius: {{ e.van_del_waals_radius|option }},
|
||||
ionization_energy: {{ e.ionization_energy|option }},
|
||||
electron_affinity: {{ e.electron_affinity|option }},
|
||||
oxidation_states: {{ e.oxidation_states|slice }},
|
||||
standard_state: {{ e.standard_state|option_state }},
|
||||
bonding_type: {{ e.bonding_type|str }},
|
||||
melting_point: {{ e.melting_point|option }},
|
||||
boiling_point: {{ e.boiling_point|option }},
|
||||
density: {{ e.density|option_f32 }},
|
||||
group_block: {{ e.group_block|str }},
|
||||
year_discovered: {{ e.year_discovered|year }},
|
||||
};
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user