29 questions
Score of 0
1 answer
204 views
Propagate errors across task boundaries in an ergonomic way
I am writing a small cli application to learn rust and did start my error propagation with a lot of Result<_, Box<dyn std::error::Error>>. This is quite flexible and works nicely.
Now I ...
Score of 0
1 answer
178 views
In Rust, what's the most idiomatic way to convert a result to another result given the Error type is convertible [closed]
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() -&...
Score of 0
1 answer
120 views
Is there a simple way to get Result<&T, E> from Result<T, E>?
Result<T, E>.as_ref() will convert it to Result<&T, &E>, but the expected result is Result<&T, E>.
Score of 0
1 answer
1800 views
Read claims without verification. , Understanding the Result return
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 ...
Score of 1
2 answers
2782 views
Why is `return` necessary in `match` arm when using `Result` in `main`?
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(...
Score of 0
1 answer
475 views
How to take T out of Result<Vec<Data<&T>>>?
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>>, ()&...
Score of 4
1 answer
5173 views
How do I generify the error of a Rust Result<T, E> to Result<T, Box<dyn std::error::Error>>?
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 ...
Score of 14
1 answer
7608 views
What is the point of an Infallible Result, over just returning the Ok() branch?
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 ...
Score of 1
2 answers
1309 views
Should I ditch using `and_then` and always use the `?` operator?
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::...
Score of 1
0 answers
64 views
How to work with custom string errors in rust? [duplicate]
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 {
...
Score of 2
1 answer
2045 views
How do I return a Result data type in Rust?
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, ...
Score of 10
1 answer
6156 views
Calling map on Iter of Results in Rust
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 ...
Score of 4
1 answer
919 views
How to avoid "Error:" output when returning Result from main?
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 {
...
Score of 7
1 answer
10782 views
Cannot call a function that returns Result: found opaque type impl std::future::Future
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();
...
Score of 13
1 answer
4166 views
What does dotenv().ok() do?
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();
...