docs: add readme docs
This commit is contained in:
parent
c15dabe60c
commit
5db74c86fe
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -2,15 +2,6 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
|
||||
|
||||
[[package]]
|
||||
name = "vessel"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
]
|
||||
|
@ -4,5 +4,3 @@ resolver = "2"
|
||||
|
||||
[workspace.dependencies]
|
||||
vessel = { path = "crates/vessel" }
|
||||
|
||||
anyhow = { version = "1.0.71" }
|
||||
|
51
README.md
Normal file
51
README.md
Normal file
@ -0,0 +1,51 @@
|
||||
# Vessel
|
||||
|
||||
`vessel::Vessel` is a simple, immutable value bag for Rust – inspired by Go's `context.Context`, but focused solely on storing and propagating context in a simple manner.
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- Immutable: setting a value returns a new `Vessel`.
|
||||
- Ordered: uses a `BTreeMap` internally for deterministic iteration.
|
||||
- Ergonomic: fluent API with zero dependencies (aside from the standard library).
|
||||
- Useful for threading context-like metadata (e.g., request IDs, tenant info) through application layers.
|
||||
|
||||
## 📦 Example
|
||||
|
||||
```rust
|
||||
use vessel::Vessel;
|
||||
|
||||
let vessel = Vessel::new();
|
||||
let vessel = vessel.with_value("request_id", "abc-123");
|
||||
|
||||
assert_eq!(vessel.get_value("request_id"), Some(&"abc-123".to_string()));
|
||||
````
|
||||
|
||||
## 📚 API
|
||||
|
||||
```rust
|
||||
pub fn new() -> Self;
|
||||
pub fn with_value(&self, key: &str, value: &str) -> Self;
|
||||
pub fn get_value(&self, key: &str) -> Option<&String>;
|
||||
pub fn get_values(&self) -> &BTreeMap<String, String>;
|
||||
```
|
||||
|
||||
* `with_value`: Adds a key-value pair to the vessel, returning a new instance.
|
||||
* `get_value`: Retrieves a value for a given key.
|
||||
* `get_values`: Returns all key-value pairs.
|
||||
|
||||
## 🧪 Tests
|
||||
|
||||
Run tests with:
|
||||
|
||||
```bash
|
||||
cargo test
|
||||
```
|
||||
|
||||
## 🔒 Stability
|
||||
|
||||
The crate is small and intentionally limited in scope. You can depend on its behavior being stable.
|
||||
|
||||
## 📜 License
|
||||
|
||||
MIT
|
||||
|
@ -3,7 +3,5 @@ name = "vessel"
|
||||
version = "0.1.1"
|
||||
edition = "2024"
|
||||
description = "A context propogation struct. Carries cancellation, and other useful items transparently through an application"
|
||||
readme = "../../README.md"
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user