Repository: casey/just
File: src/function.rs (Rust)

Code before:
pub(crate) enum Function {
  Nullary(fn(&FunctionContext) -> Result<String, String>),
  Unary(fn(&FunctionContext, &str) -> Result<String, String>),
  Binary(fn(&FunctionContext, &str, &str) -> Result<String, String>),
  Ternary(fn(&FunctionContext, &str, &str, &str) -> Result<String, String>),
}

lazy_static! {
  pub(crate) static ref TABLE: BTreeMap<&'static str, Function> = vec![
    ("arch", Nullary(arch)),
    ("clean", Unary(clean)),
    ("env_var", Unary(env_var)),
    ("env_var_or_default", Binary(env_var_or_default)),
    ("extension", Unary(extension)),
    ("file_name", Unary(file_name)),
    ("file_stem", Unary(file_stem)),
    ("invocation_directory", Nullary(invocation_directory)),
    ("join", Binary(join)),
    ("just_executable", Nullary(just_executable)),
    ("justfile", Nullary(justfile)),
    ("justfile_directory", Nullary(justfile_directory)),
    ("os", Nullary(os)),
    ("os_family", Nullary(os_family)),
    ("parent_directory", Unary(parent_directory)),
    ("without_extension", Unary(without_extension)),
    ("uppercase", Unary(uppercase)),
    ("lowercase", Unary(lowercase)),
    ("trim", Unary(trim)),
    ("replace", Ternary(replace)),
  ]
  .into_iter()
  .collect();
}

impl Function {
  pub(crate) fn argc(&self) -> usize {
    match *self {
      Nullary(_) => 0,
      Unary(_) => 1,
      Binary(_) => 2,
      Ternary(_) => 3,
    }
  }
}

fn arch(_context: &FunctionContext) -> Result<String, String> {
  Ok(target::arch().to_owned())
}

fn clean(_context: &FunctionContext, path: &str) -> Result<String, String> {
  Ok(Path::new(path).lexiclean().to_str().unwrap().to_owned())

Review comment (suggestion):
Ahh, sorry I forgot, this list should be sorted. Also, the functions themselves should also be declared in alphabetic order in this file.

Code after:
pub(crate) enum Function {
  Nullary(fn(&FunctionContext) -> Result<String, String>),
  Unary(fn(&FunctionContext, &str) -> Result<String, String>),
  Binary(fn(&FunctionContext, &str, &str) -> Result<String, String>),
  Ternary(fn(&FunctionContext, &str, &str, &str) -> Result<String, String>),
}

lazy_static! {
  pub(crate) static ref TABLE: BTreeMap<&'static str, Function> = vec![
    ("arch", Nullary(arch)),
    ("clean", Unary(clean)),
    ("env_var", Unary(env_var)),
    ("env_var_or_default", Binary(env_var_or_default)),
    ("extension", Unary(extension)),
    ("file_name", Unary(file_name)),
    ("file_stem", Unary(file_stem)),
    ("invocation_directory", Nullary(invocation_directory)),
    ("join", Binary(join)),
    ("just_executable", Nullary(just_executable)),
    ("justfile", Nullary(justfile)),
    ("justfile_directory", Nullary(justfile_directory)),
    ("lowercase", Unary(lowercase)),
    ("os", Nullary(os)),
    ("os_family", Nullary(os_family)),
    ("parent_directory", Unary(parent_directory)),
    ("replace", Ternary(replace)),
    ("trim", Unary(trim)),
    ("uppercase", Unary(uppercase)),
    ("without_extension", Unary(without_extension)),
  ]
  .into_iter()
  .collect();
}

impl Function {
  pub(crate) fn argc(&self) -> usize {
    match *self {
      Nullary(_) => 0,
      Unary(_) => 1,
      Binary(_) => 2,
      Ternary(_) => 3,
    }
  }
}

fn arch(_context: &FunctionContext) -> Result<String, String> {
  Ok(target::arch().to_owned())
}

fn clean(_context: &FunctionContext, path: &str) -> Result<String, String> {
  Ok(Path::new(path).lexiclean().to_str().unwrap().to_owned())