Compare commits
No commits in common. "main" and "1.0.0" have entirely different histories.
|
@ -1,5 +1,7 @@
|
||||||
.direnv/
|
# Generated by Cargo
|
||||||
coverage/
|
Cargo.lock
|
||||||
debug/
|
debug/
|
||||||
target/
|
target/
|
||||||
Cargo.lock
|
|
||||||
|
# Code coverage results
|
||||||
|
coverage/
|
||||||
|
|
17
Cargo.toml
17
Cargo.toml
|
@ -5,22 +5,15 @@ name = "webextension-native-messaging"
|
||||||
description = "WebExtension native messaging library for Rust."
|
description = "WebExtension native messaging library for Rust."
|
||||||
repository = "https://git.bauke.xyz/Holllo/webextension-native-messaging"
|
repository = "https://git.bauke.xyz/Holllo/webextension-native-messaging"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
version = "1.0.1"
|
version = "1.0.0"
|
||||||
authors = ["Holllo <helllo@holllo.org>"]
|
authors = ["Holllo <helllo@holllo.org>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "source/lib.rs"
|
path = "source/lib.rs"
|
||||||
|
|
||||||
[lints.clippy]
|
|
||||||
missing_docs_in_private_items = "warn"
|
|
||||||
|
|
||||||
[lints.rust]
|
|
||||||
missing_docs = "warn"
|
|
||||||
unsafe_code = "forbid"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "1.5.0"
|
byteorder = "1.4.3"
|
||||||
serde = { version = "1.0.196", features = ["derive"] }
|
serde = { version = "1.0.145", features = ["derive"] }
|
||||||
serde_json = "1.0.113"
|
serde_json = "1.0.85"
|
||||||
thiserror = "1.0.56"
|
thiserror = "1.0.37"
|
||||||
|
|
|
@ -1,21 +1,33 @@
|
||||||
# Do a full check of everything.
|
[tasks.fmt]
|
||||||
[tasks.complete-check]
|
command = "cargo"
|
||||||
dependencies = [
|
args = ["fmt", "${@}"]
|
||||||
"format",
|
|
||||||
"spellcheck",
|
[tasks.check]
|
||||||
"check",
|
command = "cargo"
|
||||||
"clippy",
|
args = ["check", "${@}"]
|
||||||
"test",
|
|
||||||
"code-coverage",
|
[tasks.clippy]
|
||||||
"docs",
|
command = "cargo"
|
||||||
"build",
|
args = ["clippy", "${@}"]
|
||||||
"audit-flow",
|
|
||||||
"outdated-flow",
|
[tasks.test]
|
||||||
]
|
command = "cargo"
|
||||||
|
args = ["test", "${@}"]
|
||||||
|
|
||||||
|
[tasks.doc]
|
||||||
|
command = "cargo"
|
||||||
|
args = ["doc", "${@}"]
|
||||||
|
|
||||||
|
[tasks.build]
|
||||||
|
command = "cargo"
|
||||||
|
args = ["build", "${@}"]
|
||||||
|
|
||||||
|
[tasks.complete-check]
|
||||||
|
dependencies = ["fmt", "check", "clippy", "test", "doc", "build"]
|
||||||
|
|
||||||
# Run cargo-tarpaulin and output the test coverage.
|
|
||||||
[tasks.code-coverage]
|
[tasks.code-coverage]
|
||||||
workspace = false
|
workspace = false
|
||||||
|
install_crate = "cargo-tarpaulin"
|
||||||
command = "cargo"
|
command = "cargo"
|
||||||
args = [
|
args = [
|
||||||
"tarpaulin",
|
"tarpaulin",
|
||||||
|
@ -23,10 +35,5 @@ args = [
|
||||||
"--out=html",
|
"--out=html",
|
||||||
"--output-dir=coverage",
|
"--output-dir=coverage",
|
||||||
"--skip-clean",
|
"--skip-clean",
|
||||||
"--target-dir=target/tarpaulin",
|
"--target-dir=target/tarpaulin"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Do a source code spellcheck.
|
|
||||||
[tasks.spellcheck]
|
|
||||||
clear = true
|
|
||||||
command = "typos"
|
|
||||||
|
|
128
flake.lock
128
flake.lock
|
@ -1,128 +0,0 @@
|
||||||
{
|
|
||||||
"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": 1706589919,
|
|
||||||
"narHash": "sha256-pNHnDITxSI3a17GOF1RUF3jBO1OiNYTRH2yV/cJG4m4=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "222c1940fafeda4dea161858ffe6ebfc853d3db5",
|
|
||||||
"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": 1706667075,
|
|
||||||
"narHash": "sha256-KBI5jcOWh9nsOFWj2SRq7vj+fPDf8Do8ceL582kFA70=",
|
|
||||||
"owner": "oxalica",
|
|
||||||
"repo": "rust-overlay",
|
|
||||||
"rev": "2c993daf3136c6955fd13bfe215d0d4faf6090f1",
|
|
||||||
"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
17
flake.nix
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
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; };
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
[toolchain]
|
|
||||||
channel = "stable"
|
|
||||||
components = ["cargo", "clippy", "rustfmt", "rust-src"]
|
|
18
shell.nix
18
shell.nix
|
@ -1,18 +0,0 @@
|
||||||
{ 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
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#![forbid(unsafe_code)]
|
||||||
|
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
||||||
|
|
||||||
//! # WebExtension Native Messaging
|
//! # WebExtension Native Messaging
|
||||||
//!
|
//!
|
||||||
//! > **WebExtension native messaging library for Rust.**
|
//! > **WebExtension native messaging library for Rust.**
|
||||||
|
@ -15,7 +18,7 @@
|
||||||
//! Then in your native executable:
|
//! Then in your native executable:
|
||||||
//!
|
//!
|
||||||
//! ```rust,no_run
|
//! ```rust,no_run
|
||||||
//! use webextension_native_messaging::read_message;
|
//! use web_ext_native_messaging::read_message;
|
||||||
//!
|
//!
|
||||||
//! let message = read_message::<String>().unwrap();
|
//! let message = read_message::<String>().unwrap();
|
||||||
//! println!("{}", message);
|
//! println!("{}", message);
|
||||||
|
@ -36,7 +39,7 @@
|
||||||
//! Then in your native executable:
|
//! Then in your native executable:
|
||||||
//!
|
//!
|
||||||
//! ```rust,no_run
|
//! ```rust,no_run
|
||||||
//! use webextension_native_messaging::write_message;
|
//! use web_ext_native_messaging::write_message;
|
||||||
//!
|
//!
|
||||||
//! let message = "Hey, there!".to_string();
|
//! let message = "Hey, there!".to_string();
|
||||||
//! write_message(&message).unwrap();
|
//! write_message(&message).unwrap();
|
||||||
|
@ -54,6 +57,9 @@ use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
|
||||||
/// All possible errors that can happen with reading or writing messages.
|
/// All possible errors that can happen with reading or writing messages.
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum MessagingError {
|
pub enum MessagingError {
|
||||||
|
/// Infallible errors.
|
||||||
|
#[error(transparent)]
|
||||||
|
Infallible(#[from] std::convert::Infallible),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
/// IO errors.
|
/// IO errors.
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
|
@ -74,7 +80,7 @@ where
|
||||||
D: for<'a> serde::Deserialize<'a>,
|
D: for<'a> serde::Deserialize<'a>,
|
||||||
R: Read,
|
R: Read,
|
||||||
{
|
{
|
||||||
let message_length = reader.read_u32::<NativeEndian>()?.into();
|
let message_length = reader.read_u32::<NativeEndian>()?.try_into()?;
|
||||||
let message_bytes = reader.take(message_length);
|
let message_bytes = reader.take(message_length);
|
||||||
|
|
||||||
serde_json::from_reader(message_bytes).map_err(Into::into)
|
serde_json::from_reader(message_bytes).map_err(Into::into)
|
||||||
|
|
Loading…
Reference in New Issue