laravel_casts/lib.rs
1//! Eloquent-style attribute casts for laravel-rust models.
2//!
3//! laravel-rust models have typed fields and no cast hook, so a cast is the field's type, the way
4//! `Encrypted<T>` is. `get` is `Decode` + `Serialize`, `set` is `From<&T> for Value` + `Deserialize`.
5//!
6//! ```ignore
7//! #[model]
8//! struct Invoice {
9//! id: i64,
10//! issued_at: DateCast, // DateCast::class
11//! paid_at: Option<DateTimeCast<Parsed>>, // DateTimeCast::SETPARSED
12//! period: Option<DateCast<MonthYear>>, // DateCast::SETONLYMONTHYEAR
13//! }
14//! ```
15//!
16//! A cast of your own implements [`ColumnCast`]. Casts chosen at run time, by name, are in `laravel_casts::dynamic`,
17//! behind the `dynamic` feature (off by default).
18
19#![cfg_attr(docsrs, feature(doc_cfg))]
20
21pub mod canonical;
22mod cast;
23mod config;
24mod contract;
25#[cfg(feature = "dynamic")]
26pub mod dynamic;
27mod error;
28mod kind;
29mod pattern;
30
31pub use cast::{Cast, DateCast, DateTimeCast};
32pub use config::configure;
33pub use contract::ColumnCast;
34pub use error::CastError;
35pub use kind::{Configured, DateAndTime, DateOnly, Format, Kind, MonthYear, Parsed, Storage};
36pub use php_dates::{DateConfig, DatePatterns, Error, PhpDatePattern, Result};
37
38/// What [`impl_column_cast!`] names, so that the type that uses it does not need these crates by name.
39#[doc(hidden)]
40pub mod __private {
41 pub use laravel::Result;
42 pub use laravel::db::{AnyRow, Decode, Nullable, Value};
43}