1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//! Linear Types Module - Resource-safe programming with single-use guarantees
//!
//! > *"Semel et simul"*
//! > — Once and together. (Medieval Latin)
//!
//! This module provides linear type abstractions inspired by Idris 2's Quantitative
//! Type Theory (QTT) and Haskell's Linear Types extension. Linear types enforce
//! that values are used exactly once, enabling compile-time resource safety.
//!
//! # Overview
//!
//! Linear types provide:
//!
//! - [`Linearis`] - A wrapper enforcing single-use semantics
//! - [`Unrestricted`] - Explicitly non-linear (can be used multiple times)
//! - [`FunctorLinearis`] - Functor operations preserving linearity
//! - [`MonadLinearis`] - Monadic operations for linear computations
//! - [`Res`] - Resource management with guaranteed cleanup
//!
//! # Scholastic Naming
//!
//! | English | Latin | Etymology |
//! |---------|-------|-----------:|
//! | Linear | Linearis | *linearis* = of a line, linear |
//! | Once | Semel | *semel* = once, a single time |
//! | Unrestricted | Liber | *liber* = free, unrestricted |
//! | Resource | Res | *res* = thing, matter, resource |
//! | Consume | Consumere | *consumere* = to use up |
//! | Duplicate | Duplicare | *duplicare* = to double |
//!
//! # Multiplicity System
//!
//! Following Idris 2's QTT, we distinguish three multiplicities:
//!
//! - **0 (Erased)**: Value exists only at compile time, erased at runtime
//! - **1 (Linear)**: Value must be used exactly once
//! - **ω (Unrestricted)**: Value can be used any number of times
//!
//! Rust's ownership system naturally enforces linearity through move semantics.
//! This module provides explicit types and traits to make linear programming
//! more ergonomic and self-documenting.
//!
//! # Example
//!
//! ```rust
//! use ordofp_core::linear::Linearis;
//!
//! // A resource that must be used exactly once
//! let file = Linearis::new(String::from("data.txt"));
//!
//! // Use the value linearly - this consumes it
//! let contents = file.consume_with(|name| format!("contents of {name}"));
//! assert_eq!(contents, "contents of data.txt");
//!
//! // file cannot be used again - it has been consumed!
//! ```
//!
//! # Feature Flags
//!
//! This module is available with the `linear` feature:
//!
//! ```toml
//! [dependencies]
//! ordofp = { version = "3.0", features = ["linear"] }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use bracket_safe;
pub use ;
pub use ;
/// Marker trait for types that can be used linearly.
///
/// Types implementing this trait guarantee that they have meaningful
/// single-use semantics. This is primarily a documentation trait,
/// as Rust's ownership system already enforces move semantics.
///
/// # Example
///
/// ```rust
/// use ordofp_core::linear::UsusLinearis;
///
/// struct FileHandle { /* ... */ }
///
/// impl UsusLinearis for FileHandle {
/// fn use_once(self) {
/// // Close the file handle
/// }
/// }
/// ```
/// Marker trait for types that explicitly support duplication.
///
/// This is the opposite of linear types - types implementing `Duplicabilis`
/// can be freely copied or cloned. This trait exists to make the distinction
/// between linear and non-linear types explicit in APIs.
///
/// # Note
///
/// This is automatically implemented for types that implement `Clone`.
/// Marker trait for types that can be safely discarded without use.
///
/// Some linear types require explicit consumption, while others can be
/// safely dropped. This trait marks types that can be discarded.
///
/// # Note
///
/// In Rust, all types can technically be dropped, but this trait
/// documents intentional discard capability.