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

refactor: Make Agent take DID by value #10

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

matheus23
Copy link
Member

I think this makes sense, because in practice, if Agent is meant to be alive for a long time in a program, it's much easier to do that when it doesn't borrow data, but instead is self-contained. E.g. this way you can put it into an axum's AppState, or hold it across an await point in a tokio task.
The downside is that you're sometimes required to clone the DID and Signer that you put into the Agent, but I'd argue that, the longer the Agent lives for, the less often you're required to clone something into it.

@matheus23 matheus23 requested a review from expede March 20, 2024 11:47
@matheus23 matheus23 self-assigned this Mar 20, 2024
@matheus23 matheus23 force-pushed the matheus23/v1.0-rc.1-no-agent-lifetime branch from 85c3701 to 254b7f4 Compare March 20, 2024 15:22
@@ -73,7 +72,7 @@ where
let nonce = Nonce::generate_12(&mut salt);

if let Some(ref sub) = subject {
if sub == self.did {
if sub == &self.did {
Copy link
Member

Choose a reason for hiding this comment

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

Minor question about this, because I run into it a lot. There's two options:

if sub == &self.did
// vs
if *sub == self.did

I assume that when you compare with &s, it has to deref these (which is extra indirection). The compiler can probably get rid of this, but do we know?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. Good question.
In the error message the compiler suggests &, but * totally works here, too.

@@ -438,8 +435,7 @@ mod tests {
#[test_log::test]
fn test_invoker_is_sub_implicit_aud() -> TestResult {
let (_nbf, now, exp) = setup_valid_time();
let (server, server_signer) = gen_did();
let mut agent = setup_agent(&server, &server_signer);
let mut agent = setup_agent();
Copy link
Member

Choose a reason for hiding this comment

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

Hm yeah this is a nice effect of this change

Copy link
Member

@expede expede left a comment

Choose a reason for hiding this comment

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

Thanks @matheus23

@matheus23 matheus23 merged commit 0e4308b into matheus23/v1.0-rc.1 Mar 20, 2024
2 of 9 checks passed
@matheus23 matheus23 deleted the matheus23/v1.0-rc.1-no-agent-lifetime branch March 20, 2024 18:40
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.

2 participants