-
-
Notifications
You must be signed in to change notification settings - Fork 53
Specta Swift #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jamiepine
wants to merge
10
commits into
specta-rs:main
Choose a base branch
from
jamiepine:swift
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Specta Swift #405
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Added `specta-serde`, `thiserror`, and `serde` dependencies to `Cargo.toml`. - Updated `specta` dependency to include the `derive` feature. - Enhanced documentation in `lib.rs` with usage examples for exporting Rust types to Swift. - Refactored `tests` to rename `Type` enum to `TypeEnum` for clarity.
- Introduced new structs and enums including Admin, Circle, Shape, User, and UserType to enhance type representation. - Added ApiResponse and DatabaseResult enums for better API response handling. - Updated naming conventions in primitives.rs for enum case conversion. - Enhanced the Swift naming convention implementation in swift.rs to support enum case formatting.
- Changed author in Cargo.toml and updated dependencies to include `uuid` and `chrono`. - Introduced CommentsExample.swift to demonstrate multi-line comment support in generated Swift code. - Improved comment handling in primitives.rs to format multi-line documentation correctly. - Added tests for multi-line comments and support for common types, including UUID and Chrono.
…eneration - Introduced CriticalFixesDemo.swift to showcase improvements in handling Duration fields, tuple structs, multi-line documentation, and complex union types. - Updated primitives.rs to correctly convert Duration structs to TimeInterval and handle special standard library types. - Added tests for verifying the correct generation of Swift code from Rust types, ensuring no malformed syntax is produced. - Enhanced overall documentation and examples for better clarity in generated Swift output.
- Added `is_string_enum` method to determine if an enum should be serialized as a string enum based on its variants. - Updated `EnumRepr` to include a representation for string enums with optional `rename_all` attribute. - Enhanced Swift code generation to support string enums, including raw value assignments for unit variants. - Introduced tests for various string enum scenarios, ensuring correct Swift output for different naming conventions. - Improved handling of struct-like variants in enums, generating appropriate Swift structs and Codable implementations.
…on for adjacently tagged enums - Changed the conversion of Duration structs from `TimeInterval` to `RustDuration`. - Updated handling of special standard types to reflect the new Duration conversion. - Improved the generation of custom Codable implementations for adjacently tagged enums, including type keys and variant handling. - Refactored code for better readability and maintainability.
- Implemented handling for string enums with a `rename_all` attribute to support various naming conventions (snake_case, UPPERCASE, camelCase, PascalCase, kebab-case). - Added error handling to ensure string enums do not have fields. - Updated validation logic to reflect that string enums are treated as string literals, not objects.
- Added multiple example files to showcase various Rust to Swift type conversions, including basic types, advanced unions, configuration options, and special types. - Removed outdated example files such as CommentsExample.swift and CriticalFixesDemo.swift to streamline the codebase. - Updated README.md to reflect the new examples and their functionalities. - Improved documentation and organization of example files for better clarity and usability.
…on status - Updated the README to include a new section detailing support for exporting structs and enums to multiple languages, including TypeScript and Swift. - Added a table summarizing the status of various language exporters, including their features and implementation status. - Improved examples to demonstrate exporting types to multiple languages, enhancing clarity for users. - Provided a legend to explain the stability status of each language exporter.
- Updated multiple enum declarations across various Swift example files to remove the explicit Codable conformance, as it will now be handled via extensions. - Ensured that the generated Swift code maintains proper syntax and functionality while improving clarity and reducing redundancy. - Adjusted tests to verify the correct generation of enums without direct Codable conformance, confirming that extensions are used for Codable implementation instead.
what the sigma |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Specta Swift - Rust to Swift Type Exporter
What's Added
This PR introduces
specta-swift
, a new exporter for the Specta ecosystem that generates Swift code from Rust type definitions.Key Features
std::time::Duration
to a customRustDuration
helper structImplementation
.naming()
,.indent()
,.add_protocol()
UserRole
→UserRoleUserData
)Testing & Examples
Usage
Generates:
Files Added
specta-swift/
- Main crate with Swift code generationspecta-swift/src/
- Core implementation (lib.rs, swift.rs, primitives.rs, error.rs)specta-swift/examples/
- 8 comprehensive examplesspecta-swift/tests/
- 12 test filesspecta-swift/README.md
- Documentation and usage guideThis completes the Swift exporter for the Specta ecosystem, providing a robust way to share types between Rust backends and Swift/iOS applications.