{"id":25293915,"url":"https://github.com/pgimalac/rust-graphviz","last_synced_at":"2025-10-28T01:31:58.575Z","repository":{"id":52976470,"uuid":"283424555","full_name":"pgimalac/rust-graphviz","owner":"pgimalac","description":"FFI bindings for the graphviz C lib generated with rust-bindgen.","archived":false,"fork":false,"pushed_at":"2021-09-14T08:52:41.000Z","size":8,"stargazers_count":5,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-21T08:19:40.860Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgimalac.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":"2020-07-29T07:03:07.000Z","updated_at":"2023-10-26T19:48:12.000Z","dependencies_parsed_at":"2022-08-30T23:42:54.580Z","dependency_job_id":null,"html_url":"https://github.com/pgimalac/rust-graphviz","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/pgimalac%2Frust-graphviz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgimalac%2Frust-graphviz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgimalac%2Frust-graphviz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgimalac%2Frust-graphviz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgimalac","download_url":"https://codeload.github.com/pgimalac/rust-graphviz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238579782,"owners_count":19495551,"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-02-13T01:56:17.479Z","updated_at":"2025-10-28T01:31:58.273Z","avatar_url":"https://github.com/pgimalac.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Description\nFFI bindings for the [Graphviz C library](https://graphviz.org/) generated with [Rust-bindgen](https://github.com/rust-lang/rust-bindgen). Very unsafe and not very usable in my opinion.\n\n### Other similar crates\nI discovered that the [graphviz-sys crate](https://crates.io/crates/graphviz-sys) (which is almost exactly the same as this crate) existed when I decided to publish this crate on [crates.io](https://crates.io/). Nevertheless I decided to publish it since I'd like (one day) to crate safe API bindings for the graphviz library. Any help with that would be appreciated.\n\n### How to use\nOne example of use of the graphviz C library (from [this document](https://www.graphviz.org/pdf/libguide.pdf), although slightly modified) is\n\n```C\n#include \u003cgraphviz/gvc.h\u003e\n\nint main(int argc, char**argv){\n    FILE *fp;\n    if (argc \u003e 1)\n        fp = fopen(argv[1], \"r\");\n    else\n        fp = stdin;\n\n    GVC_t *gvc = gvContext();\n    Agraph_t *g = agread(fp, 0);\n\n    gvLayout(gvc, g, \"dot\");\n    gvRender(gvc, g, \"plain\", stdout);\n\n    gvFreeLayout(gvc, g);\n    agclose(g);\n\n    return gvFreeContext(gvc);\n}\n```\n\nA similar Rust code would be\n```Rust\nuse graphviz_ffi::{\n    agclose, agread, fopen, gvContext, gvFreeContext, gvFreeLayout, gvLayout, gvRender, stdin,\n    stdout,\n};\n\nmacro_rules! to_c_string {\n    ($str:expr) =\u003e {\n        std::ffi::CString::new($str).unwrap().as_ptr()\n    };\n}\n\nfn main() {\n    unsafe {\n        let fp = match std::env::args().nth(1) {\n            Some(path) =\u003e fopen(to_c_string!(path), to_c_string!(\"r\")),\n            None =\u003e stdin,\n        };\n\n        let gvc = gvContext();\n        let g = agread(fp as _, 0 as _);\n\n        gvLayout(gvc, g, to_c_string!(\"dot\"));\n        gvRender(gvc, g, to_c_string!(\"plain\"), stdout);\n\n        gvFreeLayout(gvc, g);\n        agclose(g);\n\n        std::process::exit(gvFreeContext(gvc))\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgimalac%2Frust-graphviz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgimalac%2Frust-graphviz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgimalac%2Frust-graphviz/lists"}