pub struct ContentProcessingErrorBuilder { /* private fields */ }Expand description
Builder for constructing Error::ContentProcessing variants.
This builder offers a fluent API for incrementally specifying optional fields like custom error messages, a source error, additional context details, and severity levels.
§Examples
use staticdatagen::{ContentProcessingErrorBuilder, ErrorSeverity};
use std::error::Error as StdError;
fn process_content() -> Result<(), Box<dyn StdError>> {
// Emulate a scenario where content parsing fails
let err = ContentProcessingErrorBuilder::new()
.message("Invalid content structure")
.context("Failed to parse JSON")
.severity(ErrorSeverity::Error)
.build();
Err(Box::new(err))
}Implementations§
Source§impl ContentProcessingErrorBuilder
impl ContentProcessingErrorBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new ContentProcessingErrorBuilder instance with default values.
All fields are initially:
message:Nonesource:Noneadditional_context: empty vectorseverity:None
Sourcepub fn message(self, msg: impl Into<String>) -> Self
pub fn message(self, msg: impl Into<String>) -> Self
Sets the primary error message.
This message should concisely describe what went wrong.
Sourcepub fn source<T>(self, err: T) -> Self
pub fn source<T>(self, err: T) -> Self
Sets the underlying source error, if any.
Including the source error can help diagnose the root cause of a failure.
This version allows callers to pass either a concrete type implementing
StdError + Send + Sync + 'static or a Box<dyn StdError + Send + Sync>.
Sourcepub fn context(self, ctx: impl Into<String>) -> Self
pub fn context(self, ctx: impl Into<String>) -> Self
Adds an additional context message describing the error scenario.
You can call this method multiple times to append different context snippets.
Sourcepub fn severity(self, severity: ErrorSeverity) -> Self
pub fn severity(self, severity: ErrorSeverity) -> Self
Sets the severity level of the error for more granular categorisation.
Refer to ErrorSeverity for possible variants and their definitions.
Sourcepub fn build(self) -> Error
pub fn build(self) -> Error
Builds and returns a fully constructed Error::ContentProcessing variant.
If no message has been set, a default of "Unknown error" is used. All context
strings and severity indicators are appended to the final error message.
Trait Implementations§
Source§impl Default for ContentProcessingErrorBuilder
impl Default for ContentProcessingErrorBuilder
Source§fn default() -> ContentProcessingErrorBuilder
fn default() -> ContentProcessingErrorBuilder
Auto Trait Implementations§
impl Freeze for ContentProcessingErrorBuilder
impl !RefUnwindSafe for ContentProcessingErrorBuilder
impl Send for ContentProcessingErrorBuilder
impl Sync for ContentProcessingErrorBuilder
impl Unpin for ContentProcessingErrorBuilder
impl UnsafeUnpin for ContentProcessingErrorBuilder
impl !UnwindSafe for ContentProcessingErrorBuilder
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more