#![allow(clippy::pedantic)]
tonic::include_proto!("arcana.activation");
pub trait HeadedResponse {
fn eof() -> Self;
fn from_header(header: ResponseHeader) -> Self;
}
pub trait HeadedRequest {
fn header(&self) -> &Option<RequestHeader>;
}
impl ResponseHeader {
pub(crate) fn eof() -> Self {
ResponseHeader {
msg: String::new(),
response_type: ResponseType::Eof.into(),
}
}
pub fn error(msg: String) -> Self {
ResponseHeader {
msg,
response_type: ResponseType::Error.into(),
}
}
pub fn warn(msg: String) -> Self {
ResponseHeader {
msg,
response_type: ResponseType::Warn.into(),
}
}
pub fn log(msg: String) -> Self {
ResponseHeader {
msg,
response_type: ResponseType::Log.into(),
}
}
}
impl HeadedResponse for ApplyResponse {
fn eof() -> Self {
ApplyResponse {
header: Some(ResponseHeader::eof()),
}
}
fn from_header(header: ResponseHeader) -> Self {
ApplyResponse {
header: Some(header),
}
}
}
impl HeadedResponse for BuildResponse {
fn eof() -> Self {
BuildResponse {
header: Some(ResponseHeader::eof()),
new_store_path: None,
}
}
fn from_header(header: ResponseHeader) -> Self {
let new_store_path = if header.msg.starts_with("/nix/store") {
Some(header.msg.clone())
} else {
None
};
BuildResponse {
header: Some(header),
new_store_path,
}
}
}
impl HeadedResponse for CopyClosureResponse {
fn eof() -> Self {
CopyClosureResponse {
header: Some(ResponseHeader::eof()),
}
}
fn from_header(header: ResponseHeader) -> Self {
CopyClosureResponse {
header: Some(header),
}
}
}
impl HeadedRequest for ApplyRequest {
fn header(&self) -> &Option<RequestHeader> {
&self.header
}
}
impl HeadedRequest for BuildRequest {
fn header(&self) -> &Option<RequestHeader> {
&self.header
}
}
impl HeadedRequest for CopyClosureRequest {
fn header(&self) -> &Option<RequestHeader> {
&self.header
}
}