{"id":27305386,"url":"https://github.com/krtab/tower_type_steer","last_synced_at":"2025-04-12T03:28:38.341Z","repository":{"id":257811212,"uuid":"868019859","full_name":"krtab/tower_type_steer","owner":"krtab","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-05T09:23:49.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T21:47:14.491Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-10-05T09:05:49.000Z","updated_at":"2024-10-05T09:23:52.000Z","dependencies_parsed_at":"2024-10-05T09:28:59.074Z","dependency_job_id":"6d9628e5-b8e4-4c00-bb88-89a6f0063a36","html_url":"https://github.com/krtab/tower_type_steer","commit_stats":null,"previous_names":["krtab/tower_type_steer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krtab%2Ftower_type_steer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krtab%2Ftower_type_steer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krtab%2Ftower_type_steer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krtab%2Ftower_type_steer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krtab","download_url":"https://codeload.github.com/krtab/tower_type_steer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248511788,"owners_count":21116466,"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":[],"created_at":"2025-04-12T03:28:37.933Z","updated_at":"2025-04-12T03:28:38.335Z","avatar_url":"https://github.com/krtab.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Dispatch request to service by trying to convert to the service's request type.\n\n```rust\nuse futures::future::ready;\nuse serde::Deserialize;\nuse tower::{service_fn, Service, ServiceBuilder, ServiceExt};\nuse tower_type_steer::Converter;\n\n#[derive(Deserialize, Clone)]\nstruct Foo {\n    x: i8,\n    y: i8,\n}\n\n#[derive(Deserialize, Clone)]\nstruct Bar {\n    z: i8,\n}\n\nfn main() {\n    //  impl Service\u003cFoo\u003e\n    let foo_service = service_fn(|foo: Foo| ready(foo.x.checked_add(foo.y).ok_or(\"Overflow\")));\n    //  impl Service\u003cBar\u003e\n    let bar_service = service_fn(|bar: Bar| ready(Ok::\u003c_, \u0026'static str\u003e(bar.z)));\n    let error_service = service_fn(|_: \u0026str| ready(Err::\u003ci8, _\u003e(\"No matching json\")));\n    let mut s = ServiceBuilder::new()\n        .layer(tower_type_steer::serde_conv::json().wrap(foo_service))\n        .layer(tower_type_steer::serde_conv::json().wrap(bar_service))\n        .service(error_service);\n    let res: Result\u003c_, \u0026str\u003e = futures::executor::block_on(async move {\n        let s = s.ready().await?;\n        let res = [\n            // Ok(5) (foo_service)\n            s.call(r#\"{\"x\": 3, \"y\": 2}\"#).await,\n            // Err(\"Overflow\") (foo_service)\n            s.call(r#\"{\"x\": 120, \"y\": 120}\"#).await,\n            // Err(\"Ok(2)\") (bar_service)\n            s.call(r#\"{\"z\": 2}\"#).await,\n            // Err(\"No matching json\") (error_service)\n            s.call(r#\"{}\"#).await,\n        ];\n        Ok(res)\n    });\n    println!(\"{res:?}\");\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrtab%2Ftower_type_steer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrtab%2Ftower_type_steer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrtab%2Ftower_type_steer/lists"}