Skip to content

Commit 52205f7

Browse files
committed
fix rust doc examples
1 parent 70125fb commit 52205f7

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,38 @@ endpoints: list[Endpoint] = mesc.find_endpoints(chain_id=5)
105105

106106
###### rust
107107
```rust
108-
use mesc;
109-
use mesc::MescError;
108+
use mesc::{MescError, Endpoint};
109+
use std::collections::HashMap;
110110

111111
type OptionalResult = Result<Option<Endpoint>, MescError>;
112112
type MultiResult = Result<Vec<Endpoint>, MescError>;
113+
type MetadataResult = Result<HashMap<String, serde_json::Value>, MescError>;
114+
115+
// check whether mesc is enabled
116+
let enabled: bool = mesc::is_mesc_enabled();
113117

114118
// get the default endpoint
115119
let endpoint: OptionalResult = mesc::get_default_endpoint(None);
116120

117121
// get the default endpoint of a network
118-
let endpoint: OptionalResult = mesc::get_endpoint_by_network(5, None);
122+
let endpoint: OptionalResult = mesc::get_endpoint_by_network("5", None);
119123

120124
// get the default network for a particular tool
121-
let chain_id: OptionalResult = mesc::get_default_endpoint("xyz_tool");
125+
let chain_id: OptionalResult = mesc::get_default_endpoint(Some("xyz_tool"));
122126

123127
// get the default endpoint of a network for a particular tool
124-
let endpoint: OptionalResult = mesc::get_endpoint_by_network(5, "xyz_tool");
128+
let endpoint: OptionalResult = mesc::get_endpoint_by_network("5", Some("xyz_tool"));
125129

126130
// get an endpoint by name
127131
let endpoint: OptionalResult = mesc::get_endpoint_by_name("local_goerli");
128132

129133
// parse a user-provided string into a matching endpoint
130134
// (first try 1. endpoint name, then 2. chain id, then 3. network name)
131-
let endpoint: OptionalResult = mesc::get_endpoint_by_query(user_str, "xyz_tool");
135+
let user_str = "local_goerli";
136+
let endpoint: OptionalResult = mesc::get_endpoint_by_query(user_str, Some("xyz_tool"));
132137

133138
// find all endpoints matching given criteria
134-
let query = mesc::MultiEndpointQuery::new().chain_id(5);
139+
let query = mesc::MultiEndpointQuery::new().chain_id("5").unwrap();
135140
let endpoints: MultiResult = mesc::find_endpoints(query);
136141
```
137142

rust/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ let enabled: bool = mesc::is_mesc_enabled();
7070
let endpoint: OptionalResult = mesc::get_default_endpoint(None);
7171

7272
// get the default endpoint of a network
73-
let endpoint: OptionalResult = mesc::get_endpoint_by_network(5 as u8, None);
73+
let endpoint: OptionalResult = mesc::get_endpoint_by_network("5", None);
7474

7575
// get the default network for a particular tool
7676
let chain_id: OptionalResult = mesc::get_default_endpoint(Some("xyz_tool"));
7777

7878
// get the default endpoint of a network for a particular tool
79-
let endpoint: OptionalResult = mesc::get_endpoint_by_network(5 as u8, Some("xyz_tool"));
79+
let endpoint: OptionalResult = mesc::get_endpoint_by_network("5", Some("xyz_tool"));
8080

8181
// get an endpoint by name
8282
let endpoint: OptionalResult = mesc::get_endpoint_by_name("local_goerli");
@@ -87,7 +87,7 @@ let user_str = "local_goerli";
8787
let endpoint: OptionalResult = mesc::get_endpoint_by_query(user_str, Some("xyz_tool"));
8888

8989
// find all endpoints matching given criteria
90-
let query = mesc::MultiEndpointQuery::new().chain_id(5 as u8).unwrap();
90+
let query = mesc::MultiEndpointQuery::new().chain_id("5").unwrap();
9191
let endpoints: MultiResult = mesc::find_endpoints(query);
9292

9393
// get non-endpoint metadata

rust/crates/mesc_cli/src/cli/subcommands/help.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,34 +176,38 @@ metadata: Mapping[str, Any] = mesc.get_global_metadata(profile='xyz_tool')"#;
176176
}
177177

178178
fn print_rust_interface() {
179-
let interface = r#"use mesc;
180-
use mesc::MescError;
179+
let interface = r#"use mesc::{MescError, Endpoint};
180+
use std::collections::HashMap;
181181
182182
type OptionalResult = Result<Option<Endpoint>, MescError>;
183183
type MultiResult = Result<Vec<Endpoint>, MescError>;
184-
type MetadataResult = Result<HashMap<String, serde_json::Value>, MescError>
184+
type MetadataResult = Result<HashMap<String, serde_json::Value>, MescError>;
185+
186+
// check whether mesc is enabled
187+
let enabled: bool = mesc::is_mesc_enabled();
185188
186189
// get the default endpoint
187190
let endpoint: OptionalResult = mesc::get_default_endpoint(None);
188191
189192
// get the default endpoint of a network
190-
let endpoint: OptionalResult = mesc::get_endpoint_by_network(5, None);
193+
let endpoint: OptionalResult = mesc::get_endpoint_by_network("5", None);
191194
192195
// get the default network for a particular tool
193196
let chain_id: OptionalResult = mesc::get_default_endpoint(Some("xyz_tool"));
194197
195198
// get the default endpoint of a network for a particular tool
196-
let endpoint: OptionalResult = mesc::get_endpoint_by_network(5, Some("xyz_tool"));
199+
let endpoint: OptionalResult = mesc::get_endpoint_by_network("5", Some("xyz_tool"));
197200
198201
// get an endpoint by name
199202
let endpoint: OptionalResult = mesc::get_endpoint_by_name("local_goerli");
200203
201204
// parse a user-provided string into a matching endpoint
202205
// (first try 1. endpoint name, then 2. chain id, then 3. network name)
206+
let user_str = "local_goerli";
203207
let endpoint: OptionalResult = mesc::get_endpoint_by_query(user_str, Some("xyz_tool"));
204208
205209
// find all endpoints matching given criteria
206-
let query = mesc::MultiEndpointQuery::new().chain_id(5);
210+
let query = mesc::MultiEndpointQuery::new().chain_id("5").unwrap();
207211
let endpoints: MultiResult = mesc::find_endpoints(query);
208212
209213
// get non-endpoint metadata

0 commit comments

Comments
 (0)