Skip to main content

CompositeValidator

Struct CompositeValidator 

Source
pub struct CompositeValidator<N = SimpleNodeGeometry, L = ()> { /* private fields */ }
Expand description

Composite validator that combines multiple validators

All validators must return Valid for the link to be valid (AND logic). Returns the first error encountered (short-circuits on failure).

Note: Uses Vec<Box<dyn ...>> which allocates. For zero-allocation validation, chain validators manually using ValidationResult::and().

§Example

use slint_node_editor::{
    BasicLinkValidator, CompositeValidator, GeometryCache, LinkValidator,
    NoDuplicatesValidator, SimpleLink, SimpleNodeGeometry,
};

let mut cache = GeometryCache::<SimpleNodeGeometry>::new();
cache.update_node_rect(1, 0.0, 0.0, 100.0, 60.0);
cache.update_node_rect(2, 200.0, 0.0, 100.0, 60.0);
cache.handle_pin_report(3, 1, 2, 100.0, 30.0);
cache.handle_pin_report(4, 2, 1, 0.0, 30.0);
let links = Vec::<SimpleLink>::new();
let validator = CompositeValidator::new().with(NoDuplicatesValidator);

let normalized = slint_node_editor::validate_and_normalize_link(
    4, 3, &cache, &links, 2, &validator,
).unwrap();
assert_eq!((normalized.output_pin_id, normalized.input_pin_id), (3, 4));

Implementations§

Source§

impl<N, L> CompositeValidator<N, L>

Source

pub fn new() -> Self

Create a new empty composite validator

Source

pub fn with<V: LinkValidator<N, L> + 'static>(self, validator: V) -> Self

Add a validator to the composite

Validators are checked in the order they were added. The first validator to return Invalid will short-circuit.

Trait Implementations§

Source§

impl<N, L> Default for CompositeValidator<N, L>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<N, L> LinkValidator<N, L> for CompositeValidator<N, L>

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 Read more

Auto Trait Implementations§

§

impl<N = SimpleNodeGeometry, L = ()> !RefUnwindSafe for CompositeValidator<N, L>

§

impl<N = SimpleNodeGeometry, L = ()> !Send for CompositeValidator<N, L>

§

impl<N = SimpleNodeGeometry, L = ()> !Sync for CompositeValidator<N, L>

§

impl<N = SimpleNodeGeometry, L = ()> !UnwindSafe for CompositeValidator<N, L>

§

impl<N, L> Freeze for CompositeValidator<N, L>
where Vec<Box<dyn LinkValidator<N, L>>>: Freeze,

§

impl<N, L> Unpin for CompositeValidator<N, L>
where Vec<Box<dyn LinkValidator<N, L>>>: Unpin,

§

impl<N, L> UnsafeUnpin for CompositeValidator<N, L>
where Vec<Box<dyn LinkValidator<N, L>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.