use crate::error::Error;
use std::num::NonZero;
#[must_use]
#[derive(Clone, Debug)]
#[derive_const(Default)]
pub struct Builder {
pub(super) message: Option<Box<str>>,
pub(super) offset: Option<NonZero<u64>>,
}
impl Builder {
#[inline]
pub const fn new() -> Self {
Default::default()
}
pub fn message<T: ToString>(mut self, message: T) -> Self {
self.message = Some(message.to_string().into());
self
}
#[inline]
pub fn offset(mut self, mut offset: u64) -> Self {
offset = offset.checked_add(1)
.expect("cannot specify `0xFFFFFFFFFFFFFFFF` as offset");
self.offset = NonZero::new(offset);
self
}
#[inline]
pub fn build(self) -> Error {
Error::from_builder(self)
}
}