1
Fork 0

Compare commits

...

4 Commits
0.1.0 ... main

Author SHA1 Message Date
Bauke e5dd90547f
Update dependencies and fix Deserialize lifetime. 2024-02-01 13:20:52 +01:00
Bauke ffc0333e5c
Add Nix flake and direnv files. 2024-02-01 13:16:43 +01:00
Bauke 6ec6e77b92
Parse also errors when TOML parsing fails. 2023-01-07 13:08:33 +01:00
Bauke cc51e71b06
Inst' -> isn't. 2023-01-06 14:11:26 +01:00
9 changed files with 198 additions and 38 deletions

3
.envrc Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
use flake

8
.gitignore vendored
View File

@ -1,7 +1,5 @@
# Generated by Cargo.
Cargo.lock
.direnv/
coverage/
debug/
target/
# Coverage results.
coverage/
Cargo.lock

View File

@ -13,13 +13,13 @@ edition = "2021"
path = "source/lib.rs"
[dependencies]
anyhow = "1.0.68"
toml = "0.5.10"
anyhow = "1.0.79"
toml = "0.8.9"
[dependencies.serde]
features = ["derive"]
version = "1.0.152"
version = "1.0.196"
[dev-dependencies.insta]
features = ["toml"]
version = "1.24.1"
version = "1.34.0"

View File

@ -1,33 +1,21 @@
[tasks.fmt]
command = "cargo"
args = ["fmt", "${@}"]
[tasks.check]
command = "cargo"
args = ["check", "${@}"]
[tasks.clippy]
command = "cargo"
args = ["clippy", "${@}"]
[tasks.test]
command = "cargo"
args = ["test", "${@}"]
[tasks.doc]
command = "cargo"
args = ["doc", "${@}"]
[tasks.build]
command = "cargo"
args = ["build", "${@}"]
# Do a full check of everything.
[tasks.complete-check]
dependencies = ["fmt", "check", "clippy", "test", "doc", "build"]
dependencies = [
"format",
"spellcheck",
"check",
"clippy",
"test",
"code-coverage",
"docs",
"build",
"audit-flow",
"outdated-flow",
]
# Run cargo-tarpaulin and output the test coverage.
[tasks.code-coverage]
workspace = false
install_crate = "cargo-tarpaulin"
command = "cargo"
args = [
"tarpaulin",
@ -36,5 +24,9 @@ args = [
"--output-dir=coverage",
"--skip-clean",
"--target-dir=target/tarpaulin",
"--workspace"
]
# Do a source code spellcheck.
[tasks.spellcheck]
clear = true
command = "typos"

128
flake.lock Normal file
View File

@ -0,0 +1,128 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1706683685,
"narHash": "sha256-FtPPshEpxH/ewBOsdKBNhlsL2MLEFv1hEnQ19f/bFsQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5ad9903c16126a7d949101687af0aa589b1d7d3d",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1706487304,
"narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "90f456026d284c22b3e3497be980b2e47d0b28ac",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1706753617,
"narHash": "sha256-ZKqTFzhFwSWFEpQTJ0uXnfJBs5Y/po9/8TK4bzssdbs=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "58be43ae223034217ea1bd58c73210644031b687",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

17
flake.nix Normal file
View File

@ -0,0 +1,17 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}

3
rustup-toolchain.toml Normal file
View File

@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["cargo", "clippy", "rustfmt", "rust-src"]

18
shell.nix Normal file
View File

@ -0,0 +1,18 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
rustup-toolchain = rust-bin.fromRustupToolchainFile ./rustup-toolchain.toml;
in
mkShell rec {
packages = [
cargo-audit
cargo-edit
cargo-make
cargo-outdated
cargo-tarpaulin
rustup-toolchain
typos
];
}

View File

@ -27,7 +27,8 @@ return the remaining contents of the string.
This function will return an [`Err`] when:
- the data doesn't have a frontmatter section,
- the frontmatter isnt' at the beginning of the data.
- the frontmatter isn't at the beginning of the data,
- the TOML fails to parse.
## Example
@ -48,7 +49,7 @@ Some **Markdown**. Or something else!
let (frontmatter, markdown) = toml_frontmatter::parse::<Frontmatter>(sample).unwrap();
```
*/
pub fn parse<'a, D: Deserialize<'a>>(data: &'a str) -> Result<(D, &'a str)> {
pub fn parse<D: for<'de> Deserialize<'de>>(data: &str) -> Result<(D, &str)> {
let start_marker = "---toml\n";
let end_marker = "\n---\n";