% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dist_structure-class.R
\name{validate_dist_structure}
\alias{validate_dist_structure}
\title{Validate that an object satisfies the dist_structure protocol}
\usage{
validate_dist_structure(x)
}
\arguments{
\item{x}{An object claiming to satisfy the \code{dist_structure} protocol.}
}
\value{
\code{TRUE} (invisibly) if all checks pass. Stops with an
informative error otherwise.
}
\description{
Checks that \code{x} declares \code{"dist_structure"} in its class chain and
provides the three required generics: \code{\link[=ncomponents]{ncomponents()}}, \code{\link[=component]{component()}},
and at least one of \code{\link[=phi]{phi()}} or \code{\link[=min_paths]{min_paths()}}.
}
\details{
Useful in subclass constructors to fail fast with a clear error
message rather than at first method dispatch (where the user sees
opaque "no applicable method" errors). A typical pattern:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{my_subclass <- function(...) \{
  obj <- structure(list(...), class = c("my_subclass", "dist_structure",
                                         "univariate_dist", "continuous_dist", "dist"))
  validate_dist_structure(obj)
  obj
\}
}\if{html}{\out{</div>}}
}
\examples{
# Success: a valid dist_structure (any built-in topology shortcut works).
validate_dist_structure(series_dist(replicate(3,
  algebraic.dist::exponential(1), simplify = FALSE)))

# Failure: an object that declares dist_structure but provides no
# primitives. Wrapped in tryCatch for the example's success status.
bad <- structure(list(),
                 class = c("not_a_real_class", "dist_structure",
                           "univariate_dist", "continuous_dist", "dist"))
tryCatch(validate_dist_structure(bad),
         error = function(e) conditionMessage(e))
}
