Skip to content

Commit a0a87ed

Browse files
authored
docs: add Rust examples to concept pages and quickstart (#34)
Add a Rust tab to every per-SDK example block across the feature pages — ephemerals, sequence keys, secondary indexes, notifications, namespaces, key sorting, versioning, and partition keys — so Rust sits alongside Go, Java, Python, and Node.js everywhere they appear. Each Rust snippet mirrors its sibling tabs using the oxia-client fluent builder API. Also link the Rust SDK from the getting-started "Using client SDKs" list. Signed-off-by: Matteo Merli <mmerli@apache.org>
1 parent 35a83f9 commit a0a87ed

9 files changed

Lines changed: 125 additions & 11 deletions

src/content/features/ephemerals.mdx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Ephemeral records can be used to implement many system coordination tasks, such
2929

3030
When creating/modifying a record, applications can specify the "ephemeral" option:
3131

32-
<Tabs items={['Go', 'Java', 'Python', 'Node.js']}>
32+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust']}>
3333
<Tabs.Tab>
3434
```go
3535
insertedKey, res, err := client.Put(context.Background(),
@@ -53,6 +53,11 @@ When creating/modifying a record, applications can specify the "ephemeral" optio
5353
const { key, version } = await client.put('my-key', 'my-value', { ephemeral: true });
5454
```
5555
</Tabs.Tab>
56+
<Tabs.Tab>
57+
```rust
58+
let res = client.put("my-key", "my-value").ephemeral().await?;
59+
```
60+
</Tabs.Tab>
5661
</Tabs>
5762

5863

@@ -82,7 +87,7 @@ new session.
8287

8388
A client can optionally specify a client identifier that will be tied to the session.
8489

85-
<Tabs items={['Go', 'Java', 'Python', 'Node.js']}>
90+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust']}>
8691
<Tabs.Tab>
8792
```go
8893
client, err := oxia.NewClient("localhost:6648", oxia.WithIdentity("my-client-identity"))
@@ -107,6 +112,15 @@ A client can optionally specify a client identifier that will be tied to the ses
107112
});
108113
```
109114
</Tabs.Tab>
115+
<Tabs.Tab>
116+
```rust
117+
let client = OxiaClient::builder()
118+
.service_address("localhost:6648")
119+
.identity("my-client-identity")
120+
.build()
121+
.await?;
122+
```
123+
</Tabs.Tab>
110124
</Tabs>
111125

112126
The client identity is stored as part of the version object, for ephemeral records, and will

src/content/features/namespaces.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Each namespace has its own independent key-space and set of shards.
1212
When creating an Oxia client, it's possible to specify the namespace to be used. If not provided,
1313
the client will use the `default` namespace.
1414

15-
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'CLI']}>
15+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust', 'CLI']}>
1616
<Tabs.Tab>
1717
```go
1818
client, err := oxia.NewClient("localhost:6648", oxia.WithNamespace("my-namespace"))
@@ -37,6 +37,15 @@ the client will use the `default` namespace.
3737
});
3838
```
3939
</Tabs.Tab>
40+
<Tabs.Tab>
41+
```rust
42+
let client = OxiaClient::builder()
43+
.service_address("localhost:6648")
44+
.namespace("my-namespace")
45+
.build()
46+
.await?;
47+
```
48+
</Tabs.Tab>
4049
<Tabs.Tab>
4150
```shell
4251
oxia client --namespace my-namespace put my-key my-value

src/content/features/notifications.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ of failures.
1111

1212
## Subscribing to notifications
1313

14-
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'CLI']}>
14+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust', 'CLI']}>
1515
<Tabs.Tab>
1616
```go
1717
notifications, err := client.GetNotifications()
@@ -47,6 +47,14 @@ of failures.
4747
}
4848
```
4949
</Tabs.Tab>
50+
<Tabs.Tab>
51+
```rust
52+
let mut notifications = client.notifications().await?;
53+
while let Some(notification) = notifications.recv().await {
54+
println!("{notification}");
55+
}
56+
```
57+
</Tabs.Tab>
5058
<Tabs.Tab>
5159
```shell
5260
oxia client notifications

