pub enum Element {
H,
He,
Li,
// some variants omitted
}Expand description
Each of the known chemical elements
Variants§
Implementations§
Source§impl Element
impl Element
Sourcepub const fn list() -> &'static [Self]
pub const fn list() -> &'static [Self]
Slice containing all elements, ordered by atomic number
use mendeleev::Element;
use mendeleev::N_ELEMENTS;
for n in 1..=N_ELEMENTS {
assert_eq!(Element::list()[n - 1].atomic_number() as usize, n);
}Examples found in repository?
More examples
4fn main() {
5 for element in Element::list() {
6 print!("{}: ", element.name());
7 let isotope_count = Isotope::list()
8 .iter()
9 .filter(|isotope| &isotope.element() == element)
10 .flat_map(|isotope| {
11 let abundance = isotope.natural_abundance()?;
12 print!("{}: {}, ", isotope.display_with_superscript(), abundance);
13 Some(())
14 })
15 .count();
16 if isotope_count == 0 {
17 print!("No naturally occurring isotopes");
18 }
19 println!();
20 }
21}4fn main() {
5 for period in 1..=N_PERIODS {
6 for group in Group::list() {
7 let element = Element::list()
8 .iter()
9 .find(|e| e.period() == period && e.group() == Some(*group));
10 match element {
11 Some(element) => print!("{:<4}", element.symbol()),
12 None => print!(" "),
13 }
14 }
15 println!();
16 }
17 println!();
18 for period in 6..=7 {
19 print!(" ");
20 for element in Element::list()
21 .iter()
22 .filter(|el| el.period() == period && el.group().is_none())
23 {
24 print!("{:<4}", element.symbol());
25 }
26 println!();
27 }
28}4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn atomic_number(&self) -> u32
pub const fn atomic_number(&self) -> u32
Returns the element’s atomic number, i.e., the number of protons in its nucleus.
use mendeleev::Element;
assert_eq!(Element::H.atomic_number(), 1);
assert_eq!(Element::Og.atomic_number(), 118);Examples found in repository?
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn atomic_radius(&self) -> Option<Picometer>
pub const fn atomic_radius(&self) -> Option<Picometer>
Returns the element’s empirically measured atomic radius, if available.
use mendeleev::{Element, Picometer};
assert_eq!(Element::H.atomic_radius(), Some(Picometer(25.0)));Examples found in repository?
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn atomic_weight(&self) -> AtomicWeight
pub const fn atomic_weight(&self) -> AtomicWeight
Returns the element’s Standard Atomic Weight, if applicable, or its mass number otherwise.
use mendeleev::{Element, AtomicWeight};
assert_eq!(Element::H.atomic_weight(),
AtomicWeight::Interval{range: 1.0078..=1.0082, conventional: 1.008});
assert_eq!(Element::Og.atomic_weight(), AtomicWeight::MassNumber{number: 294});Examples found in repository?
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn cpk_color(&self) -> Option<Color>
pub const fn cpk_color(&self) -> Option<Color>
Returns the color for the element in the CPK convention.
use mendeleev::{Element, Color};
assert_eq!(Element::H.cpk_color(), Some(Color{r: 255, g: 255, b: 255}));
assert_eq!(Element::Og.cpk_color(), None);
assert_eq!(Element::Au.cpk_color(), Some(Color{r: 218, g: 165, b: 32}));Examples found in repository?
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn group(&self) -> Option<Group>
pub const fn group(&self) -> Option<Group>
Returns the element’s group in the periodic table, if any.
use mendeleev::{Element, Group};
assert_eq!(Element::H.group(), Some(Group::IA));
assert_eq!(Element::Og.group(), Some(Group::VIIIA));
assert_eq!(Element::U.group(), None);Examples found in repository?
4fn main() {
5 for period in 1..=N_PERIODS {
6 for group in Group::list() {
7 let element = Element::list()
8 .iter()
9 .find(|e| e.period() == period && e.group() == Some(*group));
10 match element {
11 Some(element) => print!("{:<4}", element.symbol()),
12 None => print!(" "),
13 }
14 }
15 println!();
16 }
17 println!();
18 for period in 6..=7 {
19 print!(" ");
20 for element in Element::list()
21 .iter()
22 .filter(|el| el.period() == period && el.group().is_none())
23 {
24 print!("{:<4}", element.symbol());
25 }
26 println!();
27 }
28}More examples
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn jmol_color(&self) -> Option<Color>
pub const fn jmol_color(&self) -> Option<Color>
Returns the color for the element in the jmol software
use mendeleev::{Element, Color};
assert_eq!(Element::H.jmol_color(), Some(Color{r: 255, g: 255, b: 255}));
assert_eq!(Element::Og.jmol_color(), None);
assert_eq!(Element::Au.jmol_color(), Some(Color{r: 255, g: 209, b: 35}));Examples found in repository?
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn name(&self) -> &'static str
pub const fn name(&self) -> &'static str
Returns the name of the element in English.
use mendeleev::Element;
assert_eq!(Element::H.name(), "Hydrogen");Examples found in repository?
4fn main() {
5 for element in Element::list() {
6 print!("{}: ", element.name());
7 let isotope_count = Isotope::list()
8 .iter()
9 .filter(|isotope| &isotope.element() == element)
10 .flat_map(|isotope| {
11 let abundance = isotope.natural_abundance()?;
12 print!("{}: {}, ", isotope.display_with_superscript(), abundance);
13 Some(())
14 })
15 .count();
16 if isotope_count == 0 {
17 print!("No naturally occurring isotopes");
18 }
19 println!();
20 }
21}More examples
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn period(&self) -> u32
pub const fn period(&self) -> u32
Returns the element’s period number in the periodic table.
use mendeleev::Element;
assert_eq!(Element::H.period(), 1);
assert_eq!(Element::Og.period(), 7);Examples found in repository?
4fn main() {
5 for period in 1..=N_PERIODS {
6 for group in Group::list() {
7 let element = Element::list()
8 .iter()
9 .find(|e| e.period() == period && e.group() == Some(*group));
10 match element {
11 Some(element) => print!("{:<4}", element.symbol()),
12 None => print!(" "),
13 }
14 }
15 println!();
16 }
17 println!();
18 for period in 6..=7 {
19 print!(" ");
20 for element in Element::list()
21 .iter()
22 .filter(|el| el.period() == period && el.group().is_none())
23 {
24 print!("{:<4}", element.symbol());
25 }
26 println!();
27 }
28}More examples
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn symbol(&self) -> &'static str
pub const fn symbol(&self) -> &'static str
Returns the symbol for the element
use mendeleev::Element;
assert_eq!(Element::H.symbol(), "H");Examples found in repository?
More examples
4fn main() {
5 for period in 1..=N_PERIODS {
6 for group in Group::list() {
7 let element = Element::list()
8 .iter()
9 .find(|e| e.period() == period && e.group() == Some(*group));
10 match element {
11 Some(element) => print!("{:<4}", element.symbol()),
12 None => print!(" "),
13 }
14 }
15 println!();
16 }
17 println!();
18 for period in 6..=7 {
19 print!(" ");
20 for element in Element::list()
21 .iter()
22 .filter(|el| el.period() == period && el.group().is_none())
23 {
24 print!("{:<4}", element.symbol());
25 }
26 println!();
27 }
28}4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn year_discovered(&self) -> YearDiscovered
pub const fn year_discovered(&self) -> YearDiscovered
The year in which the element was discovered, if known.
use mendeleev::{Element, YearDiscovered};
assert_eq!(Element::H.year_discovered(), YearDiscovered::Known(1766));
assert_eq!(Element::Og.year_discovered(), YearDiscovered::Known(2002));
assert_eq!(Element::Au.year_discovered(), YearDiscovered::Ancient);Examples found in repository?
4fn main() {
5 let columns: Vec<(&str, Box<dyn Fn(&Element) -> String>)> = vec![
6 (
7 "Number",
8 Box::new(|e: &Element| e.atomic_number().to_string()),
9 ),
10 ("Symbol", Box::new(|e: &Element| e.symbol().to_string())),
11 (
12 "Name ",
13 Box::new(|e: &Element| format!("{:<10}", e.name())),
14 ),
15 (
16 "Year",
17 Box::new(|e: &Element| e.year_discovered().to_string()),
18 ),
19 (
20 "CPK color",
21 Box::new(|e: &Element| {
22 format!(
23 "{:<10}",
24 e.cpk_color()
25 .map(|c| c.to_string())
26 .unwrap_or("".to_string()),
27 )
28 }),
29 ),
30 (
31 "Jmol color",
32 Box::new(|e: &Element| {
33 format!(
34 "{:<10}",
35 e.jmol_color()
36 .map(|c| c.to_string())
37 .unwrap_or("".to_string()),
38 )
39 }),
40 ),
41 (
42 "Atomic Weight",
43 Box::new(|e: &Element| format!("{:<10}", e.atomic_weight().to_string())),
44 ),
45 (
46 "Atomic Radius",
47 Box::new(|e: &Element| {
48 format!(
49 "{:10}",
50 e.atomic_radius()
51 .map(|r| r.to_string())
52 .unwrap_or("".to_string())
53 )
54 }),
55 ),
56 ("Period", Box::new(|e: &Element| e.period().to_string())),
57 (
58 "Group",
59 Box::new(|e: &Element| {
60 format!("{:<10}", e.group().map(|g| g.group_symbol()).unwrap_or(""))
61 }),
62 ),
63 ];
64 println!(
65 "{}",
66 columns
67 .iter()
68 .map(|(name, _)| *name)
69 .collect::<Vec<_>>()
70 .join("\t")
71 );
72 for element in Element::list() {
73 println!(
74 "{}",
75 columns
76 .iter()
77 .map(|(_, prop)| prop(&element))
78 .collect::<Vec<_>>()
79 .join("\t")
80 );
81 }
82}Source§impl Element
impl Element
Sourcepub const fn melting_point(&self) -> Option<Kelvin>
pub const fn melting_point(&self) -> Option<Kelvin>
Returns the element’s melting point, if known.
For some elements that do not melt at atmospheric pressure, the value is given for triple point pressure.
For elements that have multiple allotropes, one of them was chosen arbitrarily for the return value.
use mendeleev::{Element, Kelvin};
assert_eq!(Element::H.melting_point(), Some(Kelvin(13.99)));
// Carbon allotropes have no melting point at standard pressure
assert_eq!(Element::C.melting_point(), None);
// White phosphorus
assert_eq!(Element::P.melting_point(), Some(Kelvin(317.3)));
assert_eq!(Element::Og.melting_point(), None);Source§impl Element
impl Element
Sourcepub const fn boiling_point(&self) -> Option<Kelvin>
pub const fn boiling_point(&self) -> Option<Kelvin>
Returns the element’s boiling point, if known.
For elements that have multiple allotropes, one of them was chosen arbitrarily for the return value.
use mendeleev::{Element, Kelvin};
assert_eq!(Element::H.boiling_point(), Some(Kelvin(20.271)));
// Graphite (sublimation point)
assert_eq!(Element::C.boiling_point(), Some(Kelvin(4098.15)));
// White phosphorus
assert_eq!(Element::P.boiling_point(), Some(Kelvin(553.65)));
assert_eq!(Element::Og.boiling_point(), None);Source§impl Element
impl Element
Sourcepub const fn fusion_heat(&self) -> Option<KiloJoulePerMole>
pub const fn fusion_heat(&self) -> Option<KiloJoulePerMole>
Returns the element’s fusion heat, if known.
use mendeleev::{Element, KiloJoulePerMole};
assert_eq!(Element::H.fusion_heat(), Some(KiloJoulePerMole(0.117)));
assert_eq!(Element::Og.fusion_heat(), None);Source§impl Element
impl Element
Sourcepub const fn evaporation_heat(&self) -> Option<KiloJoulePerMole>
pub const fn evaporation_heat(&self) -> Option<KiloJoulePerMole>
Returns the element’s evaporation heat, if known.
use mendeleev::{Element, KiloJoulePerMole};
assert_eq!(Element::H.evaporation_heat(), Some(KiloJoulePerMole(0.904)));Source§impl Element
impl Element
Sourcepub const fn electronic_configuration(&self) -> ElectronicConfiguration
pub const fn electronic_configuration(&self) -> ElectronicConfiguration
Returns the element’s electronic configuration.
use mendeleev::{Element, SubshellLabel};
let configuration = Element::Li.electronic_configuration();
assert_eq!(configuration.noble_gas, Some(Element::He));
assert_eq!(configuration.valence_subshells[0].shell_number, 2);
assert_eq!(configuration.valence_subshells[0].subshell_label, SubshellLabel::S);
assert_eq!(configuration.valence_subshells[0].number_of_electrons, 1);Source§impl Element
impl Element
Sourcepub const fn discoverers(&self) -> Option<&'static [&'static str]>
pub const fn discoverers(&self) -> Option<&'static [&'static str]>
Returns the persons and/or institutions involved in the discovery of the element, if known.
use mendeleev::Element;
assert_eq!(Element::H.discoverers(), Some(["Henry Cavendish"].as_slice()));
assert_eq!(Element::He.discoverers(), Some(["Sir William Ramsey", "Nils Langet", "P.T.Cleve"].as_slice()));
assert_eq!(Element::Og.discoverers(), Some(["Joint Institute for Nuclear Research"].as_slice()));
assert_eq!(Element::Au.discoverers(), None);Source§impl Element
impl Element
Sourcepub const fn discovery_location(&self) -> Option<&'static [&'static str]>
pub const fn discovery_location(&self) -> Option<&'static [&'static str]>
Returns the location (country, in most cases) where the element was discovered, if known. There can be multiple locations if it was an international effort or if multiple teams discovered or isolated the element independently.
use mendeleev::Element;
assert_eq!(Element::H.discovery_location(), Some(["England"].as_slice()));
assert_eq!(Element::He.discovery_location(), Some(["Scotland", "Sweden"].as_slice()));
assert_eq!(Element::Og.discovery_location(), Some(["Russia"].as_slice()));
assert_eq!(Element::Au.discovery_location(), None);Source§impl Element
impl Element
Sourcepub const fn oxidation_states(
&self,
category: OxidationStateCategory,
) -> &'static [i8]
pub const fn oxidation_states( &self, category: OxidationStateCategory, ) -> &'static [i8]
Returns the element’s oxidation states for the given category.
§Example
use mendeleev::{Element, OxidationStateCategory::{Main, Extended, All}};
assert_eq!(Element::N.oxidation_states(Main), [-3, 3, 5]);
assert_eq!(Element::N.oxidation_states(Extended), [-2, -1, 0, 1, 2, 4]);
assert_eq!(Element::N.oxidation_states(All), [-3, -2, -1, 0, 1, 2, 3, 4, 5]);Source§impl Element
impl Element
Sourcepub const fn density(&self) -> Option<GramPerCubicCentimeter>
pub const fn density(&self) -> Option<GramPerCubicCentimeter>
Returns the element’s density in its most common form, if available.
use mendeleev::{Element, GramPerCubicCentimeter};
assert_eq!(Element::H.density(), Some(GramPerCubicCentimeter(0.00008988)));Source§impl Element
impl Element
Sourcepub const fn electron_affinity(&self) -> Option<Electronvolt>
pub const fn electron_affinity(&self) -> Option<Electronvolt>
Returns the element’s electron affinity, if available.
use mendeleev::{Element, Electronvolt};
assert_eq!(Element::H.electron_affinity(), Some(Electronvolt(0.754)));Source§impl Element
impl Element
Sourcepub const fn ionization_energy(&self) -> Option<Electronvolt>
pub const fn ionization_energy(&self) -> Option<Electronvolt>
Returns the element’s ionization energy, if available.
use mendeleev::{Element, Electronvolt};
assert_eq!(Element::H.ionization_energy(), Some(Electronvolt(13.598)));