Skip to content

Commit 0de0dc8

Browse files
committed
More README updates
1 parent ef2029a commit 0de0dc8

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
> `swift-bridge` facilitates Rust and Swift interop.
44
5-
`swift-bridge` is a library that lets you pass and share high-level types such as `Option<T>`, `String`,
6-
`Structs` and `Classes` between Rust and Swift.
5+
`swift-bridge` is a library that helps you pass and share high-level types such as `Option<T>`, `String`,
6+
`struct` and `Class` between Rust and Swift.
77

8-
It also lets you bridge higher level language features between Rust and Swift, such as async functions and generics.
8+
It also helps you bridge higher level language features between Rust and Swift, such as async functions and generics.
99

1010
## Installation
1111

@@ -36,52 +36,50 @@ Here's a quick peek at how you might describe an FFI boundary between Swift and
3636

3737
<!-- ANCHOR: bridge-module-example -->
3838
```rust
39-
// Use the `swift_bridge::bridge` macro to declare a bridge module that
40-
// `swift-bridge-build` will parse at build time in order to generate
41-
// the necessary Swift and C FFI glue code.
39+
// We use the `swift_bridge::bridge` macro to declare a bridge module.
40+
// Then at build time the `swift-bridge-build` crate is used to generate
41+
// the corresponding Swift and C FFI glue code.
4242
#[swift_bridge::bridge]
4343
mod ffi {
44-
// Create shared structs where both Rust and Swift can directly access the fields.
44+
// Create "transparent" structs where both Rust and Swift can directly access the fields.
4545
struct AppConfig {
4646
file_manager: CustomFileManager,
4747
}
4848

49-
// Shared enums are also supported
49+
// Transparent enums are also supported.
5050
enum UserLookup {
5151
ById(UserId),
5252
ByName(String),
5353
}
5454

55-
// Export Rust types, functions and methods for Swift to use.
55+
// Export opaque Rust types, functions and methods for Swift to use.
5656
extern "Rust" {
5757
type RustApp;
5858

5959
#[swift_bridge(init)]
60-
fn new(config: AppConfig);
60+
fn new(config: AppConfig) -> RustApp;
6161

62-
fn insert_user(&mut self, user_id: UserId, user: User);
6362
fn get_user(&self, lookup: UserLookup) -> Option<&User>;
6463
}
6564

6665
extern "Rust" {
6766
type User;
67+
type MessageBoard;
6868

69-
#[swift_bridge(Copy(4))]
70-
type UserId;
71-
72-
#[swift_bridge(init)]
73-
fn new(user_id: UserId, name: String, email: Option<String>) -> User;
69+
#[swift_bridge(get(&nickname))]
70+
fn informal_name(self: &User) -> &str;
7471
}
7572

76-
// Import Swift classes and functions for Rust to use.
73+
// Import opaque Swift classes and functions for Rust to use.
7774
extern "Swift" {
7875
type CustomFileManager;
7976
fn save_file(&self, name: &str, contents: &[u8]);
8077
}
8178
}
8279

83-
#[derive(Copy)]
84-
struct UserId(u32);
80+
struct User {
81+
nickname: String
82+
}
8583
```
8684
<!-- ANCHOR_END: bridge-module-example -->
8785

0 commit comments

Comments
 (0)