-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: Make Agent
take DID
by value
#10
Conversation
85c3701
to
254b7f4
Compare
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @matheus23
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'sAppState
, or hold it across an await point in a tokio task.The downside is that you're sometimes required to clone the
DID
andSigner
that you put into theAgent
, but I'd argue that, the longer theAgent
lives for, the less often you're required toclone
something into it.