~ioiojo/kiwi

f18b4834875e6ff844014c802fd84bddc20e40e5 — Andy Weidenbaum 2 years ago 75da023
format and touch up comments
M src/cli_error.rs => src/cli_error.rs +1 -2
@@ 15,8 15,7 @@ pub enum CliError {
        kiwi_dir: PathBuf,
    },

    /// Could not convert Kiwi global config directory path (`path`) to valid UTF-8
    /// string.
    /// Could not convert Kiwi global config directory path (`path`) to valid UTF-8 string.
    MalformedKiwiConfigHomePath {
        path: PathBuf,
    },

M src/cli_setup.rs => src/cli_setup.rs +4 -6
@@ 205,8 205,7 @@ impl<'a> LoadDiet for Context<'a> {
        let module: Table = if let Some(Value::Boolean(true)) = ok_module.next() {
            // `pcall` was successful: found `diet` module.
            //
            // Return `Table` if given a `Value::Table` as expected, otherwise raise
            // error.
            // Return `Table` if given a `Value::Table` as expected, otherwise raise error.
            match ok_module.next() {
                Some(value) => match value {
                    Value::Table(module) if module.is_list() => module,


@@ 271,8 270,7 @@ impl<'a> LoadProfile for Context<'a> {
        let module: Table = if let Some(Value::Boolean(true)) = ok_module.next() {
            // `pcall` was successful: found `profile` module.
            //
            // Return `Table` if given a `Value::Table` as expected, otherwise raise
            // error.
            // Return `Table` if given a `Value::Table` as expected, otherwise raise error.
            match ok_module.next() {
                Some(Value::Table(module)) => module,
                _ => return Err(CliError::UnexpectedProfileModule),


@@ 291,8 289,8 @@ impl<'a> LoadProfile for Context<'a> {
            return Err(CliError::MissingProfileModule { cause });
        };

        // This could easily be an `.unwrap()`, because it’s assumed
        // `load_kiwi_profile()` is only called when `opts.name.is_some()`.
        // This could easily be an `.unwrap()`, because it’s assumed `load_kiwi_profile()`
        // is only called when `opts.name.is_some()`.
        let name: String = match opts.name.take() {
            Some(name) => name,
            None => return Err(CliError::MissingProfileName),

M src/dir_error.rs => src/dir_error.rs +3 -6
@@ 190,8 190,7 @@ pub enum InputFoodErrorKind {
    /// `Dine` instantiation function got malformed table input.
    Malformed(InputFoodError),

    /// `Dine` instantiation function got malformed table input in an unexpected
    /// position.
    /// `Dine` instantiation function got malformed table input in an unexpected position.
    UnexpectedMalformed(InputFoodError),
}



@@ 222,8 221,7 @@ pub enum DateStringErrorKind {
    /// `Dine` instantiation input datestring contents couldn’t be converted to UTF-8.
    Malformed(InputDateStringError),

    /// `Dine` instantiation function got valid datestring input in an unexpected
    /// position.
    /// `Dine` instantiation function got valid datestring input in an unexpected position.
    Unexpected(NaiveDateTime),

    /// `Dine` instantiation function got invalid datestring input in an unexpected


@@ 261,8 259,7 @@ pub enum DictErrorKind {
    /// `Dine` instantiation function got malformed table input.
    Malformed(Vec<DictKeyPairError>),

    /// `Dine` instantiation function got malformed table input in an unexpected
    /// position.
    /// `Dine` instantiation function got malformed table input in an unexpected position.
    UnexpectedMalformed(Vec<DictKeyPairError>),

    /// `Dine` instantiation function got valid table input with `Food` which couldn’t be

M src/fir_arg.rs => src/fir_arg.rs +7 -8
@@ 72,7 72,7 @@ pub struct FirArgs(pub Vec<(usize, FirArg)>);
pub enum FirArg {
    /// `rlua::String`.
    ///
    /// Wrapped in a `InputStringResult` to represent erroneous input, e.g. invalid
    /// Wrapped in an `InputStringResult` to represent erroneous input, e.g. invalid
    /// UTF-8.
    String(InputStringResult<String>),



@@ 83,8 83,8 @@ pub enum FirArg {

    /// `rlua::Table` with exclusively numeric keys.
    ///
    /// Wrapped in an `InputFoodAvgResult` to represent erroneous input, e.g.
    /// unsupported elements.
    /// Wrapped in an `InputFoodAvgResult` to represent erroneous input, e.g. unsupported
    /// elements.
    List(InputFoodAvgResult<List>),

    /// An unsupported value.


@@ 571,9 571,9 @@ impl TryFrom<Table<'_>> for FoodAvg {

    fn try_from(table: Table) -> InputFoodAvgResult<Self> {
        // Make the sequence `Peekable` to facilitate checking for ratios. Or rather, to
        // facilitate not needing to e.g. `sequence_values` twice — as would be
        // necessary if instead `.nth(1)` were used to check whether the second list
        // element were a ratio — or similar.
        // facilitate not needing to e.g. `sequence_values` twice — as would be necessary
        // if instead `.nth(1)` were used to check whether the second list element were a
        // ratio — or similar.
        let mut iter = table
            .sequence_values::<Value>()
            .map(|v| v.expect(SEQUENCE_VALUES_EXPECT))


@@ 1439,8 1439,7 @@ fn handle_phenylalanine_value(
            builder.phenylalanine(phenylalanine);
        }
        Err(e) => {
            // Convert `DictAminoAcidsPhenylalanineError` to
            // `DictAminoAcidsKeyPairError`.
            // Convert `DictAminoAcidsPhenylalanineError` to `DictAminoAcidsKeyPairError`.
            let error = DictAminoAcidsKeyPairError::from(e);
            unsupported.push_or_init(error);
        }

M src/fir_consts.rs => src/fir_consts.rs +3 -4
@@ 1,5 1,4 @@
/// Error message designed for instantiating `Composite` with length-checked
/// `constituents`.
/// Error message designed for instantiating `Composite` with length-checked `constituents`.
pub const COMPOSITE_NEW_EXPECT: &str =
    "Instantiating `Composite` with length-checked constituents unexpectedly failed";



@@ 23,8 22,8 @@ pub const PAIRS_EXPECT: &str = "`rlua::TablePairs::pairs()` unexpectedly failed"
/// Error message designed for situations where we’re sifting through partitioned data.
pub const PARTITIONED_EXPECT: &str = "Partitioning unexpectedly failed";

/// Error message designed for unwrapping `Result` from
/// `rlua::Context::registry_value()`, which should always succeed.
/// Error message designed for unwrapping `Result` from `rlua::Context::registry_value()`,
/// which should always succeed.
pub const REGISTRY_VALUE_EXPECT: &str = "Fetching registry value unexpectedly failed";

/// Error message for `Iterator::Item.expect()` in `rlua::TableSequence`’ — which `rlua`

M src/fir_error.rs => src/fir_error.rs +3 -6
@@ 446,8 446,7 @@ pub enum InputQuantityError {
    /// Expected `Quantity` number to be greater than or equal to zero, but got `number`.
    MalformedNumber { number: f64 },

    /// Expected `Quantity` number to be greater than or equal to zero, but got
    /// `integer`.
    /// Expected `Quantity` number to be greater than or equal to zero, but got `integer`.
    MalformedInteger { integer: i64 },

    /// Expected `Quantity` value to be a number or list, but got `got`.


@@ 595,8 594,7 @@ pub enum InputFoodAvgError {
    /// instantiation.
    MalformedElemFoodQuantityTableLength { table_pairs_len: usize },

    /// Expected `FoodAvgElem` instantiation input to be a table or `Food`, but got
    /// `got`.
    /// Expected `FoodAvgElem` instantiation input to be a table or `Food`, but got `got`.
    MissingElemTableOrFood { got: &'static str },

    /// Couldn’t convert `Quantity::ServingSize` to `ServingSize`.


@@ 698,8 696,7 @@ pub enum DictErrorKind {
    /// `Food` instantiation function got malformed table input.
    Malformed(Vec<DictKeyPairError>),

    /// `Food` instantiation function got malformed table input in an unexpected
    /// position.
    /// `Food` instantiation function got malformed table input in an unexpected position.
    UnexpectedMalformed(Vec<DictKeyPairError>),

    /// `Food` instantiation function got valid table input with `Food` which couldn’t be

M src/fir_traits.rs => src/fir_traits.rs +1 -2
@@ 1,7 1,6 @@
use rlua::{Context, Function, Table, Value};

/// Error message for `rlua::Table::contains_key(1).expect()` — which should always
/// succeed.
/// Error message for `rlua::Table::contains_key(1).expect()` — which should always succeed.
const TABLE_CONTAINS_KEY_1_EXPECT: &str = "`rlua::Table::contains_key(1)` unexpectedly failed";

pub trait FennelView<'a> {

M src/food.rs => src/food.rs +2 -1
@@ 966,7 966,8 @@ pub struct Composite {
    /// `Env` is optional in `Composite` foods because macronutrient values — which would
    /// otherwise have to be obtained by consulting an `Env` — can be automatically
    /// derived from constituent foods comprising the `Composite`. Constituent foods are
    /// guaranteed to contain at least one `Simple` food¹.
    /// guaranteed to contain at least one `Simple` food¹, which are in turn guaranteed
    /// to contain an `Env`.
    ///
    /// ¹: Except in the case where recursion limits are exceeded.
    pub env: Option<CompositeEnv>,

M src/plan.rs => src/plan.rs +1 -2
@@ 46,8 46,7 @@ pub struct Plan {
    /// 4. Thermic Effect of Activity (Exercise)
    ///
    /// For simplicity, factors 2-4 are condensed into a single factor called *Activity
    /// Level*. The specified Activity Level controls the Katch–McArdle multiplier on
    /// BMR.
    /// Level*. The specified Activity Level controls the Katch–McArdle multiplier on BMR.
    pub tdee: f64,

    /// Recommended Caloric Intake

M src/tir.rs => src/tir.rs +2 -2
@@ 19,8 19,8 @@ const DATA_POSITION: usize = 0;
const DIET_DINE_EXPECT: &str =
    "Unexpectedly could not find `Some` value for pre-checked dine collection";

/// Error message designed for running `rlua::Table::len(table)` where `table` is a
/// known list.
/// Error message designed for running `rlua::Table::len(table)` where `table` is a known
/// list.
const TABLE_LEN_EXPECT: &str = "Unexpectedly could not get length of table";

/// Error message designed for converting the `i64` returned by `rlua::Table::len(table)`

M src/tir_arg.rs => src/tir_arg.rs +3 -3
@@ 18,9 18,9 @@ pub struct TirArgs(pub Vec<(usize, TirArg)>);
/// `rlua::MultiValue`.
///
/// The values wrapped in `Result` are wrapped as such to preserve context, e.g. that we
/// received `rlua::UserData` which proved to contain either valid or invalid input
/// during processing. Said context is useful in enforcing the order of arguments during
/// `Diet` instantiation.
/// received `rlua::UserData` which proved to contain either valid or invalid input during
/// processing. Said context is useful in enforcing the order of arguments during `Diet`
/// instantiation.
#[derive(Debug)]
pub enum TirArg {
    Dine(InputDineResult<Dine>),