Element

Enum Element 

Source
pub enum Element {
    H,
    He,
    Li,
    // some variants omitted
}
Expand description

Each of the known chemical elements

Variants§

§

H

Hydrogen

§

He

Helium

§

Li

Lithium

Implementations§

Source§

impl Element

Source

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?
examples/print_electronic_configuration.rs (line 5)
4fn main() {
5    for element in Element::list() {
6        println!(
7            "{}:\t{}",
8            element.symbol(),
9            element.electronic_configuration()
10        );
11    }
12}
More examples
Hide additional examples
examples/print_isotope_abundance.rs (line 5)
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}
examples/print_periodic_table.rs (line 7)
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}
examples/print_all_elements.rs (line 72)
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

pub fn iter() -> impl Iterator<Item = Self> + Clone

Returns an iterator that yields all the elements by value, ordered by atomic number

use mendeleev::Element;

assert_eq!(Element::iter().next(), Some(Element::H));
Source§

impl Element

Source

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?
examples/print_all_elements.rs (line 8)
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

Source

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?
examples/print_all_elements.rs (line 50)
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

Source

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?
examples/print_all_elements.rs (line 43)
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

Source

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?
examples/print_all_elements.rs (line 24)
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

Source

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?
examples/print_periodic_table.rs (line 9)
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
Hide additional examples
examples/print_all_elements.rs (line 60)
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

Source

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?
examples/print_all_elements.rs (line 35)
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

Source

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?
examples/print_isotope_abundance.rs (line 6)
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
Hide additional examples
examples/print_all_elements.rs (line 13)
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

Source

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?
examples/print_periodic_table.rs (line 9)
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
Hide additional examples
examples/print_all_elements.rs (line 56)
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

Source

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?
examples/print_electronic_configuration.rs (line 8)
4fn main() {
5    for element in Element::list() {
6        println!(
7            "{}:\t{}",
8            element.symbol(),
9            element.electronic_configuration()
10        );
11    }
12}
More examples
Hide additional examples
examples/print_periodic_table.rs (line 11)
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}
examples/print_all_elements.rs (line 10)
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

Source

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?
examples/print_all_elements.rs (line 17)
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

Source

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

Source

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

Source

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

Source

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

Source

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);
Examples found in repository?
examples/print_electronic_configuration.rs (line 9)
4fn main() {
5    for element in Element::list() {
6        println!(
7            "{}:\t{}",
8            element.symbol(),
9            element.electronic_configuration()
10        );
11    }
12}
Source§

impl Element

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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)));

Trait Implementations§

Source§

impl Clone for Element

Source§

fn clone(&self) -> Element

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Element

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Element

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Element

Source§

fn cmp(&self, other: &Element) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Element

Source§

fn eq(&self, other: &Element) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Element

Source§

fn partial_cmp(&self, other: &Element) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Element

Source§

impl Eq for Element

Source§

impl StructuralPartialEq for Element

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.