Crate postmortem

Crate postmortem 

Source
Expand description

§Postmortem

A validation library that accumulates ALL validation errors, providing comprehensive feedback rather than short-circuiting on the first failure.

§Overview

Unlike typical validation libraries that stop at the first error, postmortem collects all validation errors to give users complete information about what needs to be fixed. This is achieved through integration with stillwater’s Validation type for applicative error accumulation.

§Core Types

  • JsonPath: Represents paths to values in nested structures (e.g., users[0].email)
  • SchemaError: A single validation error with context (path, message, expected/got values)
  • SchemaErrors: A non-empty collection of validation errors
  • Schema: Entry point for creating validation schemas

§Example

use postmortem::{JsonPath, Schema};
use serde_json::json;

// Create a string schema with constraints
let schema = Schema::string()
    .min_len(1)
    .max_len(100);

// Validate a value
let result = schema.validate(&json!("hello"), &JsonPath::root());
assert!(result.is_success());

// Invalid values produce detailed errors
let result = schema.validate(&json!(""), &JsonPath::root());
assert!(result.is_failure());

Re-exports§

pub use error::SchemaError;
pub use error::SchemaErrors;
pub use path::JsonPath;
pub use path::PathSegment;
pub use registry::RegistryError;
pub use registry::SchemaRegistry;
pub use schema::ArraySchema;
pub use schema::CombinatorSchema;
pub use schema::IntegerSchema;
pub use schema::ObjectSchema;
pub use schema::RefSchema;
pub use schema::Schema;
pub use schema::SchemaLike;
pub use schema::StringSchema;
pub use schema::ValueValidator;

Modules§

error
Error types for validation failures.
path
JSON path representation for locating values in nested structures.
registry
Schema registry for named schema storage and reference resolution.
schema
Schema definitions for validation.
validation
Validation context for schema reference resolution.

Type Aliases§

ValidationResult
Type alias for validation results using SchemaErrors