tacacs_plus_protocol/authorization/
owned.rs

1use std::string::{String, ToString};
2use std::vec::Vec;
3
4use super::{Reply, Status};
5use crate::owned::FromBorrowedBody;
6use crate::sealed::Sealed;
7use crate::Argument;
8
9/// An authorization reply packet with owned fields.
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11pub struct ReplyOwned {
12    /// The status returned by the TACACS+ server.
13    pub status: Status,
14
15    /// The message to present to the user connected to this client.
16    pub server_message: String,
17
18    /// An administrative/console log message.
19    pub data: String,
20
21    /// The arguments sent by the server.
22    pub arguments: Vec<Argument<'static>>,
23}
24
25impl Sealed for ReplyOwned {}
26
27impl FromBorrowedBody for ReplyOwned {
28    type Borrowed<'b> = Reply<'b>;
29
30    fn from_borrowed(borrowed: &Self::Borrowed<'_>) -> Self {
31        let arguments_vec = borrowed
32            .iter_arguments()
33            .map(Argument::into_owned)
34            .collect();
35
36        ReplyOwned {
37            status: borrowed.status,
38            server_message: borrowed.server_message.to_string(),
39            data: borrowed.data.to_string(),
40            arguments: arguments_vec,
41        }
42    }
43}