use std::borrow::Cow;
use std::fmt;
use std::num::NonZeroI32;
use crate::{FullStatus, ThinStatus};
pub struct ThinStatusBuilder<'a> {
pub(crate) full: FullStatus,
pub(crate) message: Cow<'a, str>,
}
impl<'a> ThinStatusBuilder<'a> {
pub fn new<C: Into<NonZeroI32>>(code: C) -> Self {
Self {
full: FullStatus {
code: code.into(),
details: Default::default(),
},
message: Cow::Borrowed(""),
}
}
pub fn code<C: Into<NonZeroI32>>(mut self, code: C) -> Self {
self.full.code = code.into();
self
}
pub fn message<S: Into<Cow<'a, str>> + ?Sized>(mut self, message: S) -> Self {
self.message = message.into();
self
}
#[cfg(feature = "use_any")]
pub fn add_detail(mut self, detail: google_cloud_wkt::Any) -> Self {
self.full.details.details.push(detail);
self
}
#[cfg(feature = "use_any")]
pub fn details(mut self, details: Vec<google_cloud_wkt::Any>) -> Self {
self.full.details.details = details;
self
}
pub fn build(self) -> ThinStatus {
ThinStatus::from_builder(self)
}
}
impl From<ThinStatusBuilder<'_>> for ThinStatus {
fn from(builder: ThinStatusBuilder) -> Self {
builder.build()
}
}
impl<'a> fmt::Write for ThinStatusBuilder<'a> {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.message.to_mut().push_str(s);
Ok(())
}
}