doc: update documentation to reach higher coverage

This commit is contained in:
2025-10-29 14:23:33 +01:00
parent a38b96a667
commit 6ef36e2068
10 changed files with 114 additions and 10 deletions

View File

@@ -1,6 +1,21 @@
use crate::*; use crate::*;
impl Catalog { impl Catalog {
/// Checks if the catalog contains an entity with the specified key.
///
/// # Arguments
///
/// * `k` - The key to check for.
///
/// # Returns
///
/// `Ok(true)` if an entity with the specified key exists in the catalog,
/// `Ok(false)` otherwise.
///
/// # Errors
///
/// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex
/// could not be locked.
pub fn contains_key(&self, k: &str) -> Result<bool, FailedTo> { pub fn contains_key(&self, k: &str) -> Result<bool, FailedTo> {
self.with_items(|items| Ok(items.contains_key(k))) self.with_items(|items| Ok(items.contains_key(k)))
} }

View File

@@ -1,6 +1,16 @@
use crate::*; use crate::*;
impl Catalog { impl Catalog {
/// Checks if the catalog is empty.
///
/// # Returns
///
/// `Ok(true)` if the catalog contains no entities, `Ok(false)` otherwise.
///
/// # Errors
///
/// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex
/// could not be locked.
pub fn is_empty(&self) -> Result<bool, FailedTo> { pub fn is_empty(&self) -> Result<bool, FailedTo> {
self.with_items(|items| Ok(items.is_empty())) self.with_items(|items| Ok(items.is_empty()))
} }

View File

@@ -1,6 +1,16 @@
use crate::*; use crate::*;
impl Catalog { impl Catalog {
/// Returns the number of entities in the catalog.
///
/// # Returns
///
/// The total number of entities currently held in the catalog's memory.
///
/// # Errors
///
/// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex
/// could not be locked.
pub fn len(&self) -> Result<usize, FailedTo> { pub fn len(&self) -> Result<usize, FailedTo> {
self.with_items(|items| Ok(items.len())) self.with_items(|items| Ok(items.len()))
} }

View File

@@ -1,13 +1,25 @@
use crate::*; use crate::*;
impl Catalog { impl Catalog {
/// Returns an iterator over all entities of a specific class in the in-memory catalog. /// Returns a list of all entities of a specific class from the in-memory catalog.
/// ///
/// This is a purely in-memory operation and does not interact with the database. /// This method filters the in-memory entities by the class of type `T` and
/// attempts to convert them into `T`. This is a purely in-memory operation
/// and does not interact with the database.
/// ///
/// # Returns /// # Returns
/// ///
/// An iterator that yields items of type `T` from the in-memory cache. /// A `Result` containing a `Vec` of `Result<T, FailedTo>>`. Each inner `Result`
/// represents the outcome of converting an entity to type `T`.
///
/// - `Ok(Vec<Ok(T)>)`: A vector of successfully converted entities.
/// - `Ok(Vec<Err(FailedTo::ConvertEntity)>)`: If an entity of the correct class
/// could not be converted to type `T`.
///
/// # Errors
///
/// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex
/// could not be locked.
pub fn list_by_class<T>(&self) -> Result<Vec<Result<T, FailedTo>>, FailedTo> pub fn list_by_class<T>(&self) -> Result<Vec<Result<T, FailedTo>>, FailedTo>
where where
T: EAV, T: EAV,

View File

@@ -1,14 +1,29 @@
use crate::*; use crate::*;
impl Catalog { impl Catalog {
/// Returns an iterator over all entities of a specific class and subclass /// Returns a list of all entities of a specific class and subclass from the in-memory catalog.
/// in the in-memory catalog.
/// ///
/// This is a purely in-memory operation and does not interact with the database. /// This method filters the in-memory entities by the class of type `T` and the
/// provided `subclass`, then attempts to convert them into `T`. This is a purely
/// in-memory operation and does not interact with the database.
///
/// # Arguments
///
/// * `subclass` - The subclass to filter by.
/// ///
/// # Returns /// # Returns
/// ///
/// An iterator that yields items of type `T` from the in-memory cache. /// A `Result` containing a `Vec` of `Result<T, FailedTo>>`. Each inner `Result`
/// represents the outcome of converting an entity to type `T`.
///
/// - `Ok(Vec<Ok(T)>)`: A vector of successfully converted entities.
/// - `Ok(Vec<Err(FailedTo::ConvertEntity)>)`: If an entity of the correct class
/// and subclass could not be converted to type `T`.
///
/// # Errors
///
/// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex
/// could not be locked.
pub fn list_by_class_and_subclass<T>( pub fn list_by_class_and_subclass<T>(
&self, &self,
subclass: &str, subclass: &str,

View File

@@ -1,6 +1,6 @@
//! A lightweight and intuitive Entity-Attribute-Value (EAV) database library for Rust. //! A lightweight and intuitive Entity-Attribute-Value (EAV) database library for Rust.
//! //!
//! This library provides a simple way to persist and query semi-structured data using an EAV model on top of a SQLite database. It is designed to be easy to use, with a focus on simplicity and developer experience. //! This library provides a simple and thread safe way to persist and query semi-structured data using an EAV model on top of a SQLite database. It is designed to be easy to use, with a focus on simplicity and developer experience.
//! //!
//! ## What is the Entity-Attribute-Value (EAV) Model? //! ## What is the Entity-Attribute-Value (EAV) Model?
//! //!

View File

@@ -1,12 +1,26 @@
use crate::*; use crate::*;
/// Represents an attribute of an entity, consisting of an ID and a `Value`.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct O { pub struct O {
/// The unique identifier for this attribute (e.g., "name", "price").
pub id: String, pub id: String,
/// The value of the attribute.
pub value: Value, pub value: Value,
} }
impl Attribute { impl Attribute {
/// Creates a new `Attribute` instance.
///
/// # Arguments
///
/// * `id` - The ID of the attribute.
/// * `value` - The value of the attribute, which can be any type that
/// implements `Into<Value>`.
///
/// # Returns
///
/// A new `Attribute` instance.
pub fn new(id: &str, value: impl Into<Value>) -> Self { pub fn new(id: &str, value: impl Into<Value>) -> Self {
Self { Self {
id: String::from(id), id: String::from(id),

View File

@@ -21,12 +21,22 @@ impl<'a> Filter<'a> {
conditions: Vec::new(), conditions: Vec::new(),
} }
} }
/// Adds a class condition to the filter. /// Sets the entity class to filter by.
///
/// # Arguments
///
/// * `value` - The class name to filter for. Only entities with this class
/// name will be considered.
pub fn with_class(mut self, value: &str) -> Self { pub fn with_class(mut self, value: &str) -> Self {
self.class = Some(value.to_string()); self.class = Some(value.to_string());
self self
} }
/// Adds a subclass condition to the filter. /// Sets the entity subclass to filter by.
///
/// # Arguments
///
/// * `value` - The subclass name to filter for. Only entities with this
/// subclass name will be considered.
pub fn with_subclass(mut self, value: &str) -> Self { pub fn with_subclass(mut self, value: &str) -> Self {
self.subclass = Some(value.to_string()); self.subclass = Some(value.to_string());
self self

View File

@@ -1,11 +1,20 @@
/// Represents failures that can occur specifically within the SQLite implementation.
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Hash)] #[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Hash)]
pub enum FailedTo { pub enum FailedTo {
/// Failed to begin a database transaction.
BeginTransaction, BeginTransaction,
/// Failed to build a SQL statement.
BuildStatement, BuildStatement,
/// Failed to commit a database transaction.
CommitTransaction, CommitTransaction,
/// Failed to execute a batch of SQL statements.
ExecuteBatch, ExecuteBatch,
/// Failed to execute a SQL query.
ExecuteQuery, ExecuteQuery,
/// Failed to execute a prepared SQL statement.
ExecuteStatement, ExecuteStatement,
/// Failed to open a connection to the SQLite database.
OpenConnection, OpenConnection,
/// Failed to prepare a SQL statement for execution.
PrepareStatement, PrepareStatement,
} }

View File

@@ -1,11 +1,20 @@
use crate::*; use crate::*;
/// Represents the value of an entity's attribute.
///
/// This enum can hold different data types, allowing for flexible and
/// semi-structured data storage.
#[derive(Debug, PartialEq, PartialOrd, Clone)] #[derive(Debug, PartialEq, PartialOrd, Clone)]
pub enum Value { pub enum Value {
/// A boolean value (`true` or `false`).
Bool(bool), Bool(bool),
/// A floating-point number (`f64`).
Real(f64), Real(f64),
/// A signed 64-bit integer.
SignedInt(i64), SignedInt(i64),
/// A UTF-8 encoded string.
Text(String), Text(String),
/// An unsigned 64-bit integer.
UnsignedInt(u64), UnsignedInt(u64),
} }