Last active
October 27, 2019 14:54
-
-
Save pscott/4d5b29c3a92d36e160516f9f70811cc8 to your computer and use it in GitHub Desktop.
<3
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
trait MyTrait<U, T> { | |
fn signing_func(&self, challenger: &U, history: &[T]) -> Result<usize, &'static str>; | |
} | |
impl MyTrait<TypeA, TypeB> | |
for HistoryInfo<TypeB> | |
{ | |
fn signing_func( | |
&self, | |
challenger: &TypeA, | |
history: &[TypeB], | |
) -> Result<usize, &'static str> { | |
should_sign_attestation(challenger, history).map_err(|_| "invalid attestation") | |
} | |
} | |
impl MyTrait<TypeC, TypeD> | |
for HistoryInfo<TypeD> | |
{ | |
fn signing_func( | |
&self, | |
challenger: &TypeC, | |
history: &[TypeD], | |
) -> Result<usize, &'static str> { | |
should_sign_block(challenger, history) | |
} | |
} | |
#[derive(Debug)] | |
struct HistoryInfo<T: Encode + Decode + Clone> { | |
filename: String, | |
mutex: Arc<Mutex<Vec<T>>>, | |
} | |
impl<T: Encode + Decode + Clone> HistoryInfo<T> { | |
fn should_sign<U>(&self, challenger: &U) -> Result<usize, &'static str> { | |
let guard = self.mutex.lock(); | |
let history = &guard[..]; | |
self.signing_func(challenger, history) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment