Skip to main content

miniextendr_api/
prelude.rs

1//! Convenience re-exports for common miniextendr items.
2//!
3//! A single `use miniextendr_api::prelude::*;` brings into scope the most
4//! commonly used macros, traits, types, and helpers so user crates can avoid
5//! a long list of individual imports.
6//!
7//! ## Optional feature types
8//!
9//! When a Cargo feature is enabled (e.g., `uuid`, `regex`, `ndarray`), the
10//! prelude includes both the miniextendr adapter types **and** a re-export of
11//! the upstream dependency crate itself. This means you do **not** need to add
12//! optional crates as direct dependencies in your `Cargo.toml` — enabling the
13//! feature on `miniextendr-api` is enough.
14//!
15//! ```toml
16//! [dependencies]
17//! miniextendr-api = { version = "0.1", features = ["uuid", "ndarray"] }
18//! # No need for: uuid = "1", ndarray = "0.16"
19//! ```
20//!
21//! Access the upstream crate via the prelude:
22//!
23//! ```ignore
24//! use miniextendr_api::prelude::*;
25//!
26//! // Uuid is re-exported from the uuid crate
27//! let id = Uuid::new_v4();
28//!
29//! // The full crate is also available for advanced usage
30//! let parsed = uuid::Uuid::parse_str("...").unwrap();
31//! ```
32//!
33//! # Example
34//!
35//! ```ignore
36//! use miniextendr_api::prelude::*;
37//!
38//! #[miniextendr]
39//! fn add(a: i32, b: i32) -> i32 {
40//!     a + b
41//! }
42//! ```
43
44// region: Proc-macro re-exports
45pub use crate::{
46    // Derive macros
47    Altrep,
48    AltrepComplex,
49    AltrepInteger,
50    AltrepList,
51    AltrepLogical,
52    AltrepRaw,
53    AltrepReal,
54    AltrepString,
55    ExternalPtr,
56    MatchArg,
57    RFactor,
58    list,
59    miniextendr,
60    typed_dataframe,
61    typed_list,
62};
63// endregion
64
65// region: Core traits
66pub use crate::altrep::RegisterAltrep;
67// Round out the ALTREP surface so it matches the DataFrame/serde prelude precedent.
68pub use crate::{
69    AltComplexData, AltIntegerData, AltListData, AltLogicalData, AltRawData, AltRealData,
70    AltStringData, AltrepExtract, AltrepLen, Coerce, IntoR, IntoRAltrep, TryCoerce, TryFromSexp,
71};
72// endregion
73
74// region: Types
75pub use crate::{
76    IntoList, Lazy, List, ListBuilder, ListMut, Missing, NamedVector, OwnedProtect, ProtectScope,
77    Protected, ProtectedStrVec, RCow, StrVec, StrVecBuilder,
78};
79// endregion
80
81// region: DataFrame family
82//
83// The row/group-level data-frame surface: the owned type, its error, the
84// conversion trait pair, and the `#[derive(DataFrameRow)]` macro. Group-level
85// items (`GroupedDataFrame`, `GroupKey`, `group_rows`) stay at the crate root
86// — `df.group_by(..)` returns them without the caller naming the types.
87pub use crate::{
88    BuiltDataFrame, ColumnarFrame, DataFrame, DataFrameError, DataFrameRow, FromDataFrame,
89    IntoDataFrame, IntoDataFrameSplit,
90};
91// endregion
92
93// region: Extension-trait `.wrap_*()` verbs
94//
95// The `As*Ext` family is blanket-impl'd over the `Into*` traits and provides the
96// method-style return verbs (`value.wrap_data_frame()`, `.wrap_list()`,
97// `.wrap_external_ptr()`, …) that a `#[derive(DataFrameRow)]` / `#[derive(List)]`
98// / … type gets for free. They were already re-exported at the crate root but
99// not from the prelude, leaving `IntoDataFrame` / `FromDataFrame` (above) exposed
100// while their `.wrap_*()` companions were not — this closes that gap so the
101// canonical surface is fully discoverable via `use miniextendr_api::prelude::*`.
102#[cfg(feature = "vctrs")]
103pub use crate::AsVctrsExt;
104pub use crate::{
105    AsDataFrameExt, AsExternalPtrExt, AsListExt, AsNamedListExt, AsNamedVectorExt, AsRNativeExt,
106};
107// endregion
108
109// region: Worker thread
110pub use crate::{Sendable, with_r_thread};
111// endregion
112
113// region: Error handling and console output
114pub use crate::{r_print, r_println, r_warning};
115// endregion
116
117// region: R evaluation
118//
119// `r!` / `r_str!` evaluate R source from Rust; `r_eval_str` is the underlying
120// protect-safe parse + eval function they expand to.
121pub use crate::expression::r_eval_str;
122pub use crate::{r, r_str};
123// endregion
124
125// region: Safe R-value surface
126//
127// `SEXP` is the central newtype; `SexpExt` is the ergonomic extension trait
128// that provides the safe higher-level methods. The type vocabulary
129// (`SEXPTYPE`, `R_xlen_t`, `RLogical`, `Rboolean`, `Rcomplex`, `RNativeType`,
130// …) is **not** re-exported here — those are lower-level types that user
131// code should reach for explicitly at the crate root
132// (`miniextendr_api::SEXPTYPE`, `miniextendr_api::R_xlen_t`, …) when
133// genuinely needed (rare; common in tests and macro-generated code).
134// `miniextendr_api::sys::*` is the raw-FFI escape hatch — `extern
135// "C-unwind"` symbols and the ALTREP method type aliases only. The prelude
136// is for the abstraction surface, not the raw R C API.
137pub use crate::{SEXP, SexpExt};
138// endregion
139
140// region: Optional feature re-exports
141
142// --- either ---
143#[cfg(feature = "either")]
144pub use crate::{Either, Left, Right};
145
146#[cfg(feature = "either")]
147pub use either;
148
149// --- uuid ---
150#[cfg(feature = "uuid")]
151pub use crate::{RUuidOps, Uuid};
152#[cfg(feature = "uuid")]
153pub use uuid;
154
155// --- regex ---
156#[cfg(feature = "regex")]
157pub use crate::{CaptureGroups, RRegexOps, Regex};
158#[cfg(feature = "regex")]
159pub use regex;
160
161// --- url ---
162#[cfg(feature = "url")]
163pub use crate::{RUrlOps, Url};
164#[cfg(feature = "url")]
165pub use url;
166
167// --- time ---
168#[cfg(feature = "time")]
169pub use crate::{Date, Duration, OffsetDateTime, RDuration};
170#[cfg(feature = "time")]
171pub use time;
172
173// --- ordered-float ---
174#[cfg(feature = "ordered-float")]
175pub use crate::{OrderedFloat, ROrderedFloatOps};
176#[cfg(feature = "ordered-float")]
177pub use ordered_float;
178
179// --- num-bigint ---
180#[cfg(feature = "num-bigint")]
181pub use crate::{BigInt, BigUint, RBigIntOps, RBigUintOps};
182#[cfg(feature = "num-bigint")]
183pub use num_bigint;
184
185// --- rust_decimal ---
186#[cfg(feature = "rust_decimal")]
187pub use crate::{Decimal, RDecimalOps};
188#[cfg(feature = "rust_decimal")]
189pub use rust_decimal;
190
191// --- num-complex ---
192#[cfg(feature = "num-complex")]
193pub use crate::{Complex, RComplexOps};
194#[cfg(feature = "num-complex")]
195pub use num_complex;
196
197// --- num-traits ---
198#[cfg(feature = "num-traits")]
199pub use crate::{RFloat, RNum, RSigned};
200#[cfg(feature = "num-traits")]
201pub use num_traits;
202
203// --- ndarray ---
204#[cfg(feature = "ndarray")]
205pub use crate::{
206    Array1, Array2, Array3, Array4, Array5, Array6, ArrayD, ArrayView1, ArrayView2, ArrayViewD,
207    ArrayViewMut1, ArrayViewMut2, ArrayViewMutD, RNdArrayOps,
208};
209#[cfg(feature = "ndarray")]
210pub use ndarray;
211
212// --- nalgebra ---
213#[cfg(feature = "nalgebra")]
214pub use crate::{DMatrix, DVector, RMatrixOps, RVectorOps, SMatrix, SVector};
215#[cfg(feature = "nalgebra")]
216pub use nalgebra;
217
218// --- indexmap ---
219#[cfg(feature = "indexmap")]
220pub use crate::{IndexMap, RIndexMapOps};
221#[cfg(feature = "indexmap")]
222pub use indexmap;
223
224// --- rayon ---
225#[cfg(feature = "rayon")]
226pub use crate::{RParallelExtend, RParallelIterator};
227#[cfg(feature = "rayon")]
228pub use rayon;
229
230// --- rand ---
231#[cfg(feature = "rand")]
232pub use crate::{RDistributionOps, RDistributions, RRng, RRngOps};
233#[cfg(feature = "rand")]
234pub use rand;
235#[cfg(feature = "rand_distr")]
236pub use rand_distr;
237
238// --- serde (direct R serialization) ---
239#[cfg(feature = "serde")]
240pub use crate::serde::{AsSerialize, RDeserializeNative, RSerializeNative};
241#[cfg(feature = "serde")]
242pub use serde;
243
244// --- serde_json ---
245#[cfg(feature = "serde_json")]
246pub use crate::{JsonOptions, JsonValue, RDeserialize, RSerialize};
247#[cfg(feature = "serde_json")]
248pub use serde_json;
249
250// --- toml ---
251#[cfg(feature = "toml")]
252pub use crate::{TomlValue, toml_from_str, toml_to_string};
253#[cfg(feature = "toml")]
254pub use toml;
255
256// --- bytes ---
257#[cfg(feature = "bytes")]
258pub use crate::{Bytes, BytesMut, RBuf, RBufMut};
259#[cfg(feature = "bytes")]
260pub use bytes;
261
262// --- aho-corasick ---
263#[cfg(feature = "aho-corasick")]
264pub use crate::{AhoCorasick, aho_compile};
265#[cfg(feature = "aho-corasick")]
266pub use aho_corasick;
267
268// --- bitflags ---
269#[cfg(feature = "bitflags")]
270pub use crate::RFlags;
271#[cfg(feature = "bitflags")]
272pub use bitflags;
273
274// --- bitvec ---
275#[cfg(feature = "bitvec")]
276pub use crate::RBitVec;
277#[cfg(feature = "bitvec")]
278pub use bitvec;
279
280// --- borsh ---
281#[cfg(feature = "borsh")]
282pub use crate::{Borsh, RBorshOps};
283#[cfg(feature = "borsh")]
284pub use borsh;
285
286// --- raw_conversions ---
287#[cfg(feature = "raw_conversions")]
288pub use crate::{Pod, Raw, RawSlice, Zeroable};
289#[cfg(feature = "raw_conversions")]
290pub use bytemuck;
291
292// --- sha2 ---
293#[cfg(feature = "sha2")]
294pub use crate::{sha256_bytes, sha256_str, sha512_bytes, sha512_str};
295#[cfg(feature = "sha2")]
296pub use sha2;
297
298// --- tabled ---
299#[cfg(feature = "tabled")]
300pub use crate::{Table, Tabled, table_to_string};
301#[cfg(feature = "tabled")]
302pub use tabled;
303
304// --- tinyvec ---
305#[cfg(feature = "tinyvec")]
306pub use crate::{ArrayVec, TinyVec};
307#[cfg(feature = "tinyvec")]
308pub use tinyvec;
309
310// --- indicatif ---
311#[cfg(feature = "indicatif")]
312pub use crate::progress;
313#[cfg(feature = "indicatif")]
314pub use indicatif;
315
316// --- vctrs ---
317#[cfg(feature = "vctrs")]
318pub use crate::{IntoVctrs, VctrsClass};
319// endregion