| Crates.io | tnuctipun |
| lib.rs | tnuctipun |
| version | 0.1.2 |
| created_at | 2025-08-05 22:24:33.865756+00 |
| updated_at | 2026-01-12 14:06:55.517098+00 |
| description | The Tnuctipun of Ringworld — ancient, subversive, ingenious — or a type-safe MongoDB builder library |
| homepage | |
| repository | https://github.com/cchantep/tnuctipun |
| max_upload_size | |
| id | 1783144 |
| size | 655,685 |
The Tnuctipun of Ringworld — ancient, subversive, ingenious — or a type-safe MongoDB builder library.
Add this to your Cargo.toml:
[dependencies]
tnuctipun = "0.1.2"
The library only requires the bson crate for MongoDB document types and provides type-safe query building capabilities.
use tnuctipun::{FieldWitnesses, MongoComparable, filters::empty, projection, updates};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, FieldWitnesses, MongoComparable)]
struct User {
pub name: String,
pub age: i32,
pub email: String,
}
// Type-safe filter building with compile-time field validation
let mut filter_builder = empty::<User>();
filter_builder.eq::<user_fields::Name, _>("John".to_string());
filter_builder.gt::<user_fields::Age, _>(18);
// Convert to MongoDB document
let filter_doc = filter_builder.and();
// Results in: { "$and": [{ "name": "John" }, { "age": { "$gt": 18 } }] }
// Type-safe projection building with method chaining
let projection_doc = projection::empty::<User>()
.includes::<user_fields::Name>()
.includes::<user_fields::Age>()
.excludes::<user_fields::Email>() // Hide sensitive data
.build();
// Results in: { "name": 1, "age": 1, "email": 0 }
// Type-safe update building with compile-time field validation
let update_doc = updates::empty::<User>()
.set::<user_fields::Name, _>("Jane".to_string())
.inc::<user_fields::Age, _>(1)
.unset::<user_fields::Email>()
.build();
// Results in: {
// "$set": { "name": "Jane" },
// "$inc": { "age": 1 },
// "$unset": { "email": "" }
// }
For information about contributing and releasing new versions, see:
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.