Skip to main content

toasty_core/
lib.rs

1//! Core types and abstractions for the Toasty ORM.
2//!
3//! This crate provides the shared foundation used by all Toasty components:
4//!
5//! - [`Schema`] -- the combined app-level, database-level, and mapping schema
6//! - [`stmt`] -- the statement AST used to represent queries and mutations
7//! - [`driver`] -- the trait interface that database drivers implement
8//! - [`Error`] / [`Result`] -- unified error handling
9//!
10//! Most users interact with the higher-level `toasty` crate. This crate is
11//! relevant when writing database drivers or working with schema internals.
12//!
13//! # Examples
14//!
15//! ```ignore
16//! use toasty_core::{Schema, Error, Result};
17//!
18//! fn check_schema(schema: &Schema) -> Result<()> {
19//!     println!("models: {}", schema.app.models.len());
20//!     Ok(())
21//! }
22//! ```
23
24#![warn(missing_docs)]
25
26#[macro_use]
27mod macros;
28
29/// Database driver traits and capability descriptions.
30pub mod driver;
31pub use driver::Connection;
32
33mod error;
34/// The error type returned by Toasty operations.
35pub use error::Error;
36
37/// Schema migration metadata shared by Toasty runtime and macros.
38#[cfg(feature = "migration")]
39pub mod migration;
40
41/// Schema definitions spanning the app layer, database layer, and the mapping
42/// between them.
43pub mod schema;
44pub use schema::Schema;
45
46/// Statement AST types for representing queries, inserts, updates, and deletes.
47pub mod stmt;
48
49/// A `Result` type alias that uses Toasty's [`Error`] type.
50///
51/// This is the standard return type for fallible operations throughout
52/// `toasty-core`.
53///
54/// # Examples
55///
56/// ```ignore
57/// use toasty_core::Result;
58///
59/// fn validate_name(name: &str) -> Result<()> {
60///     if name.is_empty() {
61///         return Err(toasty_core::Error::invalid_schema("name must not be empty"));
62///     }
63///     Ok(())
64/// }
65/// ```
66pub type Result<T, E = Error> = core::result::Result<T, E>;