Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API improvements #115

Merged
merged 12 commits into from
Apr 15, 2022
Merged

API improvements #115

merged 12 commits into from
Apr 15, 2022

Conversation

anweiss
Copy link
Owner

@anweiss anweiss commented Mar 24, 2022

Addresses #105 and #114

@anweiss anweiss self-assigned this Mar 24, 2022
@anweiss anweiss added bug Something isn't working enhancement New feature or request labels Mar 24, 2022
@anweiss anweiss added this to the v1.0.0 milestone Mar 24, 2022
@anweiss
Copy link
Owner Author

anweiss commented Mar 25, 2022

@itamarst FYSA, this PR introduces some API improvements per #105 so you can now do something like

let cddl_schema = CDDL::from_slice(
  r#"
    foo = {
      bar: tstr
    }
  "#.as_bytes(),
)
.unwrap();

let documents = [r#"{ "bar": "foo" }"#, r#"{ "bar": "foo2" }"#];

documents
  .iter()
  .all(|doc| cddl_schema.validate(doc.as_bytes(), None).is_ok());

Let me know what you think

@itamarst
Copy link
Contributor

I can probably create a branch off of your branch, will try that.

@itamarst
Copy link
Contributor

That is, create a branch of pycddl that uses branch of cddl, to try the new API.

@itamarst
Copy link
Contributor

I tested CDDL::from_slice with my current approach of parsing the schema for every validation. It works, simplified the code slightly.

@itamarst
Copy link
Contributor

(The lifetime requirements is still making interop with PyO3 hard, though, since it's explicitly not supported: PyO3/pyo3#502. So #104 is still blocker on keeping pre-parsed CDDL around.)

@itamarst
Copy link
Contributor

@anweiss
Copy link
Owner Author

anweiss commented Mar 30, 2022

Thanks for testing! Yea, I'll be working through #104 once I get this PR finished up.

@anweiss anweiss marked this pull request as ready for review April 15, 2022 15:35
@anweiss anweiss merged commit b91f289 into main Apr 15, 2022
@anweiss anweiss deleted the api-improvements branch April 15, 2022 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants