Skip to content

Instantly share code, notes, and snippets.

Joining Futures that can fail.

Rust futures join_all has changed behaviour.

With old futures API futures:0.1

When you had a bunch of futures that you want to wait to complete, you could join them with futures::future::join_all and wait on the joined future created.

@tarquin-the-brave
tarquin-the-brave / docker-compose.yml
Last active May 12, 2020 11:01
Code examples for [my blog post](https://tarquin-the-brave.github.io/blog/posts/mockserver-dc/) on using mockserver to FV test microservices.
version: "3.7"
services:
test:
build: ./fv
command: <command to run tests> ${TEST_ARGS}
microservice:
image: ${IMAGE:-x:latest}
environment:
LOG_LEVEL: debug
volumes:
#![allow(unused_variables)]
use serde_derive::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
struct MyData {
field_one: usize,
field_two: String,
field_three: bool,
some_data: std::collections::HashMap<String, usize>,
let yaml_data = serde_yaml::from_str::<serde_yaml::Value>(my_data_yaml)?;
let toml_data = toml::from_str::<toml::Value>(my_data_toml)?;
let json_data = serde_json::from_str::<serde_json::Value>(my_data_json)?;
let toml_from_yaml = serde_yaml::from_str::<toml::Value>(my_data_yaml)?;
let some_yaml = r#"
[5,6]: true
"#;
let try_yaml = serde_yaml::from_str::<serde_yaml::Value>(some_yaml);
let try_json = serde_yaml::from_str::<serde_json::Value>(some_yaml);
assert!(try_yaml.is_ok());
assert!(try_json.is_err());
{
"checked": false,
"dimensions": {
"width": 5,
"height": 10
},
"id": 1,
"name": "A green door",
"price": 12.5,
"tags": [
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
"description": "The root schema is the schema that comprises the entire JSON document.",
"default": {},
"required": [
"checked",
"dimensions",
let json_schema = serde_json::from_str::<schemars::schema::RootSchema>(
&std::fs::read_to_string("example.schema.json")?,
)?;
let json_schema_from_yaml = serde_yaml::from_str::<schemars::schema::RootSchema>(
&std::fs::read_to_string("example.schema.yaml")?,
)?;
$schema: http://json-schema.org/draft-07/schema
$id: http://example.com/root.json
type: object
title: The Root Schema
description: The root schema is the schema that comprises the entire JSON document.
default: {}
required:
- checked
- dimensions
- id