{"id":18535788,"url":"https://github.com/ohkami-rs/serdev","last_synced_at":"2025-04-08T04:16:02.302Z","repository":{"id":254639755,"uuid":"845056712","full_name":"ohkami-rs/serdev","owner":"ohkami-rs","description":"SerdeV - Serde with Validation","archived":false,"fork":false,"pushed_at":"2025-03-04T07:11:58.000Z","size":70,"stargazers_count":58,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-01T03:15:02.542Z","etag":null,"topics":["derive","no-std","rust","serde","validation"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ohkami-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-20T13:51:37.000Z","updated_at":"2025-03-31T11:03:36.000Z","dependencies_parsed_at":"2024-12-25T01:15:30.481Z","dependency_job_id":null,"html_url":"https://github.com/ohkami-rs/serdev","commit_stats":null,"previous_names":["ohkami-rs/serdev"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fserdev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fserdev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fserdev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fserdev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohkami-rs","download_url":"https://codeload.github.com/ohkami-rs/serdev/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247773719,"owners_count":20993639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["derive","no-std","rust","serde","validation"],"created_at":"2024-11-06T19:27:30.867Z","updated_at":"2025-04-08T04:16:02.278Z","avatar_url":"https://github.com/ohkami-rs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eSerdeV\u003c/h1\u003e\n    SerdeV - Serde with Validation\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n- Just a wrapper of \u003ca href=\"https://github.com/serde-rs/serde\" target=\"_blank\"\u003eSerde\u003c/a\u003e and 100% compatible\n- Declarative validation in deserialization by `#[serde(validate = \"...\")]`\n\n\u003cdiv align=\"right\"\u003e\n    \u003ca href=\"https://github.com/ohkami-rs/serdev/blob/main/LICENSE\" target=\"_blank\"\u003e\n        \u003cimg alt=\"License\" src=\"https://img.shields.io/crates/l/ohkami.svg\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/ohkami-rs/serdev/actions\" target=\"_blank\"\u003e\n        \u003cimg alt=\"CI status\" src=\"https://github.com/ohkami-rs/serdev/actions/workflows/CI.yml/badge.svg\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/serdev\" target=\"_blank\"\u003e\n        \u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/serdev\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n\n## Example\n\n```toml\n[dependencies]\nserdev     = \"0.2\"\nserde_json = \"1.0\"\n```\n\n```rust\nuse serdev::{Serialize, Deserialize};\n\n#[derive(Serialize, Deserialize, Debug)]\n#[serde(validate = \"Self::validate\")]\nstruct Point {\n    x: i32,\n    y: i32,\n}\n\nimpl Point {\n    fn validate(\u0026self) -\u003e Result\u003c(), impl std::fmt::Display\u003e {\n        if self.x * self.y \u003e 100 {\n            return Err(\"x * y must not exceed 100\")\n        }\n        Ok(())\n    }\n}\n\nfn main() {\n    let point = serde_json::from_str::\u003cPoint\u003e(r#\"\n        { \"x\" : 1, \"y\" : 2 }\n    \"#).unwrap();\n\n    // Prints point = Point { x: 1, y: 2 }\n    println!(\"point = {point:?}\");\n\n    let error = serde_json::from_str::\u003cPoint\u003e(r#\"\n        { \"x\" : 10, \"y\" : 20 }\n    \"#).unwrap_err();\n\n    // Prints error = x * y must not exceed 100\n    println!(\"error = {error}\");\n}\n```\n\nOf course, you can use it in combination with some validation tools like \u003ca href=\"https://crates.io/crates/validator\" target=\"_blank\"\u003evalidator\u003c/a\u003e! ( \u003ca href=\"https://github.com/ohkami-rs/serdev/blob/main/examples/examples/validator.rs\" target=\"_blank\"\u003efull example\u003c/a\u003e )\n\n\n## Attribute\n\n- `#[serde(validate = \"function\")]`\n\n  Automatically validate by the `function` in deserialization. The `function` must be callable as `fn(\u0026self) -\u003e Result\u003c(), impl Display\u003e`.\\\n  Errors are converted to a `String` internally and passed to `serde::de::Error::custom`.\n\n- `#[serde(validate(by = \"function\", error = \"Type\"))]`\n\n  Using given `Type` for validation error without internal conversion. The `function` must explicitly return `Result\u003c(), Type\u003e`.\\\n  This may be preferred when you need better performance _even in error cases_.\\\n  For **no-std** use, this is the only way supported.\n\nBoth `\"function\"` and `\"Type\"` accept path like `\"crate::util::validate\"`.\n\nAdditionally, `#[serdev(crate = \"path::to::serdev\")]` is supported for reexport from another crate.\n\n\n## License\n\nLicensed under MIT LICENSE ( [LICENSE](https://github.com/ohkami-rs/serdev/blob/main/LICENSE) or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT) ).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohkami-rs%2Fserdev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohkami-rs%2Fserdev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohkami-rs%2Fserdev/lists"}