asimov_patterns/lib.rs
1// This is free and unencumbered software released into the public domain.
2
3//! Execution traits and configuration values for ASIMOV program patterns.
4//!
5//! A *pattern* describes a program's role and logical input/output contract:
6//! for example, a [`Reader`] imports a document into RDF, an [`Adapter`] queries
7//! a dataset with SPARQL, and a [`Writer`] exports RDF to another representation.
8//! The [Program Patterns Specification][pps] defines their command-line
9//! interfaces and the requirements for hosts that invoke them.
10//!
11//! This crate provides two building blocks:
12//!
13//! - [`Execute<T>`] is the asynchronous operation shared by all pattern traits,
14//! with an implementation-specific associated [`Error`](Execute::Error) type.
15//! - [`programs`] contains role-specific marker traits and owned option values
16//! such as [`ReaderOptions`], with builders for configuring invocations.
17//! Optional native support is described separately by capability metadata such
18//! as [`ListerCapabilities`], using [`OptionSupport`] to distinguish unknown
19//! support from an explicit declaration. Callers supply this metadata; this
20//! crate does not discover capabilities or read module manifests.
21//!
22//! Executable lookup, process management, stream transport, and result decoding
23//! belong to implementations. The companion [`asimov-runner`][runner] crate
24//! supplies Tokio-backed process wrappers and re-exports these option types.
25//! [`asimov-remote`][remote] supplies HTTP-backed fetch/list operations using the
26//! same traits. Shared raw JSONL payloads live in [`asimov-flow`][flow]; each
27//! executor chooses its own error type. These role traits are the execution
28//! boundary for reusable components, while explicit typed port schemas and
29//! generalized graph scheduling are still evolving.
30//! Consult its documentation for supported output modes and current limitations;
31//! implementing a marker trait does not by itself establish PPS conformance.
32//!
33//! # Configuring an operation
34//!
35//! ```
36//! use asimov_patterns::{ListerOptions, OutputFormat};
37//!
38//! let options: ListerOptions = ListerOptions::builder()
39//! .limit(25)
40//! .output("jsonl")
41//! .build();
42//!
43//! assert_eq!(options.limit, Some(25));
44//! assert_eq!(options.output, Some(OutputFormat::Jsonl));
45//! assert!(options.other.is_empty());
46//! ```
47//!
48//! Building options neither executes a program nor validates its capabilities.
49//! Unset fields remain `None`: `asimov-runner` omits the corresponding flags and
50//! lets the program apply its specified defaults. In particular, `input` and
51//! `output` fields name **formats**, not files or stream endpoints.
52//!
53//! # Payloads and representations
54//!
55//! Pattern traits describe semantics without fixing a Rust representation for
56//! the result. Their type parameter `T` can represent serialized bytes, parsed
57//! data, a fallible stream, or another documented result representation; it is
58//! not the number of RDF statements or logical results. [`Indexer`] fixes its result to `()`
59//! because indexing has no payload output.
60//! A streaming implementation can return successful startup before execution
61//! finishes; its result must expose subsequent failures. See [`programs`] for
62//! links to concrete transport, completion, and result semantics.
63//!
64//! The options do not parse, validate, or transcode RDF. The spec's default
65//! `jsonl` token requires a shared [RDF mapping profile][rdf-mapping]; it does
66//! not imply JSON-LD or a particular JSON object shape. Composing two graph
67//! patterns requires agreement on both serialization and profile.
68//!
69//! # Features
70//!
71//! The crate declares `no_std` and uses `alloc` for strings, collections, and
72//! boxed futures. Cache and timing argument formatting requires `std` or `clap`
73//! and uses `humantime`, which requires the standard library. The `clap` feature
74//! also requires the standard library and enables shared argument parsing,
75//! including human-readable cache ages and execution deadlines.
76//! The `serde` feature serializes fetch/list and shared options for the remote
77//! HTTP protocol: durations are human-readable strings, sort keys and formats
78//! use CLI spellings, and unset fields are omitted. Duration parsing uses
79//! `humantime` and requires the standard library.
80//! The default features are `all` and `std`; `std` enables standard-library
81//! support in dependencies. `all`, `tracing`, and `unstable` currently enable no
82//! additional behavior in this crate. Disabling `std` here does not guarantee
83//! that the dependency graph is usable on a target without a standard library.
84//!
85//! [pps]: https://asimov-specs.github.io/program-patterns/
86//! [runner]: https://docs.rs/asimov-runner
87//! [remote]: https://docs.rs/asimov-remote
88//! [flow]: https://docs.rs/asimov-flow
89//! [rdf-mapping]: https://asimov-specs.github.io/program-patterns/#rdf-mapping
90
91#![no_std]
92#![forbid(unsafe_code)]
93#![cfg_attr(docsrs, feature(doc_cfg))]
94
95extern crate alloc;
96
97#[cfg(any(feature = "std", feature = "clap"))]
98extern crate std;
99
100pub mod execute;
101pub use execute::*;
102
103pub mod capabilities;
104pub use capabilities::*;
105
106pub mod options;
107pub use options::*;
108
109pub mod output_format;
110pub use output_format::*;
111
112pub mod programs;
113pub use programs::*;
114
115#[cfg(feature = "serde")]
116mod serialization;