Skip to content

Commit d686e52

Browse files
committed
[documentation]: #6 Move the Rust examples to this repository
Signed-off-by: 6r1d <[email protected]>
1 parent 4100a65 commit d686e52

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Rust/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "Iroha_2_examples"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
iroha_data_model = { "git" = "https://github.com/hyperledger/iroha.git", branch = "iroha2-dev" }
8+
iroha_client = { "git" = "https://github.com/hyperledger/iroha.git", branch = "iroha2-dev" }
9+
iroha_config = { "git" = "https://github.com/hyperledger/iroha.git", branch = "iroha2-dev" }
10+
11+
eyre = "0.6.8"
12+
13+
serde = { version = "1.0.151", default-features = false }
14+
serde_json = { version = "1.0.91", default-features = false }

Rust/examples/client_json_config.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::fs::File;
2+
use eyre::{Error, WrapErr};
3+
use iroha_config::client::Configuration;
4+
use iroha_data_model::TryToValue;
5+
6+
fn main() {
7+
// #region rust_config_load
8+
let config_loc = "../configs/client/config.json";
9+
let file = File::open(config_loc)
10+
.wrap_err("Unable to load the configuration file at `.....`")
11+
.expect("Config file is loading normally.");
12+
let config: Configuration = serde_json::from_reader(file)
13+
.wrap_err("Failed to parse `../configs/client/config.json`")
14+
.expect("Verified in tests");
15+
// #endregion rust_config_load
16+
17+
json_config_client_test(&config)
18+
.expect("JSON config client example is expected to work correctly");
19+
20+
println!("JSON client configuration test passed successfully!");
21+
}
22+
23+
fn json_config_client_test(config: &Configuration) -> Result<(), Error> {
24+
use iroha_client::client::Client;
25+
26+
// Initialise a client with a provided config
27+
let _current_client: Client = Client::new(&config)?;
28+
29+
Ok(())
30+
}

Rust/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

0 commit comments

Comments
 (0)