Skip to content

Commit cdd5a33

Browse files
committed
Added Rust Client snippets
1 parent 0753e10 commit cdd5a33

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ We're open for any contribution. If you noticed some inconsistency, missing piec
1515
GRPC Clients:
1616
- C# - [see more](https://github.com/EventStore/EventStore-Client-Dotnet/tree/master/samples)
1717
- NodeJS - [see more](./samples/grpc/nodejs/)
18-
- Java# - [see more](https://github.com/EventStore/EventStoreDB-Client-Java/tree/trunk/db-client-java/src/test/java/com/eventstore/dbclient/samples)
18+
- Java - [see more](https://github.com/EventStore/EventStoreDB-Client-Java/tree/trunk/db-client-java/src/test/java/com/eventstore/dbclient/samples)
19+
- Rust - [see more](https://github.com/EventStore/EventStoreDB-Client-Rust/tree/master/examples)
1920

2021
## Local development
2122

docs/.vuepress/enhanceApp.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Prism from "vue-prism-component";
88
import "prismjs/components/prism-csharp";
99
import "prismjs/components/prism-java";
1010
import "prismjs/components/prism-yaml";
11+
import "prismjs/components/prism-rust";
1112
import "prismjs/components/prism-bash";
1213
import * as gtm from "./gtm/inject";
1314
import Vuex from "vuex";

docs/clients/grpc/appending-events/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ The simplest way to append an event to EventStoreDB is to create an `EventData`
1919

2020
<<< @/docs/clients/java/generated/0.7/samples/appending_events/AppendingEvents.java#append-to-stream
2121
</xode-block>
22+
<xode-block title="Rust">
23+
24+
<<< @/docs/clients/rust/generated/0.9.9/samples/appending_events.rs#append-to-stream
25+
</xode-block>
2226
</xode-group>
2327

2428
As you can see `AppendToStream` method allows takes a collection of `EventData`, which makes possible saving more than one event in a single batch.
@@ -52,6 +56,10 @@ For example:
5256

5357
<<< @/docs/clients/java/generated/0.7/samples/appending_events/AppendingEvents.java#append-duplicate-event
5458
</xode-block>
59+
<xode-block title="Rust">
60+
61+
<<< @/docs/clients/rust/generated/0.9.9/samples/appending_events.rs#append-duplicate-event
62+
</xode-block>
5563
</xode-group>
5664

5765
will result in only a single event being appended.
@@ -97,6 +105,10 @@ For example if we try and append the same record twice expecting both times that
97105

98106
<<< @/docs/clients/java/generated/0.7/samples/appending_events/AppendingEvents.java#append-with-no-stream
99107
</xode-block>
108+
<xode-block title="Rust">
109+
110+
<<< @/docs/clients/rust/generated/0.9.9/samples/appending_events.rs#append-with-no-stream
111+
</xode-block>
100112
</xode-group>
101113

102114
There are three available stream states:
@@ -119,6 +131,10 @@ This check can be used to implement optimistic concurrency. When you retrieve a
119131

120132
<<< @/docs/clients/java/generated/0.7/samples/appending_events/AppendingEvents.java#append-with-concurrency-check
121133
</xode-block>
134+
<xode-block title="Rust">
135+
136+
<<< @/docs/clients/rust/generated/0.9.9/samples/appending_events.rs#append-with-concurrency-check
137+
</xode-block>
122138
</xode-group>
123139

124140
<!-- ## Options
@@ -140,4 +156,8 @@ You can provide user credentials to be used to append the data as follows. This
140156

141157
<<< @/docs/clients/java/generated/0.7/samples/appending_events/AppendingEvents.java#overriding-user-credentials
142158
</xode-block>
159+
<xode-block title="Rust">
160+
161+
<<< @/docs/clients/rust/generated/0.9.9/samples/appending_events.rs#overriding-user-credentials
162+
</xode-block>
143163
</xode-group>

import/import-client-docs.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,37 @@ async function replaceCodePath(mdPath, samplesPath) {
4242
await sh(replaceCommand);
4343
}
4444

45-
async function tryCopy(pathElements, subFolderName, destinationPath) {
46-
const sourcePath = path.join(...[...pathElements, subFolderName]);
45+
async function tryCopy(pathElements, destinationPath) {
46+
const sourcePath = path.join(...pathElements);
4747

4848
if (!fs.existsSync(sourcePath)) {
4949
log.info(`${sourcePath} does not exist, skipping...`);
5050
return false;
5151
}
5252

53-
log.info(`${subFolderName} exist, copying...`);
53+
log.info(`${sourcePath} exist, copying...`);
5454

5555
await fsExtra.copy(sourcePath, destinationPath);
5656

5757
return true;
5858
}
5959

60-
async function copyDocsAndSamples(clientRepo, repoLocation, docsLocation, id, tag, relativePath) {
60+
async function copySamples(clientRepo, repoLocation, destinationPath, id, tag, relativePath) {
6161
log.info(`checking out ${tag}...`);
6262
await clientRepo.checkout(tag);
6363

64-
const pathElements = [repoLocation, ...(relativePath || ['docs'])];
64+
const pathElements = [repoLocation, ...relativePath];
6565

66-
const samplesDestinationPath = path.join(docsLocation, id, 'samples');
67-
const docsDestinationPath = path.join(docsLocation, id);
66+
const destinationPathWithId = path.join(destinationPath, id);
67+
const samplesDestinationPath = path.join(destinationPathWithId, 'samples');
6868

69-
const wereDocsCopied = await tryCopy(pathElements, 'docs', docsDestinationPath);
70-
const wereSamplesCopied = await tryCopy(pathElements, 'samples', samplesDestinationPath);
69+
const wereSamplesCopied = await tryCopy(pathElements, samplesDestinationPath);
7170

72-
if (!wereDocsCopied && !wereSamplesCopied) {
71+
if (!wereSamplesCopied) {
7372
return;
7473
}
7574

76-
await replaceCodePath(docsDestinationPath, samplesDestinationPath);
75+
await replaceCodePath(destinationPathWithId, samplesDestinationPath);
7776

7877
return {path: path.join('generated', id), version: id.substr(1) + ' gRPC'};
7978
}
@@ -84,10 +83,10 @@ async function main() {
8483

8584
for (const repo of repos) {
8685
const repoPath = path.join('docs', repo.basePath);
87-
const docsLocation = path.join(repoPath, 'generated');
86+
const samplesLocation = path.join(repoPath, 'generated');
8887
const repoLocation = path.join('temp', repo.id);
8988

90-
await safeRmdir(docsLocation);
89+
await safeRmdir(samplesLocation);
9190
await git.clone(repo.repo, repoLocation);
9291

9392
const clientRepo = simpleGit(repoLocation);
@@ -108,11 +107,11 @@ async function main() {
108107
.filter(i => i)
109108

110109
if (deployCurrent) {
111-
definition[0].versions.push(await copyDocsAndSamples(clientRepo, repoLocation, docsLocation, tags.slice(-1)[0], repo.currentBranch, repo.relativePath));
110+
definition[0].versions.push(await copySamples(clientRepo, repoLocation, samplesLocation, tags.slice(-1)[0], repo.currentBranch, repo.relativePath));
112111
}
113112

114113
for (let i = 0; i < tags.length - 1; i++) {
115-
const version = await copyDocsAndSamples(clientRepo, repoLocation, docsLocation, tags[i], tags[i + 1]);
114+
const version = await copySamples(clientRepo, repoLocation, samplesLocation, tags[i], tags[i + 1], repo.relativePath);
116115

117116
if (version !== undefined) {
118117
definition[0].versions.push(version);

import/repos.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@
33
"id": "dotnet-client",
44
"group": ".NET SDK",
55
"basePath": "clients/dotnet",
6-
"relativePath": [],
6+
"relativePath": ["samples"],
77
"currentBranch": "master",
88
"repo": "https://github.com/EventStore/EventStore-Client-Dotnet.git"
99
},
1010
{
1111
"id": "java-client",
1212
"group": "Java SDK",
1313
"basePath": "clients/java",
14-
"relativePath": ["db-client-java","src","test","java","com","eventstore","dbclient"],
14+
"relativePath": ["db-client-java","src","test","java","com","eventstore","dbclient", "samples"],
1515
"currentBranch": "trunk",
1616
"repo": "https://github.com/EventStore/EventStoreDB-Client-Java.git"
17+
},
18+
{
19+
"id": "rust-client",
20+
"group": "Rust SDK",
21+
"basePath": "clients/rust",
22+
"relativePath": ["examples"],
23+
"currentBranch": "snippets_fixes_for_docs",
24+
"repo": "https://github.com/EventStore/EventStoreDB-Client-Rust.git"
1725
}
1826
]

0 commit comments

Comments
 (0)