Welcome to rustpy’s documentation!

Submodules

option module

class rustpy.option.None_

Represents absense of value. Implements Option protocol.

class rustpy.option.Some(value: _T)

Contains a value. Implements Option protocol.

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.

is_none() _bool[source]

Checks if the option does not contain a value.

is_some() _bool[source]

Checks if the option contains a value.

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 self is_some(), otherwise returns given value wrapped in rustpy.result.Err.

ok_or_else(_function: _t.Callable[[], _E]) _Result[_T, _E][source]

Returns the contained value wrapped in rustpy.result.Ok if self is_some(), otherwise returns the result of given function wrapped in rustpy.result.Err.

or_(_other: Option[_T]) Option[_T][source]

Returns self if it is_some(), otherwise returns other.

or_else(_function: Callable[[], Option[_T]]) Option[_T][source]

Returns self if it is_some(), otherwise returns the result of the given function.

unwrap() _T[source]

Returns the contained value.

unwrap_or(_default: _T) _T[source]

Returns the default if self is_none(), otherwise returns the contained value.

unwrap_or_else(_function: Callable[[], _T]) _T[source]

Returns the result of default function if self is_none(), otherwise returns the contained value.

result module

class rustpy.result.Err(value: _E)

Represents the error value. Implements Result protocol.

class rustpy.result.Ok(value: _T)

Represents the success value. Implements Result protocol.

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 self is_err(), otherwise returns rustpy.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.

is_err() _bool[source]

Checks if the result is an error.

is_ok() _bool[source]

Checks if the result is a 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 self is_ok(), otherwise returns rustpy.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.

unwrap() _T[source]

Returns the success value.

unwrap_err() _E[source]

Returns the error value.

unwrap_or(_default: _T) _T[source]

Returns the default if self is_err(), otherwise returns the success value.

unwrap_or_else(_function: Callable[[_E], _T]) _T[source]

Returns the result of default function on error value if self is_err(), otherwise returns 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).

class rustpy.primitive.f64(_value: float)[source]

A 64-bit floating point type (specifically, the “binary64” type defined in IEEE 754-2008).

class rustpy.primitive.i128(_value: int)[source]

The 128-bit signed integer type.

class rustpy.primitive.i16(_value: int)[source]

The 16-bit signed integer type.

class rustpy.primitive.i32(_value: int)[source]

The 32-bit signed integer type.

class rustpy.primitive.i64(_value: int)[source]

The 64-bit signed integer type.

class rustpy.primitive.i8(_value: int)[source]

The 8-bit signed integer type.

class rustpy.primitive.isize(_value: int)[source]

The pointer-sized signed integer type.

class rustpy.primitive.u128(_value: int)[source]

The 128-bit unsigned integer type.

class rustpy.primitive.u16(_value: int)[source]

The 16-bit unsigned integer type.

class rustpy.primitive.u32(_value: int)[source]

The 32-bit unsigned integer type.

class rustpy.primitive.u64(_value: int)[source]

The 64-bit unsigned integer type.

class rustpy.primitive.u8(_value: int)[source]

The 8-bit unsigned integer type.

class rustpy.primitive.usize(_value: int)[source]

The pointer-sized unsigned integer type.

Note

If member is not listed in documentation it should be considered as implementation detail that can change and should not be relied upon.

Indices and tables