{"id":20847373,"url":"https://github.com/zingerlittlebee/port-selector-rs","last_synced_at":"2025-10-30T06:39:46.101Z","repository":{"id":40387010,"uuid":"487032780","full_name":"ZingerLittleBee/port-selector-rs","owner":"ZingerLittleBee","description":"Select free port --- Rust Library","archived":false,"fork":false,"pushed_at":"2025-08-11T18:53:36.000Z","size":40,"stargazers_count":8,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-09T18:21:11.326Z","etag":null,"topics":["check","port","rust","select"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/port-selector","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/ZingerLittleBee.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-04-29T16:03:33.000Z","updated_at":"2025-07-22T13:24:47.000Z","dependencies_parsed_at":"2024-10-23T18:46:56.984Z","dependency_job_id":"f2c74d74-67e1-4d9f-9264-07ac1114e5d4","html_url":"https://github.com/ZingerLittleBee/port-selector-rs","commit_stats":{"total_commits":42,"total_committers":2,"mean_commits":21.0,"dds":0.09523809523809523,"last_synced_commit":"cdc4d11b69ec647c158ac9fb31e5092799a23f9d"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ZingerLittleBee/port-selector-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZingerLittleBee","download_url":"https://codeload.github.com/ZingerLittleBee/port-selector-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275396026,"owners_count":25457242,"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","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["check","port","rust","select"],"created_at":"2024-11-18T02:19:46.584Z","updated_at":"2025-09-16T09:35:27.051Z","avatar_url":"https://github.com/ZingerLittleBee.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Language : 🇺🇸 English | [🇨🇳 简体中文](./README.zh-CN.md)\n\n\u003ch1 align=\"center\"\u003eport-selector\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n\n[![Build Status](https://img.shields.io/crates/v/port-selector?style=for-the-badge)](https://crates.io/crates/port-selector)\n![Crates Downloads](https://img.shields.io/crates/d/port-selector?style=for-the-badge)\n![Last Commit](https://img.shields.io/github/last-commit/ZingerLittleBee/port-selector-rs?style=for-the-badge)\n\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n\n[![Docs](https://img.shields.io/docsrs/port-selector?style=for-the-badge)](https://docs.rs/port-selector/0.1.6/port_selector/)\n[![GitHub Actions CI](https://img.shields.io/github/actions/workflow/status/ZingerLittleBee/port-selector-rs/test.yml?style=for-the-badge)](https://github.com/ZingerLittleBee/port-selector-rs/actions)\n[![LICENSE](https://img.shields.io/crates/l/port-selector?style=for-the-badge)](./LICENSE)\n\n\u003c/div\u003e\n\n## Overview\n\nport-selector is a rust library that provides functions to **port availability checking**, **port filtering based on conditions** and **occupy specified ports**.\n\n## Installation\n\n1. Get the latest version -\u003e https://crates.io/crates/port-selector\n\n2. Add the dependent\n\n```toml\n[dependencies]\nport-selector = \"0.1.6\"\n```\n\n3. Usage\n\n```rust\nuse port_selector::{is_free, Port};\nuse port_selector::take_up::{random_take_up_port, take_up_port};\n\nfn main() {\n    // check\n    let check_port: Port = 3000;\n    println!(\"is_free({}) = {}\", check_port, is_free(check_port));\n    // take up\n    let used_port = random_take_up_port();\n    println!(\"used_port: {}\", used_port);\n    assert!(take_up_port(5000));\n}\n```\n\n## Goods\n\ntype -\u003e [Port](#port) · [Selector](#selector)\n\nfn -\u003e [is_free_tcp](#is_free_tcp) · [is_free_udp](#is_free_udp) · [is_free](#is_free) · [random_free_tcp_port](#random_free_tcp_port) · [random_free_udp_port](#random_free_udp_port) · [random_free_port](#random_free_port) · [select_from_given_port](#select_from_given_port) · [select_free_port](#select_free_port)\n\nmod (`take_up`) -\u003e [take_up_tcp_port](#take_up_tcp_port) · [take_up_udp_port](#take_up_udp_port) · [take_up_port](#take_up_port) · [random_take_up_tcp_port](#random_take_up_tcp_port) · [random_take_up_udp_port](#random_take_up_udp_port) · [random_take_up_port](#random_take_up_port)\n\n## Documentation\n\n### Port\n\n`u16` type alias\n\n```rust\npub type Port = u16;\n```\n\n### Selector\n\nThe `select_free_port` requires a structure passed in\n\n```rust\npub struct Selector {\n    // Check whether the port is available on TCP.\n    // The default value is true.\n    pub check_tcp: bool,\n    // Check whether the port is available on UDP.\n    // The default value is true.\n    pub check_udp: bool,\n    // Set the range of generated ports, default (0, 65525)\n    pub port_range: (u16, u16),\n    // Maximum number of random times. Default value: 100\n    // If no available port number is found within the maximum random number of loops, None is returned\n    pub max_random_times: u16,\n}\n```\n\n### `is_free_tcp`\n\nCheck whether the port is not used on TCP\n\n```rust\npub fn is_free_udp(port: Port) -\u003e bool\n```\n\n### `is_free_udp`\n\nCheck whether the port is not used on UDP\n\n```rust\npub fn is_free_udp(port: Port) -\u003e bool\n```\n\n### `is_free`\n\nCheck whether the port is not used on TCP and UDP\n\n```rust\npub fn is_free(port: Port) -\u003e bool\n```\n\n### `random_free_tcp_port`\n\nThe system randomly assigns available TCP ports\n\n```rust\npub fn random_free_tcp_port() -\u003e Option\u003cPort\u003e\n```\n\n### `random_free_udp_port`\n\nThe system randomly assigns available UDP ports\n\n```rust\npub fn random_free_udp_port() -\u003e Option\u003cPort\u003e\n```\n\n### `random_free_port`\n\nThe system randomly assigns available TCP and UDP ports\n\n```rust\npub fn random_free_port() -\u003e Option\u003cPort\u003e\n```\n\n### `select_from_given_port`\n\nCheck from `given_port` and return the first available port\n\nReturn if `given_port` is available; Otherwise `given_port += 1` until the port is available\n\n```rust\npub fn select_from_given_port(given_port: Port) -\u003e Option\u003cPort\u003e\n```\n\n### `select_free_port`\n\nGets a matching port based on the `Selector` parameter constraint\n\n```rust\npub fn select_free_port(selector: Selector) -\u003e Option\u003cPort\u003e\n```\n\n---\n\n\u003e The ports occupied by the `take_up` series of methods will be automatically released after the main function call ends.\n\n### `take_up_tcp_port`\n\nOccupy port on tcp\n\n```rust\nfn take_up_tcp_port(port: Port) -\u003e bool\n```\n\n### `take_up_udp_port`\n\nOccupy port on udp\n\n```rust\nfn take_up_udp_port(port: Port) -\u003e bool\n```\n\n### `take_up_port`\n\nOccupy port on tcp \u0026\u0026 udp\n\n```rust\nfn take_up_port(port: Port) -\u003e bool\n```\n\n### `random_take_up_tcp_port`\n\nRandomly occupied port on tcp by the system\n\n```rust\nfn random_take_up_tcp_port() -\u003e Port\n```\n\n### `random_take_up_udp_port`\n\nRandomly occupied port on udp by the system\n\n```rust\nfn random_take_up_udp_port() -\u003e Port\n```\n\n### `random_take_up_port`\n\nRandomly occupy tcp \u0026\u0026 udp ports by the system\n\n```rust\nfn random_take_up_port() -\u003e Port\n```\n\n## Thanks\n\n[portpicker-rs](https://github.com/Dentosal/portpicker-rs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzingerlittlebee%2Fport-selector-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzingerlittlebee%2Fport-selector-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzingerlittlebee%2Fport-selector-rs/lists"}