Skip to main content

LinkValidator

Trait LinkValidator 

Source
pub trait LinkValidator<N = SimpleNodeGeometry, L = ()> {
    // Required method
    fn validate(
        &self,
        start_pin: i32,
        end_pin: i32,
        cache: &GeometryCache<N>,
        links: &[L],
    ) -> ValidationResult;
}
Expand description

Trait for custom link validation logic.

Implement this to add custom validation rules for connecting pins. Pass topology rules to validate_and_normalize_link directly or compose several rules with CompositeValidator.

The trait is generic over:

  • N: The node geometry type (defaults to SimpleNodeGeometry)
  • L: The link type for accessing existing links (must implement LinkModel)

§Example

use slint_node_editor::{
    GeometryCache, LinkValidator, NodeGeometry, ValidationResult,
};

struct MyValidator;

impl<N, L> LinkValidator<N, L> for MyValidator
where
    N: NodeGeometry + Copy,
{
    fn validate(
        &self,
        start_pin: i32,
        end_pin: i32,
        _cache: &GeometryCache<N>,
        _links: &[L],
    ) -> ValidationResult {
        // Custom validation logic
        ValidationResult::Valid
    }
}

Required Methods§

Source

fn validate( &self, start_pin: i32, end_pin: i32, cache: &GeometryCache<N>, links: &[L], ) -> ValidationResult

Check if a link between two pins is valid

§Arguments
  • start_pin - ID of the starting pin
  • end_pin - ID of the ending pin
  • cache - Geometry cache for pin information
  • links - Slice of existing links for duplicate/fan-out checks
§Returns

ValidationResult::Valid if the link is allowed, ValidationResult::Invalid(reason) otherwise

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§