Group

Enum Group 

Source
pub enum Group {
    IA,
    IIA,
    // some variants omitted
}
Expand description

Each group in the periodic table

Variants§

§

IA

Alkali metals

§

IIA

Alkaline earths

Implementations§

Source§

impl Group

Source

pub const fn group_name(&self) -> Option<&'static str>

Returns the group’s trivial name, if any.

use mendeleev::Group;
assert_eq!(Group::IA.group_name(), Some("Alkali metals"));
assert_eq!(Group::VIIIA.group_name(), Some("Noble gases"));
assert_eq!(Group::VIIIB8.group_name(), None);
Source§

impl Group

Source

pub const fn group_number(&self) -> u32

Returns the group’s number in the periodic table.

use mendeleev::Group;
assert_eq!(Group::IA.group_number(), 1);
assert_eq!(Group::VIIIA.group_number(), 18);
Source§

impl Group

Source

pub const fn group_symbol(&self) -> &'static str

Returns the group’s symbol in the CAS system

use mendeleev::Group;
assert_eq!(Group::IA.group_symbol(), "IA");
assert_eq!(Group::VIIIA.group_symbol(), "VIIIA");
assert_eq!(Group::VIIIB8.group_symbol(), "VIIIB");
Examples found in repository?
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 Group

Source

pub const fn list() -> &'static [Self]

Slice containing all groups, ordered by group number

use mendeleev::Group;
use mendeleev::N_GROUPS;

for n in 1..=N_GROUPS {
    assert_eq!(Group::list()[n - 1].group_number() as usize, n);
}
Examples found in repository?
examples/print_periodic_table.rs (line 6)
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}
Source

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

Returns an iterator that yields all the groups by value, ordered by group number

use mendeleev::Group;

assert_eq!(Group::iter().next(), Some(Group::IA));

Trait Implementations§

Source§

impl Clone for Group

Source§

fn clone(&self) -> Group

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 Group

Source§

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

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

impl Hash for Group

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 Group

Source§

fn cmp(&self, other: &Group) -> 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 Group

Source§

fn eq(&self, other: &Group) -> 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 Group

Source§

fn partial_cmp(&self, other: &Group) -> 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 Group

Source§

impl Eq for Group

Source§

impl StructuralPartialEq for Group

Auto Trait Implementations§

§

impl Freeze for Group

§

impl RefUnwindSafe for Group

§

impl Send for Group

§

impl Sync for Group

§

impl Unpin for Group

§

impl UnwindSafe for Group

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.