scientific-constants 0.1.1

Access, use and create scientific constants in your codebase!
Documentation
//! # Chemistry and physics
//! Constants more commonly seen and used in chemistry and physics.

use std::fmt::Display;

pub mod science;

/// # Examples
/// Accessing Planck's constant's fields:
/// ```
/// use scientific_constants::constants::science::*;
/// 
/// println!("Symbol: {}\nValue: {}\n Unit: {}", PLANCK.symbol, PLANCK.value, PLANCK.unit)
/// ```
#[derive(Debug, Clone, Copy)]
pub struct Constant<'a> {
    pub symbol: &'a str,
    pub value: f64,
    pub unit: &'a str,
}

impl<'a> Constant<'a> {
    /// Create a new/custom constant
    ///
    /// # Arguments
    /// * `symbol` - A string slice that contains the symbol's name.
    /// * `value` - A 64-bit floating point number that contains the symbol's value.
    /// * `unit` - A string slice that contains the symbol's SI unit.
    ///
    /// # Examples
    /// The following example illustrates how to create new a constant and use it:
    /// ```
    /// use scientific_constants::constants::Constant;
    ///
    /// // Creating a new constant with the 'const' keyword
    /// const PLANCK: Constant = Constant::new("h", 6.62607015e-34, "J * 1/s");
    /// println!("Planck's constant:\n{:?}", PLANCK)
    /// ```
    pub const fn new(symbol: &'a str, value: f64, unit: &'a str) -> Self {
        return Self { symbol, value, unit };
    }
}

/// Default stdout behaviour when no debugging is explicitly used.
impl<'a> Display for Constant<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        return write!(f, "Symbol: {} Value: {} Unit: {}", self.symbol, self.value, self.unit);
    }
}