Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive Clone for HandshakeComplete #80

Merged
merged 7 commits into from
Oct 18, 2023

Conversation

mycognosist
Copy link
Contributor

Simply derives Clone for the HandshakeComplete struct and addresses clippy lints related to needless borrows.

@adria0, would you be able to merge this? I don't have write permissions for the handshake repo.

@adria0 adria0 requested review from Dhole and adria0 October 17, 2023 03:14
@mycognosist
Copy link
Contributor Author

I've added three commits which should address all clippy warnings, as well as a test warning.

@Dhole
Copy link
Collaborator

Dhole commented Oct 17, 2023

The changes look good to me! Nevertheless I see from the github actions that it's not building, do you know what's happening? The error is in lib.rs but you didn't touch that file in this PR.

@mycognosist
Copy link
Contributor Author

mycognosist commented Oct 17, 2023

@Dhole

Thanks for taking a look! The build is failing due to an "ambiguous glob re-exports" error:

error: ambiguous glob re-exports
  --> src/lib.rs:16:9
   |
16 | pub use boxstream::*;
   |         ^^^^^^^^^^^^ the name `Result` in the type namespace is first re-exported here
17 | pub use handshake::*;
   |         ------------ but the name `Result` in the type namespace is also re-exported here
   |
   = note: `-D ambiguous-glob-reexports` implied by `-D warnings`

error: ambiguous glob re-exports
  --> src/lib.rs:16:9
   |
16 | pub use boxstream::*;
   |         ^^^^^^^^^^^^ the name `Error` in the type namespace is first re-exported here
17 | pub use handshake::*;
   |         ------------ but the name `Error` in the type namespace is also re-exported here

error: could not compile `kuska-handshake` (lib) due to 2 previous errors

I haven't touched that file and I'm not able to replicate the error locally when running the build command (probably because I'm running an older version of the compiler and that specific lint was only introduced earlier this year):

RUSTFLAGS="-D warnings" cargo build --verbose --all-features --all-targets

@mycognosist
Copy link
Contributor Author

mycognosist commented Oct 17, 2023

I'm taking a closer look at thiserror to see if I can create a top-level error type which unifies the separate boxstream and handshake errors (in a transparent way that doesn't cause any breakages to downstream libraries and applications).

Solving the Result issue is easier: just define the result in src/lib.rs and use that in the boxstream and handshake modules.

@Dhole
Copy link
Collaborator

Dhole commented Oct 18, 2023

I'm taking a closer look at thiserror to see if I can create a top-level error type which unifies the separate boxstream and handshake errors (in a transparent way that doesn't cause any breakages to downstream libraries and applications).

Solving the Result issue is easier: just define the result in src/lib.rs and use that in the boxstream and handshake modules.

I was able to reproduce the build failure with Rust 1.73.0

Perhaps another solution is the following:

  • export boxstream::Error and boxstream::Result as BoxstreamError, BoxstreamResult
  • export handhsake::Error and handshake::Result as HandshakeError, HandshakeResult
  • Create a new error in lib.rs called Error with From and From, which is an enum with two cases, one for BoxstreamError and one for HandshakeError
  • Define in lib.rs pub type Result<T> = std::result::Result<T, Error>

Although this may still create downstream problems if an application is matching on the Error cases, which now will be different for the top level Error.

I guess your idea is to merge both errors into a single one? That should not break any downstream usage, but it feels a bit wrong to flatten out the error cases of the two modules 🤔

@mycognosist
Copy link
Contributor Author

mycognosist commented Oct 18, 2023

The solution you outlined is exactly what I was thinking (using the #[error(transparent)] attribute on each of the two enum variants so that the Display impl of each underlying error would be used).

I've been playing around with a few options this morning but the solution outlined above ends up breaking https://github.com/Kuska-ssb/ssb.

There's another solution which seems to work for me; simply replace the glob re-exports with explicit (named) re-exports and alias the error and result types:

pub use boxstream::{
    BoxStreamRecv, BoxStreamSend, Error as BoxstreamError, Header, Result as BoxstreamResult,
};
pub use handshake::{
    Error as HandshakeError, Handshake, Result as HandshakeResult, SendServerAccept,
};

That solution requires minimal changes to the handshake crate, solves the clippy warnings and does not cause any breakage in https://github.com/Kuska-ssb/ssb. Seems like a good outcome?

@ed255
Copy link

ed255 commented Oct 18, 2023

There's another solution which seems to work for me; simply replace the glob re-exports with explicit (named) re-exports and alias the error and result types:

pub use boxstream::{
    BoxStreamRecv, BoxStreamSend, Error as BoxstreamError, Header, Result as BoxstreamResult,
};
pub use handshake::{
    Error as HandshakeError, Handshake, Result as HandshakeResult, SendServerAccept,
};

That solution requires minimal changes to the handshake crate, solves the clippy warnings and does not cause any breakage in https://github.com/Kuska-ssb/ssb. Seems like a good outcome?

This solution looks great to me! And I think it's very clean :)

@Dhole
Copy link
Collaborator

Dhole commented Oct 18, 2023

On the last run, the examples didn't build with this error:

  --> examples/handshake.rs:12:5
   |
12 |     SharedSecret,
   |     ^^^^^^^^^^^^ no `SharedSecret` in the root

I guess SharedSecret needs to be exported too.

BTW, the message from @ed255 was myself from my other github account 😅

@mycognosist
Copy link
Contributor Author

Sorry for all the noise with these failed builds! The commit I just pushed should pass 🤞🏻

BTW, the message from @ed255 was myself from my other github account 😅

I was a bit confused at first but then I saw your bio and understood :)

Copy link
Collaborator

@Dhole Dhole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for all the extra work you did to make all the github actions pass 😄

@Dhole Dhole merged commit b941920 into Kuska-ssb:master Oct 18, 2023
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants