summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-30 22:12:49 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-30 22:12:49 +0000
commitabf784a784c6e9282dbfbe269670da0284556a7d (patch)
treefde86bc0c197e0e57a6061af84e6320e9db1f718
parent13a6ab5d21888428a13d57fa1ce6f6fdd84ddf14 (diff)
downloadgentoo-utils-abf784a784c6e9282dbfbe269670da0284556a7d.tar.gz
add some docs
-rwxr-xr-xcheck.sh2
-rw-r--r--check_commands.txt3
-rw-r--r--meson.build10
-rw-r--r--meson.options3
-rw-r--r--src/lib.rs66
5 files changed, 81 insertions, 3 deletions
diff --git a/check.sh b/check.sh
index a1d6d78..abaa5b2 100755
--- a/check.sh
+++ b/check.sh
@@ -12,7 +12,7 @@ if [[ -n ${ldd} ]]; then
fi
if [[ ! -d build ]]; then
- meson setup -Dfuzz=enabled -Dtests=enabled -Dbuildtype=debugoptimized build || exit $?
+ meson setup -Dfuzz=enabled -Dtests=enabled -Dbuildtype=debugoptimized -Ddocs=enabled build || exit $?
fi
meson compile -C build || exit $?
diff --git a/check_commands.txt b/check_commands.txt
index 1d1b424..96d8fe6 100644
--- a/check_commands.txt
+++ b/check_commands.txt
@@ -1,4 +1,5 @@
/usr/bin/meson format --recursive --check-only
rustfmt --edition 2024 --check $(find src -type f -name '*.rs')
+ninja rustdoc -C build
ninja clippy -C build
-meson test unittests '*repo*' '*porthole*' -C build
+meson test unittests doctests '*repo*' '*porthole*' -C build
diff --git a/meson.build b/meson.build
index 9e353d5..8e712dd 100644
--- a/meson.build
+++ b/meson.build
@@ -28,3 +28,13 @@ endif
if get_option('fuzz').enabled()
subdir('fuzz')
endif
+
+if get_option('docs').enabled()
+ rust.doctest(
+ 'doctests',
+ gentoo_utils,
+ dependencies: [mon, get, itertools],
+ link_with: [thiserror],
+ args: ['--nocapture'],
+ )
+endif
diff --git a/meson.options b/meson.options
index cf0463a..bc9c8a8 100644
--- a/meson.options
+++ b/meson.options
@@ -1,2 +1,3 @@
option('fuzz', type: 'feature', value: 'disabled')
-option('tests', type: 'feature', value: 'disabled') \ No newline at end of file
+option('tests', type: 'feature', value: 'disabled')
+option('docs', type: 'feature', value: 'disabled') \ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index beeae1e..7cef9a8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,17 @@
+//! Gentoo and PMS related utils.
+//!
+//! Currently implements:
+//! - parsers for atoms and DEPEND expressions
+//! - strongly typed representations of atoms, versions, etc
+//! - version comparison and equality impls
+//! - iterator over repos categories and ebuilds
+//!
+//! Planned features
+//! - profile evaluation
+//! - vdb reader
+//! - sourcing ebuilds with bash
+//!
+
#![deny(clippy::pedantic, unused_imports)]
#![allow(
dead_code,
@@ -15,6 +29,58 @@ pub trait Parseable<'a, I: Input + 'a> {
fn parser() -> Self::Parser;
}
+/// Strongly typed atom and cpv representations.
+///
+/// Create atoms from parsers:
+/// ```
+/// use gentoo_utils::{Parseable, atom::Atom};
+/// use mon::{Parser, input::InputIter};
+///
+/// let it = InputIter::new("=app-editors/emacs-31.0-r1");
+/// let emacs = Atom::parser().parse_finished(it).unwrap();
+///
+/// assert_eq!(emacs.to_string(), "=app-editors/emacs-31.0-r1");
+/// ````
+///
+/// Compare versions:
+/// ```
+/// use gentoo_utils::{Parseable, atom::Cpv};
+/// use mon::{Parser, input::InputIter};
+///
+/// let a = Cpv::parser()
+/// .parse_finished(InputIter::new("foo/bar-1.0"))
+/// .unwrap();
+///
+/// let b = Cpv::parser()
+/// .parse_finished(InputIter::new("foo/bar-2.0"))
+/// .unwrap();
+///
+/// assert!(a < b);
+/// ```
pub mod atom;
+
+/// Access to repos and ebuilds.
+///
+/// ```
+/// use gentoo_utils::repo::Repo;
+///
+/// let repo = Repo::new("/var/db/repos/gentoo");
+///
+/// for result in repo.categories().expect("failed to read categories") {
+/// let category = result.expect("failed to read category");
+///
+/// for result in category.ebuilds().expect("failed to read ebuilds") {
+/// let ebuild = result.expect("failed to read ebuild");
+///
+/// println!(
+/// "{}-{}: {}",
+/// ebuild.name(),
+/// ebuild.version(),
+/// ebuild.description().clone().unwrap_or("no description available".to_string())
+/// );
+/// }
+/// }
+///
+/// ```
pub mod repo;
pub mod useflag;