src/content/features/oxia-key-sorting.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ For example, given the following keys, the storage order would be:
3434

3535
Querying for the direct children of `/xyz/`:
3636

37-
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'CLI']}>
37+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust', 'CLI']}>
3838
<Tabs.Tab>
3939
```go
4040
keys, _ := client.List(context.Background(), "/xyz/", "/xyz//")
@@ -59,6 +59,12 @@ Querying for the direct children of `/xyz/`:
5959
// Returns: ["/xyz/A", "/xyz/B", "/xyz/C"]
6060
```
6161
</Tabs.Tab>
62+
<Tabs.Tab>
63+
```rust
64+
let keys = client.list("/xyz/", "/xyz//").await?;
65+
// Returns: ["/xyz/A", "/xyz/B", "/xyz/C"]
66+
```
67+
</Tabs.Tab>
6268
<Tabs.Tab>
6369
```shell
6470
$ oxia client list -s /xyz/ -e /xyz//

src/content/features/partition-keys.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ All operations that need to interact with co-located records should use the same
3232
The `PartitionKey` option is available on all client operations: `Put`, `Get`, `Delete`,
3333
`DeleteRange`, `List`, and `RangeScan`.
3434

35-
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'CLI']}>
35+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust', 'CLI']}>
3636
<Tabs.Tab>
3737
```go
3838
// Store related records on the same shard
@@ -95,6 +95,27 @@ The `PartitionKey` option is available on all client operations: `Put`, `Get`, `
9595
});
9696
```
9797
</Tabs.Tab>
98+
<Tabs.Tab>
99+
```rust
100+
// Store related records on the same shard
101+
client.put("/users/123/profile", "profile-data")
102+
.partition_key("/users/123")
103+
.await?;
104+
client.put("/users/123/settings", "settings-data")
105+
.partition_key("/users/123")
106+
.await?;
107+
108+
// List all records for user 123 (works because they share a partition key)
109+
let keys = client.list("/users/123/", "/users/123//")
110+
.partition_key("/users/123")
111+
.await?;
112+
113+
// Delete all records for user 123
114+
client.delete_range("/users/123/", "/users/123//")
115+
.partition_key("/users/123")
116+
.await?;
117+
```
118+
</Tabs.Tab>
98119
<Tabs.Tab>
99120
```shell
100121
$ oxia client put /users/123/profile -c --partition-key /users/123 <<< "profile-data"

src/content/features/secondary-indexes.mdx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ matching records.
3030

3131
### Writing records with secondary indexes
3232

33-
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'CLI']}>
33+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust', 'CLI']}>
3434
<Tabs.Tab>
3535
```go
3636
// Index a user record by email
@@ -63,6 +63,15 @@ matching records.
6363
);
6464
```
6565
</Tabs.Tab>
66+
<Tabs.Tab>
67+
```rust
68+
// Index a user record by email
69+
client
70+
.put("/users/123", r#"{"name":"Alice","email":"alice@example.com"}"#)
71+
.secondary_index("by-email", "alice@example.com")
72+
.await?;
73+
```
74+
</Tabs.Tab>
6675
<Tabs.Tab>
6776
```shell
6877
$ oxia client put /users/123 -d '{"name":"Alice","email":"alice@example.com"}'
@@ -74,7 +83,7 @@ matching records.
7483

7584
Use the `UseIndex` option on `Get`, `List`, or `RangeScan` to query using secondary keys.
7685

77-
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'CLI']}>
86+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust', 'CLI']}>
7887
<Tabs.Tab>
7988
```go
8089
// Lookup by secondary index
@@ -141,6 +150,20 @@ Use the `UseIndex` option on `Get`, `List`, or `RangeScan` to query using second
141150
}
142151
```
143152
</Tabs.Tab>
153+
<Tabs.Tab>
154+
```rust
155+
// Lookup by secondary index
156+
let record = client.get("alice@example.com").use_index("by-email").await?;
157+
158+
// List all keys in a secondary index range
159+
let keys = client.list("a", "b").use_index("by-email").await?;
160+
161+
// Range scan using secondary index
162+
for record in client.range_scan("a", "b").use_index("by-email").await? {
163+
println!("primary key: {}, value: {:?}", record.key, record.value);
164+
}
165+
```
166+
</Tabs.Tab>
144167
<Tabs.Tab>
145168
```shell
146169
# Get by secondary index

src/content/features/sequence-keys.mdx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ are routed to the same shard.
3030

3131
## Using sequence keys
3232

33-
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'CLI']}>
33+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust', 'CLI']}>
3434
<Tabs.Tab>
3535
```go
3636
// Write a record with a server-assigned sequence key.
@@ -72,6 +72,18 @@ are routed to the same shard.
7272
console.log('Inserted at:', key);
7373
```
7474
</Tabs.Tab>
75+
<Tabs.Tab>
76+
```rust
77+
// Write a record with a server-assigned sequence key.
78+
// The final key will be something like "/events/00000000000000000001"
79+
let res = client
80+
.put("/events/", "event-data")
81+
.partition_key("/events/")
82+
.sequence_key_deltas([1])
83+
.await?;
84+
println!("Inserted at: {}", res.key);
85+
```
86+
</Tabs.Tab>
7587
<Tabs.Tab>
7688
```shell
7789
$ oxia client put /events/ -c --partition-key /events/ --sequence-keys-deltas 1 <<< "event-data"
@@ -99,7 +111,7 @@ insertedKey, _, err := client.Put(context.Background(),
99111
Clients can subscribe to receive updates whenever new sequence keys are generated for a given
100112
prefix. This is useful for consumers that need to react to new entries.
101113

102-
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'CLI']}>
114+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust', 'CLI']}>
103115
<Tabs.Tab>
104116
```go
105117
ch, err := client.GetSequenceUpdates(context.Background(),
@@ -140,6 +152,14 @@ prefix. This is useful for consumers that need to react to new entries.
140152
}
141153
```
142154
</Tabs.Tab>
155+
<Tabs.Tab>
156+
```rust
157+
let mut updates = client.sequence_updates("/events/", "/events/").await?;
158+
while let Some(key) = updates.recv().await {
159+
println!("New sequence key: {}", key);
160+
}
161+
```
162+
</Tabs.Tab>
143163
<Tabs.Tab>
144164
```shell
145165
$ oxia client sequence-updates /events/ --partition-key /events/

src/content/features/versioning.mdx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The versioning is usually used for **Optimistic Concurrency Control (OCC)**. Ins
1515

1616
## Using Versioning
1717

18-
<Tabs items={['Go', 'Java', 'Python', 'Node.js']}>
18+
<Tabs items={['Go', 'Java', 'Python', 'Node.js', 'Rust']}>
1919
<Tabs.Tab>
2020
```go
2121
// read version
@@ -73,4 +73,16 @@ The versioning is usually used for **Optimistic Concurrency Control (OCC)**. Ins
7373
await client.put('a', 'a2', { expectedVersionId: version.versionId });
7474
```
7575
</Tabs.Tab>
76+
<Tabs.Tab>
77+
```rust
78+
// read version
79+
let record = client.get("a").await?;
80+
81+
// case-1: expect not exists
82+
client.put("a", "a2").expected_record_not_exists().await?;
83+
84+
// case-2: expect by version
85+
client.put("a", "a2").expected_version_id(record.version.version_id).await?;
86+
```
87+
</Tabs.Tab>
7688
</Tabs>

src/content/getting-started.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,6 @@ Before running anything, here are the building blocks you will encounter.
120120
1. [Go SDK](/docs/clients/go)
121121
1. [Python SDK](/docs/clients/python)
122122
1. [Node.js SDK](/docs/clients/node)
123+
1. [Rust SDK](/docs/clients/rust)
123124

124125
</Steps>

0 commit comments

Comments
 (0)