optres


Nameoptres JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/kagemeka/optres#readme
SummaryYet another Rust's Option<T> and Result<T, E> simple implementation in Python.
upload_time2023-02-09 13:09:38
maintainer
docs_urlNone
authorkagemeka
requires_python>=3.10,<4.0
licenseApache-2.0
keywords rust option result
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# optres

`Yet another Rust's Option<T> and Result<T, E> simple implementation in Python.`

[![Python package][ci-badge]][ci-url]
[![PyPI version][pypi-badge]][pypi-url]
[![License: MIT][license-badge]][license-url]
[![pre-commit][pre-commit-badge]][pre-commit-url]
[![Github pages][gh-pages-badge]][gh-pages-url]

[ci-badge]: https://github.com/kagemeka/optres/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/kagemeka/optres/actions/workflows/ci.yml
[pre-commit-badge]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
[pre-commit-url]: https://github.com/pre-commit/pre-commit
[license-badge]: https://img.shields.io/badge/License-Apache2.0-green.svg
[license-url]: https://opensource.org/licenses/Apache2.0
[pypi-badge]: https://badge.fury.io/py/optres.svg
[pypi-url]: https://badge.fury.io/py/optres
[gh-pages-badge]: https://github.com/kagemeka/optres/actions/workflows/pages/pages-build-deployment/badge.svg
[gh-pages-url]: https://kagemeka.github.io/optres

## Installation

```bash
python3 -m pip install -U optres
```

## Example

```py
from optres import unwrap, Result, Err, is_ok, is_err, unwrap_err
from typing import LiteralString


def return_result(x: int | None) -> Result[int, LiteralString]:
    return Err("not int") if x is None else x


def example() -> None:
    a: int | None = 1
    c: int = unwrap(a)
    print(c)
    assert is_ok(return_result(a))
    a = None
    # unwrap(a) # error := panic in Rust.
    may_be_err = return_result(a)
    assert is_err(may_be_err)
    print(unwrap_err(may_be_err))


if __name__ == "__main__":
    example()

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kagemeka/optres#readme",
    "name": "optres",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "rust,option,result",
    "author": "kagemeka",
    "author_email": "kagemeka1@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c9/e8/225ecf246eedcfd1a149fbbf87d40b2a826a79c649abec52015ab11629ff/optres-0.1.0.tar.gz",
    "platform": null,
    "description": "\n# optres\n\n`Yet another Rust's Option<T> and Result<T, E> simple implementation in Python.`\n\n[![Python package][ci-badge]][ci-url]\n[![PyPI version][pypi-badge]][pypi-url]\n[![License: MIT][license-badge]][license-url]\n[![pre-commit][pre-commit-badge]][pre-commit-url]\n[![Github pages][gh-pages-badge]][gh-pages-url]\n\n[ci-badge]: https://github.com/kagemeka/optres/actions/workflows/ci.yml/badge.svg\n[ci-url]: https://github.com/kagemeka/optres/actions/workflows/ci.yml\n[pre-commit-badge]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white\n[pre-commit-url]: https://github.com/pre-commit/pre-commit\n[license-badge]: https://img.shields.io/badge/License-Apache2.0-green.svg\n[license-url]: https://opensource.org/licenses/Apache2.0\n[pypi-badge]: https://badge.fury.io/py/optres.svg\n[pypi-url]: https://badge.fury.io/py/optres\n[gh-pages-badge]: https://github.com/kagemeka/optres/actions/workflows/pages/pages-build-deployment/badge.svg\n[gh-pages-url]: https://kagemeka.github.io/optres\n\n## Installation\n\n```bash\npython3 -m pip install -U optres\n```\n\n## Example\n\n```py\nfrom optres import unwrap, Result, Err, is_ok, is_err, unwrap_err\nfrom typing import LiteralString\n\n\ndef return_result(x: int | None) -> Result[int, LiteralString]:\n    return Err(\"not int\") if x is None else x\n\n\ndef example() -> None:\n    a: int | None = 1\n    c: int = unwrap(a)\n    print(c)\n    assert is_ok(return_result(a))\n    a = None\n    # unwrap(a) # error := panic in Rust.\n    may_be_err = return_result(a)\n    assert is_err(may_be_err)\n    print(unwrap_err(may_be_err))\n\n\nif __name__ == \"__main__\":\n    example()\n\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Yet another Rust's Option<T> and Result<T, E> simple implementation in Python.",
    "version": "0.1.0",
    "split_keywords": [
        "rust",
        "option",
        "result"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ce1da55dc35ea20d0d295ada7512e3cba4656798d23a8182ffa029223a1dd3b",
                "md5": "74b319ab08bcde68e5c8f55899a064b6",
                "sha256": "fc3e125ccc4693ed3f0a9a5e3004f309c8e8b7926fc736189732209ccd61ac6a"
            },
            "downloads": -1,
            "filename": "optres-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "74b319ab08bcde68e5c8f55899a064b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 7500,
            "upload_time": "2023-02-09T13:09:36",
            "upload_time_iso_8601": "2023-02-09T13:09:36.491376Z",
            "url": "https://files.pythonhosted.org/packages/9c/e1/da55dc35ea20d0d295ada7512e3cba4656798d23a8182ffa029223a1dd3b/optres-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9e8225ecf246eedcfd1a149fbbf87d40b2a826a79c649abec52015ab11629ff",
                "md5": "ca8ec3f28ce7b85e6d3d365125d78718",
                "sha256": "4266feb7dec9e35c344a284d6b9b53ab353e2424f93a302b7ef2217de7602005"
            },
            "downloads": -1,
            "filename": "optres-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ca8ec3f28ce7b85e6d3d365125d78718",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 7138,
            "upload_time": "2023-02-09T13:09:38",
            "upload_time_iso_8601": "2023-02-09T13:09:38.933342Z",
            "url": "https://files.pythonhosted.org/packages/c9/e8/225ecf246eedcfd1a149fbbf87d40b2a826a79c649abec52015ab11629ff/optres-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-09 13:09:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "kagemeka",
    "github_project": "optres#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "optres"
}
        
Elapsed time: 0.09600s