error refinement-violated
Константа нарушает предикат уточнённого типа.
What it means#
A refined type T where P carries the invariant P (§3.6). When a literal constant is used where such a type is expected, the compiler checks P at compile time and rejects values that do not satisfy it. Values that are only known at run time are obtained with Port.from(x), which returns Port | InvalidValue.
Example#
type Port = u16 where 1..=65535
fn main() {
let p: Port = 0 // <- refinement-violated
}error
refinement-violated
How to fix#
type Port = u16 where 1..=65535
fn main() {
let p: Port = 8080
}Use a value that satisfies the predicate, or construct the value at run time with Port.from(x) and handle InvalidValue.