Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

export DIRENV_WARN_TIMEOUT=20s

eval "$(devenv direnvrc)"

# `use devenv` supports the same options as the `devenv shell` command.
#
# To silence all output, use `--quiet`.
#
# Example usage: use devenv --quiet --impure --option services.postgres.enable:bool true
use devenv
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ Cargo.lock
*.bk
.vscode
*.sublime-workspace

# Devenv
.devenv*
devenv.local.nix
devenv.local.yaml

# direnv
.direnv

# pre-commit
.pre-commit-config.yaml
123 changes: 123 additions & 0 deletions devenv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1763939584,
"owner": "cachix",
"repo": "devenv",
"rev": "1ebc7baa0726314d24bb5cc34d5fc7927aa57929",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1761588595,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "f387cd2afec9419c8ee37694406ca490c3f34ee5",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"git-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1763741496,
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "20e71a403c5de9ce5bd799031440da9728c1cda1",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"git-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1762808025,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "cb5e3fdca1de58ccbc3ef53de65bd372b48f567c",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1761313199,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "d1c30452ebecfc55185ae6d1c983c09da0c274ff",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"git-hooks": "git-hooks",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": [
"git-hooks"
],
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1763952169,
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "ab726555a9a72e6dc80649809147823a813fa95b",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
59 changes: 59 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
pkgs,
lib,
config,
inputs,
...
}: {
# https://devenv.sh/basics/
env.GREET = "devenv";

# https://devenv.sh/packages/
packages = with pkgs; [
git
bacon
cargo-nextest
gitui
helix
];

# https://devenv.sh/languages/
languages.rust = {
enable = true;
channel = "stable";
};

# https://devenv.sh/processes/
# processes.dev.exec = "${lib.getExe pkgs.watchexec} -n -- ls -la";

# https://devenv.sh/services/
# services.postgres.enable = true;

# https://devenv.sh/scripts/
scripts.hello.exec = ''
echo hello from $GREET
'';

# https://devenv.sh/basics/
enterShell = ''
hello # Run scripts directly
git --version # Use packages
'';

# https://devenv.sh/tasks/
# tasks = {
# "myproj:setup".exec = "mytool build";
# "devenv:enterShell".after = [ "myproj:setup" ];
# };

# https://devenv.sh/tests/
enterTest = ''
echo "Running tests"
git --version | grep --color=auto "${pkgs.git.version}"
'';

# https://devenv.sh/git-hooks/
# git-hooks.hooks.shellcheck.enable = true;

# See full reference at https://devenv.sh/reference/options/
}
8 changes: 8 additions & 0 deletions devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
rust-overlay:
url: github:oxalica/rust-overlay
inputs:
nixpkgs:
follows: nixpkgs
24 changes: 24 additions & 0 deletions src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub const WATT_HORSEPOWER_FACTOR: f64 = 1.0 / 745.6998715822702;
pub const WATT_BTU_MIN_FACTOR: f64 = 1.0 / 17.58426666666667;
/// Number of kW in a W
pub const WATT_KILOWATT_FACTOR: f64 = 1e-3;
/// Number of MW in a W
pub const WATT_MEGAWATT_FACTOR: f64 = 1e-6;
/// Number of mW in a W
pub const WATT_MILLIWATT_FACTOR: f64 = 1e3;
/// Number of µW in a W
Expand Down Expand Up @@ -74,6 +76,11 @@ impl Power {
Self::from_watts(kw / WATT_KILOWATT_FACTOR)
}

/// Create a new Power from a floating point value in Megawatts (kW)
pub fn from_megawatts(kw: f64) -> Power {
Self::from_watts(kw / WATT_MEGAWATT_FACTOR)
}

/// Convert this Power into a floating point value in Watts
pub fn as_watts(&self) -> f64 {
self.watts
Expand Down Expand Up @@ -104,6 +111,11 @@ impl Power {
self.watts * WATT_KILOWATT_FACTOR
}

/// Convert this Power into a floating point value in megawatts (MW)
pub fn as_megawatts(&self) -> f64 {
self.watts * WATT_MEGAWATT_FACTOR
}

/// Convert this Power into a floating point value in milliwatts (mW)
pub fn as_milliwatts(&self) -> f64 {
self.watts * WATT_MILLIWATT_FACTOR
Expand Down Expand Up @@ -190,6 +202,18 @@ mod test {
assert_almost_eq(r2, 0.1);
}

#[test]
pub fn as_megawatts() {
let i1 = Power::from_megawatts(100.0);
let r1 = i1.as_watts();

let i2 = Power::from_watts(100_000.0);
let r2 = i2.as_megawatts();

assert_almost_eq(r1, 100_000_000.0);
assert_almost_eq(r2, 0.1);
}

#[test]
pub fn as_milliwatts() {
let i1 = Power::from_milliwatts(100.0);
Expand Down
17 changes: 17 additions & 0 deletions src/voltage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl Voltage {
Self::from_volts(kilovolts * 1000.0)
}

/// Create a new Voltage from a floating point value in Megavolts
pub fn from_megavolts(megavolts: f64) -> Self {
Self::from_volts(megavolts * 1000000.0)
}


/// Convert this Voltage into a floating point value in Volts
pub fn as_volts(&self) -> f64 {
self.volts
Expand All @@ -61,6 +67,11 @@ impl Voltage {
pub fn as_kilovolts(&self) -> f64 {
self.volts / 1000.0
}

/// Convert this Voltage into a floating point value in Megavolts
pub fn as_megavolts(&self) -> f64 {
self.volts / 1000000.0
}
}

impl Measurement for Voltage {
Expand Down Expand Up @@ -108,6 +119,12 @@ mod test {
assert_almost_eq(u.as_kilovolts(), 10.0);
}

#[test]
pub fn as_megavolts() {
let u = Voltage::from_volts(10_000_000.0);
assert_almost_eq(u.as_megavolts(), 10.0);
}

#[test]
pub fn as_volts() {
let u = Voltage::from_kilovolts(1.234);
Expand Down
Loading