{"id":16864720,"url":"https://github.com/38/plumber-rs","last_synced_at":"2025-03-18T16:44:05.056Z","repository":{"id":57656469,"uuid":"144232994","full_name":"38/plumber-rs","owner":"38","description":"The Rust Supporting Library for Plumber General Purpose dataflow Framework","archived":false,"fork":false,"pushed_at":"2018-10-12T16:43:51.000Z","size":245,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T07:51:36.407Z","etag":null,"topics":["dataflow-programming","plumber","rust-lang","rust-server"],"latest_commit_sha":null,"homepage":"https://plumberserver.com/index.html#plumber_rs_docs/plumber_rs","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/38.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}},"created_at":"2018-08-10T03:38:22.000Z","updated_at":"2018-10-12T16:43:53.000Z","dependencies_parsed_at":"2022-08-26T05:51:42.340Z","dependency_job_id":null,"html_url":"https://github.com/38/plumber-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/38%2Fplumber-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/38%2Fplumber-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/38%2Fplumber-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/38%2Fplumber-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/38","download_url":"https://codeload.github.com/38/plumber-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244264507,"owners_count":20425538,"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":["dataflow-programming","plumber","rust-lang","rust-server"],"created_at":"2024-10-13T14:43:38.720Z","updated_at":"2025-03-18T16:44:05.026Z","avatar_url":"https://github.com/38.png","language":"Rust","readme":"# plumber-rs\n\nThis is the Rust library that provides the connection between [Plumber Dataflow Framework](https://github.com/38/plumber)\nand the Rust Programming language.\n\nWith this library, the servlet can be written in Rust programming language. \nUnlike C and C++, the Rust servlet needs a runtime environment, which can be setup with the Rust Servlet Loader `language/rust`.\n\n## How to build a Rust servlet\n\nWith Cargo you should be able to create a servlet with Rust quite easily.\n\n**Step 1** you should create a library crate with cargo\n\n```\ncargo init hello-rust --lib\n```\n\n**Step 2** we should change the `Cargo.toml`. \n\nWe need to make sure the cargo can produce a dynamic library that can be loaded by Plumber Rust Servlet Loader.\nAlso, we need to add some depdendencies to the crate.\n\n```\n[lib]\nname = \"hello-rust\"\ncrate-type= [\"cdylib\"]\n\n[dependencies]\nplumber-rs = {git = \"https://github.com/38/plumber-rs.git\"}\n```\n\n**Step 3** Create the servlet object.\n\nIn Rust, a servlet is actually a trait. For the sync servlet, we can implemnet the trait `plumber_rs::servlet::sync_servlet`.\n\n```rust\nuse plumber_rs::servlet::{SyncServlet, Unimplemented, ServletMode, ServletFuncResult, Bootstrap, success, fail};\nuse plumber_rs::protocol::{ProtocolModel, Untyped};\n\nstruct HelloServlet {}\n\nimpl SyncServlet for HelloServlet {\n    no_protocol!();\n    fn init(\u0026mut self, _args:\u0026[\u0026str], _model:\u0026mut Self::ProtocolType) -\u003e ServletFuncResult \n    {\n        plumber_log!(N \"Hello World\");\n        return success();\n    }\n    fn exec(\u0026mut self, _ti:TypeInstanceObject) -\u003e ServletFuncResult  { success(); }\n    fn cleanup(\u0026mut self) -\u003e ServletFuncResult { success(); }\n}\n\n```\n\n**Step 4** Create the bootstrap type and export the entry point\n\n```rust\nstruct BootstrapType{}\n\nimpl Bootstrap for BootstrapType {\n    type SyncServletType = HelloServlet;\n    type AsyncServletType = Unimplemented;\n    fn get(_args:\u0026[\u0026str]) -\u003e BootstrapResult\u003cSelf\u003e\n    {\n        return Self::make_sync(HelloServlet{});\n    }\n}\n\nexport_bootstrap!(BootstrapType);\n```\n\n**Step 5** Build the servlet\n\nTo build the servlet successfully you should have Plumber installed. See the plumber install instruction at [here](https://plumberserver.com/index.html#documentation.compile).\n\nIf you have Plumber installed under the `/`, `/usr/`, `/usr/local` or your home directory, you should be able to compile the servlet successfully.\nIf you have some other install path, please specify the environment root with `ENVROOT` envrionment variable.\n\nAnd to build the servlet, you can simple run `cargo build`\n\n```bash\ncargo build\n```\n\n# Full Servlet Code\n\n```rust\n#[macro_use]\nextern crate plumber_rs;\nextern crate libc;\n\nuse plumber_rs::servlet::{SyncServlet, Unimplemented, ServletFuncResult, Bootstrap, BootstrapResult, sucess, fail};\nuse plumber_rs::protocol::{ProtocolModel, Untyped};\n\nstruct HelloServlet {}\n\nimpl SyncServlet for HelloServlet {\n    no_protocol!();\n    fn init(\u0026mut self, _args:\u0026[\u0026str], _model:\u0026mut Self::ProtocolType) -\u003e ServletFuncResult \n    {\n        plumber_log!(N \"Hello World\");\n        return sucess();\n    }\n    fn exec(\u0026mut self, _model:Self::DataModelType) -\u003e ServletFuncResult  { sucess() }\n    fn cleanup(\u0026mut self) -\u003e ServletFuncResult { sucess() }\n}\n\nstruct BootstrapType{}\n\nimpl Bootstrap for BootstrapType {\n    type SyncServletType = HelloServlet;\n    type AsyncServletType = Unimplemented;\n    fn get(_args:\u0026[\u0026str]) -\u003e BootstrapResult\n    {\n        return Self::make_sync(HelloServlet{});\n    }\n}\n\nexport_bootstrap!(BootstrapType);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F38%2Fplumber-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F38%2Fplumber-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F38%2Fplumber-rs/lists"}