Debian Codegraph @

examples/print_isotope_abundance.rs

raw symbols SCIP
1 use mendeleevrust-analyzer cargo mendeleev 0.8.1 crate/::{Elementrust-analyzer cargo mendeleev 0.8.1 element/Element#, Isotoperust-analyzer cargo mendeleev 0.8.1 isotope/Isotope#};
2
3 /// For each element, print all its naturally occurring isotopes and their abundance
4 fn mainrust-analyzer cargo mendeleev 0.8.1 main().() {
5 for element in Elementrust-analyzer cargo mendeleev 0.8.1 element/Element#::listrust-analyzer cargo mendeleev 0.8.1 element/array/impl#[Element]list().() {
6 printrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/print!!("{}: ", element.namerust-analyzer cargo mendeleev 0.8.1 properties/name/impl#[Element]name().());
7 let isotope_count = Isotoperust-analyzer cargo mendeleev 0.8.1 isotope/Isotope#::listrust-analyzer cargo mendeleev 0.8.1 isotope/array/impl#[Isotope]list().()
8 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
9 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|isotope| &isotope.elementrust-analyzer cargo mendeleev 0.8.1 properties/isotopes/element/impl#[Isotope]element().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().element)
10 .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|isotope| {
11 let abundance = isotope.natural_abundancerust-analyzer cargo mendeleev 0.8.1 properties/isotopes/natural_abundance/impl#[Isotope]natural_abundance().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
12 printrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/print!!("{}: {}, ", isotope.display_with_superscriptrust-analyzer cargo mendeleev 0.8.1 isotope/display/impl#[Isotope]display_with_superscript().(), abundance);
13 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(())
14 })
15 .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/flatten/impl#[`FlatMap<I, U, F>`][Iterator]count().();
16 if isotope_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
17 printrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/print!!("No naturally occurring isotopes");
18 }
19 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!();
20 }
21 }