Skip to content

Add Option<String> support for shared struct fields#354

Merged
chinedufn merged 36 commits into
chinedufn:masterfrom
Choochmeque:option-string-struct-field
Dec 8, 2025
Merged

Add Option<String> support for shared struct fields#354
chinedufn merged 36 commits into
chinedufn:masterfrom
Choochmeque:option-string-struct-field

Conversation

@Choochmeque
Copy link
Copy Markdown
Contributor

Adds support for Option fields in shared structs.

Example

// rust
#[swift_bridge::bridge]
mod ffi {
    #[swift_bridge(swift_repr = "struct")]
    struct UserProfile {
        name: String,
        bio: Option<String>,  // Now supported!
    }

    extern "Rust" {
        fn create_profile(name: String, bio: Option<String>) -> UserProfile;
    }
}
// swift
// Create with Some value
let profileWithBio = UserProfile(
    name: "Alice".intoRustString(),
    bio: "Hello world!".intoRustString()
)

// Create with None value  
let profileWithoutBio = UserProfile(
    name: "Bob".intoRustString(),
    bio: nil
)

// Access optional field
if let bio = profileWithBio.bio {
    print("Bio: \(bio.toString())")
}

Choochmeque and others added 30 commits November 30, 2025 23:10
Choochmeque and others added 6 commits December 3, 2025 12:56
…tring-struct-field

# Conflicts:
#	SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunner/Result.swift
#	crates/swift-bridge-ir/src/bridged_type/bridgeable_string.rs
#	crates/swift-bridge-ir/src/codegen/codegen_tests/result.rs
#	crates/swift-bridge-ir/src/codegen/generate_swift.rs
@Choochmeque
Copy link
Copy Markdown
Contributor Author

@chinedufn, please review when you have time.

@chinedufn chinedufn merged commit b80238f into chinedufn:master Dec 8, 2025
5 checks passed
@Choochmeque Choochmeque deleted the option-string-struct-field branch December 8, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants