Skip to main content

specta_swift/
lib.rs

1//! [Swift](https://www.swift.org) language exporter for [Specta](specta).
2//!
3//! This crate provides functionality to export Rust types to Swift code.
4//!
5//! # Usage
6//!
7//! Add `specta`, `specta-serde`, and `specta-swift` to your project:
8//!
9//! ```bash
10//! cargo add specta@2.0.0-rc.25 --features derive,collect
11//! cargo add specta-serde@0.0.12
12//! cargo add specta-swift@0.0.3
13//! ```
14//!
15//! Next copy the following into your `main.rs` file:
16//!
17//! ```rust
18//! use specta::{Type, Types};
19//! use specta_swift::Swift;
20//!
21//! #[derive(Type)]
22//! pub struct MyType {
23//!     pub field: MyOtherType,
24//! }
25//!
26//! #[derive(Type)]
27//! pub struct MyOtherType {
28//!     pub other_field: String,
29//! }
30//!
31//! let types = Types::default()
32//!     // We don't need to specify `MyOtherType` because it's referenced by `MyType`
33//!     .register::<MyType>();
34//!
35//! Swift::default()
36//!     .export_to("./Types.swift", &types, specta_serde::Format)
37//!     .unwrap();
38//! ```
39//!
40//! Now you're set up with Specta Swift!
41//!
42//! If you get tired of listing all your types, checkout [`specta::collect`].
43#![cfg_attr(docsrs, feature(doc_cfg))]
44#![doc(
45    html_logo_url = "https://github.com/specta-rs/specta/raw/main/.github/logo-128.png",
46    html_favicon_url = "https://github.com/specta-rs/specta/raw/main/.github/logo-128.png"
47)]
48
49mod error;
50mod primitives;
51mod swift;
52
53pub use error::Error;
54pub use swift::{GenericStyle, IndentStyle, NamingConvention, OptionalStyle, Swift};