Improve distant-core readme

pull/96/head
Chip Senkbeil 3 years ago
parent fc2a6ab09c
commit a672515378
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -32,7 +32,7 @@ You can import the dependency by adding the following to your `Cargo.toml`:
```toml ```toml
[dependencies] [dependencies]
distant-core = "0.14" distant-core = "0.15"
``` ```
## Features ## Features
@ -49,25 +49,23 @@ By default, no features are enabled on the library.
Below is an example of connecting to a distant server over TCP: Below is an example of connecting to a distant server over TCP:
```rust ```rust
use distant_core::{Request, RequestData, Session, SessionInfo}; use distant_core::{Session, SessionChannelExt, SecretKey32, XChaCha20Poly1305Codec};
use std::path::PathBuf; use std::net::SocketAddr;
// Load our session using the environment variables // 32-byte secret key paresd from hex, used for a specific codec
// let key: SecretKey32 = "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF".parse().unwrap();
// DISTANT_HOST = "..." let codec = XChaCha20Poly1305Codec::from(key);
// DISTANT_PORT = "..."
// DISTANT_KEY = "..." let addr: SocketAddr = "example.com:8080".parse().unwrap();
let mut session = Session::tcp_connect(SessionInfo::from_environment()?).await.unwrap(); let mut session = Session::tcp_connect(addr, codec).await.unwrap();
// Send a request under a specific name and wait for a response // Append text to a file, representing request as <tenant>
let tenant = "my name"; // NOTE: This method comes from SessionChannelExt
let req = Request::new( session.append_file_text(
tenant, "<tenant>",
vec![RequestData::FileReadText { path: PathBuf::from("some/path") }] "path/to/file.txt".to_string(),
); "new contents"
).await.expect("Failed to append to file");
let res = session.send(req).await.unwrap();
println!("Response: {:?}", res);
``` ```
## License ## License

Loading…
Cancel
Save