Created
August 8, 2022 16:05
-
-
Save j-griffith/608d7729c2e9d082c8b8bc08b23a1526 to your computer and use it in GitHub Desktop.
reqwest-compile-err
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use reqwest::header; | |
use serde::{Deserialize, Serialize}; | |
use std::collections::HashMap; | |
struct Secret { | |
key: String, | |
value: String, | |
} | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let s = Secret { | |
key: "Foo".into(), | |
value: "Bar".into(), | |
}; | |
let client = reqwest::Client::new(); | |
let res = client | |
.post("http://127.0.0.1:8200/v1/secret/data/secret-1") | |
.header("X-Vault-Token", "hvs.PWr1hb0ZG2YGjTFmwtiSqLBa") | |
.form(&s) | |
.send() | |
.await | |
.expect("failed to post secret"); | |
println!("POST Response: {:#?}", res); | |
let res = client | |
.get("http://127.0.0.1:8200/v1/secret/data/secret-1") | |
.header("X-Vault-Token", "hvs.PWr1hb0ZG2YGjTFmwtiSqLBa") | |
.send() | |
.await | |
.expect("failed to get response") | |
.text() | |
.await | |
.expect("failed to get payload"); | |
println!("Response: {:#?}", res); | |
Ok(()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ vault-reqwest git:(master) ✗ cargo build | |
Compiling vault-reqwest v0.1.0 (/home/jgriffith/rust/vault-reqwest) | |
warning: unused import: `reqwest::header` | |
--> src/main.rs:1:5 | |
| | |
1 | use reqwest::header; | |
| ^^^^^^^^^^^^^^^ | |
| | |
= note: `#[warn(unused_imports)]` on by default | |
warning: unused imports: `Deserialize`, `Serialize` | |
--> src/main.rs:2:13 | |
| | |
2 | use serde::{Deserialize, Serialize}; | |
| ^^^^^^^^^^^ ^^^^^^^^^ | |
warning: unused import: `std::collections::HashMap` | |
--> src/main.rs:3:5 | |
| | |
3 | use std::collections::HashMap; | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | |
error[E0277]: the trait bound `Secret: Serialize` is not satisfied | |
--> src/main.rs:22:15 | |
| | |
22 | .form(&s) | |
| ---- ^^ the trait `Serialize` is not implemented for `Secret` | |
| | | |
| required by a bound introduced by this call | |
| | |
= help: the following other types implement trait `Serialize`: | |
&'a T | |
&'a mut T | |
() | |
(T0, T1) | |
(T0, T1, T2) | |
(T0, T1, T2, T3) | |
(T0, T1, T2, T3, T4) | |
(T0, T1, T2, T3, T4, T5) | |
and 127 others | |
note: required by a bound in `RequestBuilder::form` | |
--> /home/jgriffith/.cargo/registry/src/github.com-1ecc6299db9ec823/reqwest-0.11.11/src/async_impl/request.rs:409:20 | |
| | |
409 | pub fn form<T: Serialize + ?Sized>(mut self, form: &T) -> RequestBuilder { | |
| ^^^^^^^^^ required by this bound in `RequestBuilder::form` | |
For more information about this error, try `rustc --explain E0277`. | |
warning: `vault-reqwest` (bin "vault-reqwest") generated 3 warnings | |
error: could not compile `vault-reqwest` due to previous error; 3 warnings emitted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment