Repository navigation
v0.4.0
Zefir 0.4.0 adds validator: validation rules declared on your structs.
validator
zefir-validator checks values against rules declared next to the struct.
pub const field_ruleslists the rules of each field,validateSelfchecks across fields, andv.customadds a predicate of your own.v.checkreturns the first violation without allocating;v.checkAllcollects them all, at most 100. A violation has a code, a message and a path such asitems[2].name.- A rule that does not fit its field is a compile error, and so are two rules in one tuple that no value can pass, such as
v.min(10)withv.max(5). - 96 rules in eight groups: common (
equals,oneOf,empty, …), numbers (min,max,range,positive,divisibleBy,finite, …), lists (minItems,maxItems,uniqueItems,uniqueBy,containsAll,containsNone,each), strings (minLength,maxLength,notBlank,alpha,contains,strongPassword, …), formats (email,httpUrl,fqdn,ip,port,decimal, …), encodings (json,jwt,base64,semVer,mimeType, colors, …), identifiers (uuid,iban,bic,creditCard,isbn,ean,btcAddress,ethereumAddress, …) and dates (date,rfc3339,iso8601,minDate,maxDate,militaryTime). Most rules have a public predicate, such asv.isEmail(s). .withMessagesets a message, with placeholders.
See the validator guide. From this release on, the behaviour of a shipped rule is a contract: see Compatibility in the guide.
If you tried the early preview in the v0.3.0 tag: two rules in one tuple that no value can pass are now a compile error.
Other changes
- log: the queue's detectors tell a lost wake-up from a slow thread (#32).
zig fetch --save git+https://github.com/vkiryakov/zefir#v0.4.0const zefir = b.dependency("zefir", .{ .target = target, .optimize = optimize });
// in your module's .imports:
.{ .name = "validator", .module = zefir.module("zefir-validator") },Until 1.0, breaking changes may happen in any minor release.