6dc75f0c5d
This patch adds tests for Rust 1.54.0, 1.55.0 and 1.56.0. To make the tests pass, we have to take care of some changes like more details elements and changed heading levels. To make it easier to generate the tests for new Rust versions, we also add two bash scripts that take care of that.
59 lines
1.6 KiB
Plaintext
59 lines
1.6 KiB
Plaintext
---
|
|
source: tests/output.rs
|
|
expression: "get_stdout(path, &[\"-e\", \"anyhow\"])"
|
|
|
|
---
|
|
anyhow Module anyhow rusty-man
|
|
|
|
EXAMPLES
|
|
Example 1 of 6
|
|
use anyhow::Result;
|
|
|
|
fn get_cluster_info() -> Result<ClusterMap> {
|
|
let config = std::fs::read_to_string("cluster.json")?;
|
|
let map: ClusterMap = serde_json::from_str(&config)?;
|
|
Ok(map)
|
|
}
|
|
|
|
Example 2 of 6
|
|
use anyhow::{Context, Result};
|
|
|
|
fn main() -> Result<()> {
|
|
...
|
|
it.detach().context("Failed to detach the important thing")?;
|
|
|
|
let content = std::fs::read(path)
|
|
.with_context(|| format!("Failed to read instrs from {}", path))?;
|
|
...
|
|
}
|
|
|
|
Example 3 of 6
|
|
// If the error was caused by redaction, then return a
|
|
// tombstone instead of the content.
|
|
match root_cause.downcast_ref::<DataStoreError>() {
|
|
Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),
|
|
None => Err(error),
|
|
}
|
|
|
|
Example 4 of 6
|
|
use thiserror::Error;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum FormatError {
|
|
#[error("Invalid header (expected {expected:?}, got {found:?})")]
|
|
InvalidHeader {
|
|
expected: String,
|
|
found: String,
|
|
},
|
|
#[error("Missing attribute: {0}")]
|
|
MissingAttribute(String),
|
|
}
|
|
|
|
Example 5 of 6
|
|
return Err(anyhow!("Missing attribute: {}", missing));
|
|
|
|
Example 6 of 6
|
|
bail!("Missing attribute: {}", missing);
|
|
|
|
|