~kmaasrud/wtr

60d144f939413cd2f3ae7acefcba39f676920450 — Knut Magnus Aasrud 4 months ago
init: setup library with basic structs
8 files changed, 275 insertions(+), 0 deletions(-)

A .envrc
A .gitignore
A Cargo.lock
A Cargo.toml
A flake.lock
A flake.nix
A src/lib.rs
A src/main.rs
A  => .envrc +1 -0
@@ 1,1 @@
use flake .

A  => .gitignore +2 -0
@@ 1,2 @@
/target
.direnv/

A  => Cargo.lock +65 -0
@@ 1,65 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "serde"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
dependencies = [
 "serde_derive",
]

[[package]]
name = "serde_derive"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "syn"
version = "2.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

[[package]]
name = "wtr"
version = "0.1.0"
dependencies = [
 "serde",
]

A  => Cargo.toml +7 -0
@@ 1,7 @@
[package]
name = "wtr"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1.0.197", features = ["derive"] }

A  => flake.lock +87 -0
@@ 1,87 @@
{
  "nodes": {
    "crane": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1708794349,
        "narHash": "sha256-jX+B1VGHT0ruHHL5RwS8L21R6miBn4B6s9iVyUJsJJY=",
        "owner": "ipetkov",
        "repo": "crane",
        "rev": "2c94ff9a6fbeb9f3ea0107f28688edbe9c81deaa",
        "type": "github"
      },
      "original": {
        "owner": "ipetkov",
        "repo": "crane",
        "type": "github"
      }
    },
    "fenix": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs"
        ],
        "rust-analyzer-src": "rust-analyzer-src"
      },
      "locked": {
        "lastModified": 1709101340,
        "narHash": "sha256-C5DqUNDlcI6t11w14MMIt0ojLOD05m35ea9DQ7gIQpY=",
        "owner": "nix-community",
        "repo": "fenix",
        "rev": "daa2bef600e492c137c34d01792e10067589c31d",
        "type": "github"
      },
      "original": {
        "owner": "nix-community",
        "repo": "fenix",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1709101946,
        "narHash": "sha256-TsySgcWm/GlbYdL3AEva49ceeI2BdPQ7muwfYNr1fwo=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "d53c2037394da6fe98decca417fc8fda64bf2443",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "crane": "crane",
        "fenix": "fenix",
        "nixpkgs": "nixpkgs"
      }
    },
    "rust-analyzer-src": {
      "flake": false,
      "locked": {
        "lastModified": 1709057983,
        "narHash": "sha256-ZwIAbq4qRR6Kfdmq9P9/Siieebe2R9dkwTvppsK3oSM=",
        "owner": "rust-lang",
        "repo": "rust-analyzer",
        "rev": "0ac05c05271f31c43d31017cbd288e8737a0edb0",
        "type": "github"
      },
      "original": {
        "owner": "rust-lang",
        "ref": "nightly",
        "repo": "rust-analyzer",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}

A  => flake.nix +68 -0
@@ 1,68 @@
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

    crane = {
      url = "github:ipetkov/crane";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    nixpkgs,
    crane,
    fenix,
    ...
  }: let
    systems = ["x86_64-linux" "aarch64-linux"];
    eachSystem = systems: f: let
      # Merge together the outputs for all systems.
      op = attrs: system: let
        ret = f system;
        op = attrs: key:
          attrs
          // {
            ${key} =
              (attrs.${key} or {})
              // {${system} = ret.${key};};
          };
      in
        builtins.foldl' op attrs (builtins.attrNames ret);
    in
      builtins.foldl' op {} systems;
    forAllSystems = eachSystem systems;
  in
    forAllSystems (system: let
      pkgs = import nixpkgs {
        inherit system;
      };

      toolchain = with fenix.packages.${system};
        combine [
          stable.rustc
          stable.cargo
          stable.clippy
          stable.rustfmt
          targets.arm-unknown-linux-musleabihf.stable.rust-std
        ];

      craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
    in rec {
      packages.default = craneLib.buildPackage rec {
        src = pkgs.lib.cleanSourceWith {src = craneLib.path ./.;};
      };

      apps.default = {
        drv = packages.default;
      };

      devShells.default = pkgs.mkShell {
        nativeBuildInputs = with pkgs; [toolchain];
      };
    });
}

A  => src/lib.rs +42 -0
@@ 1,42 @@
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
pub struct Forecast {
    latitude: usize,
    longitude: usize,
    masl: usize,
    forecast: Vec<ForecastEntry>,
}

#[derive(Deserialize, Serialize)]
pub struct ForecastEntry {
    instant: Instant,
    next_one_hour: NextOneHour,
    next_six_hours: NextSixHours,
    next_twelve_hours: NextTwelveHours,
}

#[derive(Deserialize, Serialize)]
pub struct Instant {
    air_pressure_at_sea_level: f64,
    air_temperature: f64,
    cloud_area_fraction: f64,
    relative_humidity: f64,
    wind_from_direction: f64,
    wind_speed: f64,
}

#[derive(Deserialize, Serialize)]
pub struct NextOneHour {
    precipitation_amount: f64,
}

#[derive(Deserialize, Serialize)]
pub struct NextSixHours {
    precipitation_amount: f64,
}

#[derive(Deserialize, Serialize)]
pub struct NextTwelveHours {
    precipitation_amount: f64,
}

A  => src/main.rs +3 -0
@@ 1,3 @@
fn main() {
    println!("Hello, world!");
}