Compiler can not deduce the type of network_event in any case

Parsec depends on the two generic types T: NetworkEvent, S: SecretId>… Suppose I have implemented structure peer_id with trait SecretId and structure transaction with trait NetworkEvent. However, if I just do something like:

fn main() {
let mut genesis_group: BTreeSet = BTreeSet::new();
let peer_id = PeerId::new(&“test”);
genesis_group.insert(peer_id);
let parsec = unwrap!(parsec::Parsec::new(peer_id, &genesis_group));
}

Then the compiler can not deduce the actual type of T, because “T” does not appear here… The compiler says:

error[E0283]: type annotations required: cannot resolve _: parsec::NetworkEvent

This error does not appear in your tests or example, as the compiler might deduce the actual type of “T” from different things. However I would say, a constructure like _::new() should be enough…

3 Likes

You can either help the compiler out by telling it the type of your transaction when you call new():

let parsec = unwrap!(parsec::Parsec::<Transaction, _>::new(peer_id, &genesis_group));

or it can be auto-deduced if you pass one of your transaction types in a parsec function, e.g.

let mut parsec = unwrap!(parsec::Parsec::new(peer_id, &genesis_group));
parsec.vote_for(my_transaction);
7 Likes

I see… My limited understanding of the rust language. Thanks

2 Likes