{"id":19334327,"url":"https://github.com/sticnarf/iprange-rs","last_synced_at":"2025-04-10T03:53:45.234Z","repository":{"id":24950074,"uuid":"102843771","full_name":"sticnarf/iprange-rs","owner":"sticnarf","description":"A Rust library for managing IP ranges","archived":false,"fork":false,"pushed_at":"2022-05-05T03:14:04.000Z","size":138,"stargazers_count":45,"open_issues_count":3,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T03:53:38.383Z","etag":null,"topics":[],"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/sticnarf.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":"2017-09-08T09:23:55.000Z","updated_at":"2025-03-19T15:45:05.000Z","dependencies_parsed_at":"2022-08-07T11:01:30.000Z","dependency_job_id":null,"html_url":"https://github.com/sticnarf/iprange-rs","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sticnarf%2Fiprange-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sticnarf%2Fiprange-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sticnarf%2Fiprange-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sticnarf%2Fiprange-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sticnarf","download_url":"https://codeload.github.com/sticnarf/iprange-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154998,"owners_count":21056542,"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":"2024-11-10T02:58:23.662Z","updated_at":"2025-04-10T03:53:45.209Z","avatar_url":"https://github.com/sticnarf.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iprange-rs\n\n[![Crates Version](https://img.shields.io/crates/v/iprange.svg)](https://crates.io/crates/iprange)\n[![CI](https://github.com/sticnarf/iprange-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/sticnarf/iprange-rs/actions/workflows/ci.yml)\n\n`iprange-rs` is a Rust library for managing IP ranges. \n\nIt provides fast adding and removing operations.\n\nIt also provides `merge`, `intersect` and `exclude` methods \nthat enable you to manipulate it like a set.\n\nOf course, you can test whether an IP address is in an `IpRange`.\n\n**See the [documentation](https://docs.rs/iprange/) for details.**\n\n## Example\n\n```rust\nextern crate iprange;\nextern crate ipnet;\n\nuse std::net::Ipv4Addr;\nuse iprange::IpRange;\nuse ipnet::Ipv4Net;\n\nfn main() {\n    let ip_range: IpRange\u003cIpv4Net\u003e = [\"10.0.0.0/8\", \"172.16.0.0/16\", \"192.168.1.0/24\"]\n        .iter()\n        .map(|s| s.parse().unwrap())\n        .collect();\n\n    assert!(ip_range.contains(\u0026\"172.16.32.1\".parse::\u003cIpv4Addr\u003e().unwrap()));\n    assert!(ip_range.contains(\u0026\"192.168.1.1\".parse::\u003cIpv4Addr\u003e().unwrap()));\n}\n```\n\n## Serde support\n\nSerde support is optional and disabled by default. To enable, use the feature `serde`.\n\n```toml\n[dependencies]\niprange = { version = \"0.6\", features = [\"serde\"] }\n```\n\n## Benchmark\n\n`iprange-rs` stores the IP networks in a radix trie.\nThis allows us to store and lookup IP information quickly.\n\nThere is no Rust alternative to this crate, so I decide to compare it to those written in Go.\n\nOn my computer, here is the [benchmark](https://github.com/smallnest/iprange) result for Go implementations: \n\n```\nBenchmarkIPv4Contains-8                   500000              2545 ns/op\nBenchmarkIPv4Contains_Radix-8             200000              6960 ns/op\nBenchmarkIPv4Contains_NRadix-8           1000000              1828 ns/op\nBenchmarkIPv6Contains-8                   300000              3989 ns/op\nBenchmarkIPv6Contains_Radix-8             200000              6818 ns/op\nBenchmarkIPv6Contains_NRadix-8            500000              3039 ns/op\n```\n\nAnd below are the results of the equivalent Rust program using `iprange-rs`:\n\n```\ntest test_ipv4_against_go             ... bench:         751 ns/iter (+/- 5)\ntest test_ipv6_against_go             ... bench:       2,500 ns/iter (+/- 20)\n```\n\nWe can see the Rust one using `iprange-rs` is **2.4x faster** than\neven the fastest Go implementation when dealing with IPv4 and is 1.2x faster with IPv6.\n\n## License\n\n`iprange-rs` is licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsticnarf%2Fiprange-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsticnarf%2Fiprange-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsticnarf%2Fiprange-rs/lists"}