Closed smCloudInTheSky closed 3 years ago
It works fine for me. How are you running the example? Are you using cargo test
in the gpgme repository or did you copy the example somewhere else? If you copied the example, did you make sure you included the "?
" at the end?
Hello,
Sorry for not answering earlier.
I did try with the ? at the end but got the following error :
let mut ctx = Context::from_protocol(Protocol::OpenPgp)?;
| | ^ cannot use the ?
operator in a function that returns ()
So I looked into your test directory and found you used unwrap instead hence my proposition of modification.
Regards
unwrap
is not generally recommended for error handling (especially for this crate) as it will usually abort the process, but is usually fine for tests. To use the ?
operator your function has to return a Result
(or an Option
) with a compatible error type. Documentation examples have an implicit main function that sort of looks like this:
fn main() -> Result<(), impl Debug> {
// example code goes here
Ok(())
}
For more information see the section on error propagation in the rust book along with the next chapter on panicking.
Ok my bad sorry for bothering you and thanks for the explanation.
Current example doesn't work and return : Error[E0599]: no method named
with_passphrase_provider
found for enumstd::result::Result<gpgme::Context, gpgme::Error>
in the current scope.Propose a working fix according to what we can find in the test directory