Skip to content

chore: update validator crate to 0.20.0 and add .idea to .gitignore #44

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lotchouang
Copy link

πŸš€ Summary

  • Ignore IDE files by adding /.idea to .gitignore
  • Upgrade the validator crate from 0.18.0 β†’ 0.20.0 (with derive feature)
  • Adjust Rocket form-validation glue to match Validator 0.20’s API:
    • Import NameBuf from rocket::form::name
    • Build form errors using an owned NameBuf instead of a borrowed Cow

πŸ“ Changes

1. .gitignore

 /target
+/.idea
  • Prevent IDE-specific files from being committed.

2. Cargo.toml

[dependencies]
- validator = { version = "0.18.0", features = ["derive"] }
+ validator = { version = "0.20.0", features = ["derive"] }
  • Bump to the latest validator release for bug fixes and improved derive macros.

3. src/lib.rs

-use rocket::{
-    data::{Data, FromData, Outcome as DataOutcome},
-    form,
-    form::{DataField, FromForm, ValueField},
-    http::Status,
-    outcome::Outcome,
-};
+use rocket::{
+    data::{Data, FromData, Outcome as DataOutcome},
+    form,
+    form::name::NameBuf,
+    form::{DataField, FromForm, ValueField},
+    http::Status,
+    outcome::Outcome,
+};

Form-Validation Impl Update

 impl<'r, T: Validate + FromForm<'r>> FromForm<'r> for Validated<T> {
     // …
     .map(|e| form::Error {
-        name: Some(e.0.into()),
-        kind: form::error::ErrorKind::Validation(std::borrow::Cow::Borrowed(e.0)),
+        name: Some(NameBuf::from(e.0.clone()).into_owned()),
+        kind: form::error::ErrorKind::Validation(e.0),
         value: None,
         entity: form::error::Entity::Value,
     })
     // …
 }

Switch from Cow::Borrowed(&str) to fully owned NameBuf.

Simplify the Validation payload in line with Validator 0.20’s API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant