GithubHelp home page GithubHelp logo

dermetfan / zig-validate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mov-rax/zig-validate

0.0 0.0 0.0 4.15 MB

A type validation library for writing a zero-cost, declarative, understandable, generic code in zig.

License: MIT License

Zig 100.00%

zig-validate's Introduction

Zig-Validate

A type validation library for writing a zero-cost, declarative, understandable, generic code in zig.


Note: minimum zig version 0.10.0 using the stage2 compiler is required to use zig-validate.

For many projects, the desired method of creating generic types is to do either of the following:

  1. Use a concrete type that results in code bloat due to repetitiveness.
  2. Use a concrete type that uses composition and hand-rolled vtables to emulate interfaces from other languages and incurring a runtime cost.
  3. Use an anytype and have the caller of the function hope that sufficient documentation was written or comb through the codebase to see what methods are required.
  4. Hand-roll type validation for a specific type every time a generic type is required.
  5. Use a switch to hand-roll static dispatch in zig due to lack of function overloading.

If only there was a way to have traits or interfaces in zig without having to waste time in repetitively writing error-prone imperative code for type validation...

Oh wait, now there is!

Zig-Validate provides a non-obtrusive solution to all of those problems with a simple-to-use interface and a rich error reporting solution for relaying to the user issues with non-conforming generic types.

The following is a taste of the error-reporting capabilities of Zig-Validate:


Static and Dynamic dispatch?

Yes, static and dynamic dispatch implementations are available in zig-validate with two different flavors of static dispatch!

For your statically-dispatched needs there is the more vanilla validate.static, and the more powerful and ergonomic validate.staticFnOverride that supports function overloading!

If you require a more dynamic approach, there exists validate.dynamic to easily generate vtables!

For more information on type validation using zig-validate, go to the static dispatch and/or dynamic dispatch page(s).

What if I have an existing application/library that would require too much refactoring to use the output type?

If you have a codebase that would require a large amount of refactoring to use the output type, then you can simply not use the output type. Due to the unobtrusive nature of zig-validate, you can simply do _ = validate.static(Target, Validator) and still use the type validation power of the library. The only downside of discarding the output type is a generic trait/interface that is used to interact with generic Target types.

That's pretty much all that there is needed to know in order to use zig-validate! Now, stop writing boilerplate and bear witness to the power of zig-validate.

Still unsure on how to use zig-validate? Then Read zig-validate's documentation!

zig-validate's People

Contributors

mov-rax avatar tensorush avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.