Giter Club home page Giter Club logo

crypt3's Issues

Consider using thiserror instead of Box<Error>

I have a main function which returns anyhow::Result<()> and I'm getting the following error when using the ? operator with crypt:

let result = crypt(password.as_bytes(), &user_pwd.pw_passwd.as_bytes())?; 
error[E0277]: the size for values of type `dyn std::error::Error` cannot be known at compilation time
   --> src/bin/passwd.rs:413:76
    |
413 |     let result = crypt(password.as_bytes(), &user_pwd.pw_passwd.as_bytes())?;
    |                                                                            ^ doesn't have a size known at compile-time
    |
    = help: the trait `Sized` is not implemented for `dyn std::error::Error`
    = help: the following other types implement trait `FromResidual<R>`:
              <Result<T, F> as FromResidual<Yeet<E>>>
              <Result<T, F> as FromResidual<Result<Infallible, E>>>
    = note: required for `Box<dyn std::error::Error>` to implement `std::error::Error`
    = note: required for `anyhow::Error` to implement `From<Box<dyn std::error::Error>>`
    = note: required for `Result<(), anyhow::Error>` to implement `FromResidual<Result<Infallible, Box<dyn std::error::Error>>>`

error[E0277]: `dyn std::error::Error` cannot be sent between threads safely
   --> src/bin/passwd.rs:413:76
    |
413 |     let result = crypt(password.as_bytes(), &user_pwd.pw_passwd.as_bytes())?;
    |                                                                            ^ `dyn std::error::Error` cannot be sent between threads safely
    |
    = help: the trait `Send` is not implemented for `dyn std::error::Error`
    = help: the following other types implement trait `FromResidual<R>`:
              <Result<T, F> as FromResidual<Yeet<E>>>
              <Result<T, F> as FromResidual<Result<Infallible, E>>>
    = note: required for `Unique<dyn std::error::Error>` to implement `Send`
note: required because it appears within the type `Box<dyn Error>`
   --> /home/amiculas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:195:12
    |
195 | pub struct Box<
    |            ^^^
    = note: required for `anyhow::Error` to implement `From<Box<dyn std::error::Error>>`
    = note: required for `Result<(), anyhow::Error>` to implement `FromResidual<Result<Infallible, Box<dyn std::error::Error>>>`

error[E0277]: `dyn std::error::Error` cannot be shared between threads safely
   --> src/bin/passwd.rs:413:76
    |
413 |     let result = crypt(password.as_bytes(), &user_pwd.pw_passwd.as_bytes())?;
    |                                                                            ^ `dyn std::error::Error` cannot be shared between threads safely
    |
    = help: the trait `Sync` is not implemented for `dyn std::error::Error`
    = help: the following other types implement trait `FromResidual<R>`:
              <Result<T, F> as FromResidual<Yeet<E>>>
              <Result<T, F> as FromResidual<Result<Infallible, E>>>
    = note: required for `Unique<dyn std::error::Error>` to implement `Sync`
note: required because it appears within the type `Box<dyn Error>`
   --> /home/amiculas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:195:12
    |
195 | pub struct Box<
    |            ^^^
    = note: required for `anyhow::Error` to implement `From<Box<dyn std::error::Error>>`
    = note: required for `Result<(), anyhow::Error>` to implement `FromResidual<Result<Infallible, Box<dyn std::error::Error>>>`

Using an error type derived with thiserror would solve this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.