openethereum/json/src/test_helpers/tester.rs
Niklas Adolfsson d311bebaee cleanup json crate (#11027)
* [json]: cleanup

write something here....

* nit: commit new/moved files

* nit: remove needless features

* nits

* fix(grumbles): use explicit import `DifficultyTest`

* fix(grumbles): remove needless type hints

* fix(grumble): docs `from -> used by`

Co-Authored-By: David <dvdplm@gmail.com>

* fix(grumbles): use explicit `imports`

* fix(grumble): merge `tx` and `tx_with_signing_info`

* fix(grumbles): resolve introduced `TODO's`
2019-09-10 20:46:50 +02:00

28 lines
694 B
Rust

use std::collections::BTreeMap;
use serde::Deserialize;
use serde::de::DeserializeOwned;
/// A genric wrapper over a `BTreeMap` for tests
#[derive(Deserialize)]
pub struct GenericTester<T: Ord, U>(BTreeMap<T, U>);
impl<T: Ord, U> IntoIterator for GenericTester<T, U> {
type Item = <BTreeMap<T, U> as IntoIterator>::Item;
type IntoIter = <BTreeMap<T, U> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl<T, U> GenericTester<T, U>
where
T: DeserializeOwned + Ord,
U: DeserializeOwned
{
/// Loads test from json.
pub fn load<R>(reader: R) -> Result<Self, serde_json::Error> where R: std::io::Read {
serde_json::from_reader(reader)
}
}