Skip to content

Commit

Permalink
add document
Browse files Browse the repository at this point in the history
  • Loading branch information
NiwakaDev committed Aug 15, 2024
1 parent 9c35120 commit 1ee9ba2
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions book/src/bridge-module/functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,58 @@ do {

## Function Attributes

#### #[swift_bridge(init)]
Used to generate a Swift initializer.

```rust
// Rust

#[swift_bridge::bridge]
mod ffi {
extern "Rust" {
type RegularInitializer;

#[swift_bridge(init)]
fn new() -> RegularInitializer;
}

extern "Rust" {
type FailableInitializer;

#[swift_bridge(init)]
fn new() -> Option<FailableInitializer>;
}

enum SomeError {
case1,
case2
}

extern "Rust" {
type ThrowingInitializer;

#[swift_bridge(init)]
fn new() -> Result<FailableInitializer, SomeError>;
}
}
```

```swift
// Swift

let regularInitializer = RegularInitializer()

if let failableInitializer = FailableInitializer() {
// ...
}

do {
let throwingInitializer = try ThrowingInitializer()
} catch let error {
// ...
}
```

#### #[swift_bridge(Identifiable)]

Used to generate a Swift `Identifiable` protocol implementation.
Expand Down

0 comments on commit 1ee9ba2

Please sign in to comment.