Debian Codegraph @

src/isotope/display.rs

raw symbols SCIP
1 use crate::superscript::Superscript;
2 use std::{format, string::String};
3
4 use super::Isotope;
5
6 impl Isotope {
7 /// Returns the isotope represented as a string using the
8 /// element's name in English and the mass number.
9 ///
10 /// ```
11 /// use mendeleev::Isotope;
12 /// assert_eq!(Isotope::H1.display_with_name(), "Hydrogen-1");
13 /// ```
14 pub fn display_with_name(&self) -> String {
15 format!("{}-{}", self.element().name(), self.mass_number())
16 }
17
18 /// Returns the isotope represented as a string using the
19 /// element's chemical symbol and the mass number.
20 ///
21 /// ```
22 /// use mendeleev::Isotope;
23 /// assert_eq!(Isotope::H1.display_with_symbol(), "H-1");
24 /// ```
25 pub fn display_with_symbol(&self) -> String {
26 format!("{}-{}", self.element().symbol(), self.mass_number())
27 }
28
29 /// Returns the isotope represented as a string using the
30 /// element's chemical symbol and the mass number as a UTF-8\
31 /// superscript.
32 ///
33 /// ```
34 /// use mendeleev::Isotope;
35 /// assert_eq!(Isotope::H1.display_with_superscript(), "¹H");
36 /// ```
37 pub fn display_with_superscript(&self) -> String {
38 format!(
39 "{}{}",
40 Superscript::new(self.mass_number()),
41 self.element().symbol()
42 )
43 }
44 }