rubedo 0.4.4

Library of useful functionality and extensions
Documentation

Rubedo

The Rubedo crate is a library of useful functionality, some being extensions of standard library entities; some extensions of other, popular crates; and some being completely new functionality.

It is named after the alchemical process of turning base metals into gold. The word "rubedo" is Latin for "redness", and is the final stage of the alchemical process. It is also the name of the final stage of the Magnum Opus. The Magnum Opus is the process of creating the philosopher's stone, which is supposed to be able to turn base metals into gold. The philosopher's stone is also said to be able to grant immortality, and is the main goal of alchemy. The philosopher's stone is also known as the "red stone" or the "red powder". The reasons for the choice of name are firstly that the "redness" is tangentially related to Rust through colour, and secondly that this crate will aspirationally help to turn your Rust code into gold... well, maybe... or at least make it easier to write.

The modules provided are:

std

The std module provides extensions to the Rust standard library.

AsStr

The AsStr trait is essentially a marker trait, indicating the presence of an as_str() method, primarily for use with the serde module, most usefully with enums:

  • as_str() - Provides a string slice representation of the type.

FromIntWithScale and ToIntWithScale

The FromIntWithScale and ToIntWithScale traits are used to convert between integers and floating-point numbers using specified scales, i.e. different numbers of decimal places, primarily for use with the serde module, most usefully with currency values:

Iterator

The Iterator trait is extended with (technically, complemented by) the following methods:

  • limit() - Limits the number of items returned by an iterator, similar to take(), but accepts an Option.

Path

The Path struct is extended with the following methods:

  • append() - Adds a string to the end of a path, and returns the result as a new path, without creating a new path component.

  • is_subjective() - Checks if the path is specifically relative to the current directory, i.e. starts with a reference to the current directory, which can be . or ...

  • normalize() - Computes the canonicalized, absolute path of a file or directory, removing any . and .. segments and returning the "real" path, without expanding symlinks or checking existence.

  • restrict() - Restricts the path to a given base path, normalising the path and not allowing it to go beyond the base path.

  • strip_parentdirs() - Removes references to parent directories, i.e. ...

  • strip_root() - Makes the path relative by removing the root and/or prefix components.

chrono

The chrono module provides extensions to the Chrono crate.

Duration

The Duration struct is extended with the following methods:

  • humanize() - Returns a human-readable string representation of the duration, as an expression of the largest unit available.

NaiveDate

The NaiveDate struct is extended with the following methods:

http

The http module provides extensions to the HTTP, Hyper, and Axum crates.

Response

The Response struct is extended with the following methods:

  • unpack() - Unpacks the response and provides the headers and body in a more accessible form, to allow it to be checked, compared, and printed easily.

serde

The serde module provides conversion utility functions for use with Serde.

Serialisation

  • as_str() - Returns a string representation of a type from a string slice.

  • into() - Returns a serialised representation of a type.

  • into_string() - Returns a string representation of a type.

  • to_string() - Returns a string copy of a type.

Deserialisation

  • from() - Returns a type from a string or other serialised representation.

  • from_string() - Returns a type from a string representation.

  • from_str() - Returns a type from a string slice representation.

  • try_from() - Returns a type from a string or other serialised representation.

  • try_from_string() - Returns a type from a string representation.

Decimal helpers

sugar

The sugar module provides macros that add syntactic sugar for common operations.

  • ip! - Builds an IP address from a range of input types. Note that this macro is provided by the rubedo-macros crate.

  • s! - Converts a str string literal to an owned String, saving having to do "foo".to_owned() or String::from("foo"). It will also convert any other type that implements the ToString trait to a String.

  • variants! - Allows shorthand for referring to multiple variants of the same enum, producing a Vec of the variants.

  • variants_hashset! - Allows shorthand for referring to multiple variants of the same enum, producing a HashSet of the variants.

  • vv! - Abbreviated form of variants!.

  • vh! - Abbreviated form of variants_hashset!.