Mercurial > crates > nonstick
diff src/pam_ffi/conversation.rs @ 74:c7c596e6388f
Make conversations type-safe (last big reorg) (REAL) (NOT CLICKBAIT)
In previous versions of Conversation, you could send messages and then
return messages of the wrong type or in the wrong order or whatever.
The receiver would then have to make sure that there were the right
number of messages and that each message was the right type.
That's annoying.
This change makes the `Message` enum a two-way channel, where the asker
puts their question into it, and then the answerer (the conversation)
puts the answer in and returns control to the asker. The asker then
only has to pull the Answer of the type they wanted out of the message.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Fri, 06 Jun 2025 22:21:17 -0400 |
parents | ac6881304c78 |
children |
line wrap: on
line diff
--- a/src/pam_ffi/conversation.rs Thu Jun 05 03:41:38 2025 -0400 +++ b/src/pam_ffi/conversation.rs Fri Jun 06 22:21:17 2025 -0400 @@ -75,7 +75,7 @@ .map(Message::try_from) .collect::<StdResult<_, _>>() .map_err(|_| ErrorCode::ConversationError)?; - let responses = conv.converse(&messages)?; + let responses = conv.communicate(&messages)?; let owned = OwnedResponses::build(&responses).map_err(|_| ErrorCode::ConversationError)?; *response_ptr = owned.into_ptr(); @@ -86,7 +86,7 @@ } impl Conversation for LibPamConversation<'_> { - fn converse(&mut self, messages: &[Message]) -> Result<Vec<Response>> { + fn communicate(&mut self, messages: &[Message]) -> Result<Vec<Response>> { let mut msgs_to_send = OwnedMessages::alloc(messages.len()); for (dst, src) in iter::zip(msgs_to_send.iter_mut(), messages.iter()) { dst.set(*src).map_err(|_| ErrorCode::ConversationError)? @@ -149,7 +149,7 @@ text_resp.free_contents(); ret } - Message::Error(_) | Message::Info(_) => Response::NoResponse, + Message::ErrorMsg(_) | Message::InfoMsg(_) => Response::NoResponse, Message::BinaryPrompt { .. } => { let bin_resp = unsafe { RawBinaryResponse::upcast(received) }; let ret = Response::Binary(bin_resp.to_owned());