Submodules
option
module
- class rustpy.option.Option(*args, **kwds)[source]
Protocol of an optional value.
- and_(_other: Option[_T]) Option[_T] [source]
Returns self if it
is_none()
, otherwise returns other.
- and_then(_function: Callable[[_T], Option[_T2]]) Option[_T2] [source]
Returns self if it
is_none()
, otherwise returns the result of given function on the contained value.
- expect(_message: str) _T [source]
Returns the contained value or raises a
ValueError
with given message if none.
- map(_function: Callable[[_T], _T2]) Option[_T2] [source]
Returns self if it
is_none()
, otherwise applies given function to a contained value.
- map_or(_default: _T2, _function: Callable[[_T], _T2]) _T2 [source]
Returns given default if self
is_none()
, otherwise returns the result of given function on the contained value.
- map_or_else(_default: Callable[[], _T2], _function: Callable[[_T], _T2]) _T2 [source]
Returns the result of given default function if self
is_none()
, otherwise returns the result of given function on the contained value.
- ok_or(_err: _E) _Result[_T, _E] [source]
Returns the contained value wrapped in
rustpy.result.Ok
if selfis_some()
, otherwise returns given value wrapped inrustpy.result.Err
.
- ok_or_else(_function: _t.Callable[[], _E]) _Result[_T, _E] [source]
Returns the contained value wrapped in
rustpy.result.Ok
if selfis_some()
, otherwise returns the result of given function wrapped inrustpy.result.Err
.
- or_else(_function: Callable[[], Option[_T]]) Option[_T] [source]
Returns self if it
is_some()
, otherwise returns the result of the given function.
result
module
- class rustpy.result.Result(*args, **kwds)[source]
- and_(_other: Result[_T2, _E]) Result[_T2, _E] [source]
Returns self if it
is_err()
, otherwise returns other.
- and_then(_other: Callable[[_T], Result[_T2, _E]]) Result[_T2, _E] [source]
Returns self if it
is_err()
, otherwise returns the result of given function on the success value.
- err() _Option[_E] [source]
Returns error value wrapped in
rustpy.option.Some
if selfis_err()
, otherwise returnsrustpy.option.None_
.
- expect(_message: str) _T [source]
Returns the success value or raises a
ValueError
with given message if error.
- expect_err(_message: str) _E [source]
Returns the error value or raises a
ValueError
with given message if success.
- map(_function: Callable[[_T], _T2]) Result[_T2, _E] [source]
Returns self if it
is_err()
, otherwise applies given function to a success value.
- map_err(_function: Callable[[_E], _E2]) Result[_T, _E2] [source]
Returns self if it
is_ok()
, otherwise applies given function to an error value.
- map_or(_default: _T2, _function: Callable[[_T], _T2]) _T2 [source]
Returns given default if self
is_err()
, otherwise returns the result of given function on the success value.
- map_or_else(_default: Callable[[_E], _T2], _function: Callable[[_T], _T2]) _T2 [source]
Returns the result of given default function on the error value if self
is_err()
, otherwise returns the result of given function on the success value.
- ok() _Option[_T] [source]
Returns success value wrapped in
rustpy.option.Some
if selfis_ok()
, otherwise returnsrustpy.option.None_
.
- or_(_other: Result[_T, _E2]) Result[_T, _E2] [source]
Returns self if it
is_ok()
, otherwise returns other.
- or_else(_other: Callable[[_E], Result[_T, _E2]]) Result[_T, _E2] [source]
Returns self if it
is_ok()
, otherwise returns the result of given function on the success value.
primitive
module
- class rustpy.primitive.bool_(_value: bool)[source]
Represents a value, which could only be either true or false. If you cast a bool into an integer, true will be 1 and false will be 0.
- class rustpy.primitive.f32(_value: float)[source]
A 32-bit floating point type (specifically, the “binary32” type defined in IEEE 754-2008).