Skip to main content
0 votes
1 answer
155 views

Let's say I call a function that returns me Result<Foo, Error1> and want to return Result<Foo, Error2>. Error2 implements From<Error1>. The two options I have in mind are fn f1() -&...
Ricola's user avatar
  • 2,981
0 votes
1 answer
107 views

Result<T, E>.as_ref() will convert it to Result<&T, &E>, but the expected result is Result<&T, E>.
progquester's user avatar
  • 1,896
0 votes
1 answer
2k views

I'm working JWT's in Rust and have come across a situation that I'm having some issues navigating. I'm new to both Rust and JWT's, so bare with me. I'm using the jwt crate found here. What I want to ...
Michael's user avatar
  • 304
1 vote
2 answers
3k views

I am reading Rust by Example book. In this example removing return in Err(e) => return Err(e) causes an error: expected `i32`, found enum `Result`` . Why is that? What is the difference between Err(...
Peter's user avatar
  • 795
0 votes
1 answer
473 views

I'd like to take SomeType out of Result<Vec<Data<&SomeType>>>, and then pass it by a channel, but I failed: pub fn read(result: Result<Vec<Data<&SomeType>>, ()&...
xc wang's user avatar
  • 372
4 votes
1 answer
5k views

I am trying to generify a Result that is returned by the reqwest::blocking::get function. It returns a Result<reqwest::blocking::Response, reqwest::Error> but the function it is called in ...
Dan's user avatar
  • 5,363
14 votes
1 answer
7k views

The canonical example of a Warp rejection handler is async fn handle_rejection(err: Rejection) -> Result<impl Reply, Infallible> { But what's the advantage of a Result<ok, err> such ...
Evan Carroll's user avatar
1 vote
2 answers
1k views

I want to write something like this, but it won't compile due to a mismatch between types: fn main() -> std::result::Result<(), Box<dyn std::error::Error>> { let val = std::env::...
Midnight Exigent's user avatar
1 vote
0 answers
63 views

How can I return my own string errors in rust? fn main() -> std::io::Result<(), std::io::Error> { let a = 30; if a == 10 { println!("ten"); } else if a == 20 { ...
Eka's user avatar
  • 15.2k
2 votes
1 answer
2k views

I have the code below fn main() { let num: i64 = 600851475143; println!("Largest prime: {}", largest_prime_factor(num)); } fn largest_prime_factor(num:i64) -> Result<i64, ...
wellows's user avatar
  • 43
9 votes
1 answer
6k views

I would like to write some code in a "functional programming" style. However, I start with an Iterator of Results and I only want to apply the function to the Ok items. Furthermore, I want ...
Unapiedra's user avatar
  • 16.5k
4 votes
1 answer
846 views

I'm trying to make my own custom errors but I do not want Rust to automatically add Error: in front of the error messages. use std::error::Error; use std::fmt; #[derive(Debug)] enum CustomError { ...
PotatoParser's user avatar
  • 1,058
7 votes
1 answer
11k views

I cannot return a result of a function from a Result. Every tutorial only shows how to use a Result, but not how to return a value from it. fn main(){ let mut a: Vec<String> = Vec::new(); ...
Dude4's user avatar
  • 163
13 votes
1 answer
4k views

I am using the Diesel ORM wrapper with PostgreSQL. I was following the guide on their website which has the following code: pub fn establish_connection() -> PgConnection { dotenv().ok(); ...
elementory's user avatar
0 votes
1 answer
798 views

After a brief attempt, when I run the the Rustling test for exercises/error_handling/errorsn.rs, I get ---- test_ioerror stdout ---- thread 'test_ioerror' panicked at 'assertion failed: `(left == ...
Evan Carroll's user avatar

15 30 50 per page