Reputation: 21
I have the following function in Rust. It converts all Torrent files to Magnet links. For some files it throws an Error. I wan't to skip those files
use rs_torrent_magnet;
pub fn build_cache(paths: Vec<PathBuf>, magnets: String, names: String){
for path in paths{
println!("Reading file: {:?}", path);
let magnet = match rs_torrent_magnet::magnet_from_torrent_file(path) {
Ok(magnet) => magnet,
Err(e) => {
eprintln!("Error reading magnet from torrent file: {:?}", e);
return;
}
};
}
}
But I get the following compiler error:
error[E0308]: mismatched types
--> src/scraper.rs:33:13
|
32 | let magnet = match rs_torrent_magnet::magnet_from_torrent_file(path) {
| ------------------------------------------------- this expression has type `std::string::String`
33 | Ok(magnet) => magnet,
| ^^^^^^^^^^ expected `String`, found `Result<_, _>`
|
= note: expected struct `std::string::String`
found enum `Result<_, _>`
Why does it return Result<_, _> instead of String?
Upvotes: 1
Views: 58
Reputation: 169018
You're trying to treat the result of magnet_from_torrent_file
as a Result
, but it's not -- it's a String
. This function may have a different way to signal errors, such as by panicking, but it's not documented so there isn't much to go on without digging into the internals.
Upvotes: 2