Skip to content

[Rust] Release 0.29.0

Latest
Compare
Choose a tag to compare
@Stranger6667 Stranger6667 released this 08 Feb 19:17
· 7 commits to master since this release
rust-v0.29.0
44e787f

Breaking Changes

  • All builder methods on ValidationOptions now take ownership of self instead of &mut self.
    This change enables better support for non-blocking retrieval of external resources during the process of building a validator.
    Update your code to chain the builder methods instead of reusing the options instance:

    // Before (0.28.x)
    let mut options = jsonschema::options();
    options.with_draft(Draft::Draft202012);
    options.with_format("custom", my_format);
    let validator = options.build(&schema)?;
    
    // After (0.29.0)
    let validator = jsonschema::options()
        .with_draft(Draft::Draft202012)
        .with_format("custom", my_format)
        .build(&schema)?;
  • The Retrieve trait's retrieve method now accepts URI references as &Uri<String> instead of &Uri<&str>.
    This aligns with the async version and simplifies internal URI handling. The behavior and available methods remain the same, this is purely a type-level change.

    // Before
    fn retrieve(&self, uri: &Uri<&str>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>>
    
    // After
    fn retrieve(&self, uri: &Uri<String>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>>
  • Simplified Registry creation API:

    • Removed RegistryOptions::try_new and RegistryOptions::try_from_resources in favor of Registry::build
    • Removed Registry::try_with_resource_and_retriever - use Registry::options().retriever() instead
    • Registry creation is now consistently done through the builder pattern
    // Before (0.28.x)
    let registry = Registry::options()
        .draft(Draft::Draft7)
        .try_new(
            "http://example.com/schema",
            resource
        )?;
    
    let registry = Registry::options()
        .draft(Draft::Draft7)
        .try_from_resources([
            ("http://example.com/schema", resource)
        ].into_iter())?;
      
    let registry = Registry.try_with_resource_and_retriever(
        "http://example.com/schema",
        resource,
        retriever
    )?;
    
    // After (0.29.0)
    let registry = Registry::options()
        .draft(Draft::Draft7)
        .build([
            ("http://example.com/schema", resource)
        ])?;
    
    let registry = Registry::options()
        .draft(Draft::Draft7)
        .build([
            ("http://example.com/schema", resource)
        ])?;
    
    let registry = Registry::options()
        .retriever(retriever)
        .build(resources)?;

Added

  • Support non-blocking retrieval for external resources during schema resolution via the new resolve-async feature. #385
  • Re-export referencing::Registry as jsonschema::Registry.
  • ValidationOptions::with_registry that allows for providing a predefined referencing::Registry. #682

Performance

  • Significantly improved validator compilation speed by using pointer-based references to schema fragments instead of cloning them during traversal.
  • Faster anchors & sub-resources lookups during validator compilation.