Git Product home page Git Product logo

valid's People

Contributors

haraldmaida avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

valid's Issues

Calling context.into() does not convert to State type

I'm following the docs and trying to call context.into to get the actual state object. But I just get unknown. Was I supposed to impl Into for my State type? Your docs don't seem to indicate that.

pub struct StreamConstraint;
pub struct StreamState;

impl StreamState {
    pub fn is_stream(val: Option<String>) -> bool {
        if let None = val {
            return false;
        }

        let stream = JsValue::from(val.clone());
        if stream.is_null() || !stream.is_object() {
            return false;
        }
        let emitter_result = serde_json::from_str::<EventEmitter>(val.unwrap().as_str());
        match emitter_result {
            Ok(_) => true,
            _ => false
        }
    }
}

impl<'a> Validate<StreamConstraint, State<&'a StreamState>> for String {
    fn validate(self, context: impl Into<State<&'a StreamState>>, constraint: &StreamConstraint) -> Validation<StreamConstraint, Self> {        
        if context.into().is_stream(Some(&self)) {
            return Validation::success(self);
        }
        Validation::failure(vec![invalid_state("invalid-stream", vec![])])
    }
}

Flat argument list instead of nested tuples for closures in `Validation` methods

Currently the closures in the methods Validation::and_then and Validation::map` get passed nested tuples which can become really ugly with more and more arguments.

We should find a way to flatten the values collected so far by the Validation type, so that the closures either get a list of arguments passed or one flat tuple with all the values.

This will be a breaking change in the API, but I think the advantage outweighs any pain with changing existing implementations.

Validation of constraints `Length` and `CharCount` might panic

The current implementation of Validate for the constraints Length and CharCount might panic. The limits are of type u32 and to perform the checks the limit values are casted to usize. If an actual value does not fit into usize it will panic. This might be the case on 16bit or 8bit targets.

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.