{"id":18017575,"url":"https://github.com/cakekindel/engsure-rs","last_synced_at":"2025-04-04T15:42:32.844Z","repository":{"id":101433048,"uuid":"266608936","full_name":"cakekindel/engsure-rs","owner":"cakekindel","description":"Model validation that humans can read - pr. \"ensure\"","archived":false,"fork":false,"pushed_at":"2020-05-26T15:33:41.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T01:37:00.085Z","etag":null,"topics":["composable","data-oriented","declarative","fluent","functional","library","model","readable","requirements","rust","validation","validation-library","well-documented"],"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/cakekindel.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":"2020-05-24T19:18:44.000Z","updated_at":"2020-05-28T03:34:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"ab684c6b-debc-46a5-a6dc-1dda543db57d","html_url":"https://github.com/cakekindel/engsure-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakekindel%2Fengsure-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakekindel%2Fengsure-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakekindel%2Fengsure-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakekindel%2Fengsure-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cakekindel","download_url":"https://codeload.github.com/cakekindel/engsure-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208015,"owners_count":20901568,"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":["composable","data-oriented","declarative","fluent","functional","library","model","readable","requirements","rust","validation","validation-library","well-documented"],"created_at":"2024-10-30T04:23:39.067Z","updated_at":"2025-04-04T15:42:32.820Z","avatar_url":"https://github.com/cakekindel.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# engsure\n## Model validation that humans can read\n_pronounced like \"ensure\"_\n\n## Table of Contents\n- [How to Use](#how-to-use)\n  - [API Docs](#api-docs)\n  - [Best Practices](#best-practices)\n  - [Simple Example](#simple-example)\n- [How to Contribute](#how-to-contribute)\n\n## How to Use\n\n### API Docs\nTODO\n\n### Best Practices\nHow to get the most out of `engsure`\n\n#### provide descriptive labels with `aka` as much as possible\nThis makes your error messages significantly more valuable, by having a human-readable name for the item being validated.\n\n#### limit `use`s from `engsure` as much as possible\nthe API was designed with concise names, that way you can use fully-qualified names rather than bringing them directly into scope. \n\n#### implement the `engsure::Validate` trait\nThis has 2 benefits:\n  1. it lets you separately define `engsure` functionality from the rest of your struct's functionality\n  2. by returning the `engsure::Ctx\u003cMyStruct\u003e`, you have more flexibility on what you can do _after_ validating.\n      - _e.g._ chain validation of other instances with `and_then` (see the `main` fn in [Simple Example](#simple-example))\n\n### Simple Example\n```rust\nstruct Person {\n  pub first_name: String,\n  pub last_name: String,\n  pub phone_number: (i8, i8, i8),\n  pub email: Option\u003cString\u003e\n}\n\nimpl Person {\n  pub fn name(\u0026self) -\u003e String {\n    format!(\"{} {}\", self.first_name, self.last_name)\n  }\n}\n\nimpl engsure::Validate for Person {\n  use engsure::opt::{is_some};\n  use engsure::tup::{is_phone_number};\n  use engsure::txt::{is_email_address};\n\n  pub fn validate(self) -\u003e engsure::Ctx\u003cPerson\u003e {\n    engsure::that(self)\n      .aka(self.name())\n      .has(|p| p.phone_number)\n      .that(is_phone_number)\n      .and()\n      .has(|p| p.email)\n      .when(is_some)\n      .that(is_email_address)\n      .done()\n  }\n}\n\npub fn main() -\u003e engsure::Result {\n  let bob = Person {\n    first_name: \"Bob\",\n    last_name: \"Builder\",\n    phone_number: (505, 555, 1234),\n    email: Some(\"bob.t.builder@yeswecan.org\")\n  }\n  \n  let sally = Person {\n    first_name: \"Sally\",\n    last_name: \"Jackson\",\n    phone_number: (602, 111, 2222),\n    email: Some(\"forgot-dotcom@gmail\")\n  };\n\n  // The following errors with:\n  //   engsure::TextError { msg: \"invalid email of 'forgot-dotcom@gmail' in 'Sally Jackson'\", .. }\n  bob.validate()\n    .and_then(|_| sally.validate())\n    .done()\n}\n```\n\n## How to Contribute\nTODO\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcakekindel%2Fengsure-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcakekindel%2Fengsure-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcakekindel%2Fengsure-rs/lists"}