Skip to content

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