Module features

Source
Available on doc or test only.
Expand description

Library features.

§Features

Features are grouped in the following categories:

There are no features enabled by default.

Features from different categories are designed to be (for the most part) independent from each other, to be orthogonally composable.

Note however that not all features are additive, e.g. it’s not possible to enable at the same time std and no_std, nor safe and unsafe.

§Development features

Intended for development and internal purposes, like debugging and maintenance.

  • __dbg: for debugging purposes, shows enabled features and reflection flags.
  • __no_test: allows excluding examples from being tested.

§Environment features

By default the crate is no_std compatible without allocation.

  • std: disables no_std compatibility and enables std functionality.
  • alloc: enables alloc functionality.
  • no_std: enables functionality incompatible with or substitute of std.

§Module features

Enabling a parent module enables all its sub-modules, except for os.

They set automatic compile flags named *··, used for reflection. For example, num·· will be set if any num submodule feature is enabled.

  • all: enables all the root modules and extra submodules.

Root modules & public sub-modules features:

§Safety features

They offer a convenient way to opt in and out of safety in a granular fashion.

  • unsafe_* features enable the use of unsafe by purpose.
  • safe_* features disable the use of unsafe per module.

Enabling any of them sets either the safe·· or unsafe·· flag.

To be able to use any unsafe functionality it’s necessary to:

  1. enable the corresponding unsafe feature.
  2. don’t enable that module’s safe feature.
  • safe: forbids unsafe (and overrides unsafe features), including

    • safe_code
    • safe_data
    • safe_lang
    • safe_media
      • safe_audio
      • safe_color
      • safe_draw
      • safe_font
      • safe_image
    • safe_num
    • safe_phys
      • safe_time
    • safe_sys
      • safe_io
      • safe_mem
    • safe_text
    • safe_work
    • safe_ui
      • safe_layout
  • unsafe: enables unsafe (as long as it isn’t forbidden for that module), including:

    • unsafe_array: faster array initialization, UninitArray.
    • unsafe_ffi: unsafe foreign function calls (WASM, OS, external C).
    • unsafe_hint: unreachable_unchecked, assert_unchecked.
    • unsafe_layout: MemPod, DSTs in the stack, ExtAny::downcast*.
    • unsafe_niche: unchecked niche constructors.
    • unsafe_ptr: Pinned, pop methods without Clone.
    • unsafe_slice: extra slice methods, avoid bound checks.
    • unsafe_str: unchecked utf-8 char and &str conversions.
    • unsafe_sync: implement Send and Sync.
    • unsafe_syscall: os syscalls.
    • unsafe_thread: Logging::set_logger_racy, Env::{remove_var, set_var}.
  • safest: forbids unsafe even in dependencies (except for the standard library).

§Nightly features

Enabling any of them sets the nightly·· flag.

  • nightly: enables the nightly features:
    • nightly_allocator: enables allocator_api.
    • nightly_autodiff: enables autodiff.
    • nightly_bigint: enables bigint_helper_methods.
    • nightly_coro: enables coroutines, coroutine_trait, iter_from_coroutine.
    • nightly_doc: enables doc_cfg, doc_notable_trait.
    • nightly_float: enables f16, f128.
    • nightly_simd: enables portable_simd.
    • nightly_stable: enables stabilized features marked to be released soon:
      • nightly_stable_next1: in the next version.
      • nightly_stable_next2: in the version after that.
      • nightly_stable_later: later than that but soon enough.

§Capability features

These semi-hidden features allows to fine-tune extra capabilities. Enabling them will likely worsen compilation times.

Documentation capabilities:

  • _docsrs[_stable][_min|_nodep]: enables the most complete (or custom) version of the documentation, for docs.rs.
§data capabilities

Enable specific implementations for Bitwise, bitfield, enumset:

  • _bit_all:
    • _bit_i8, _bit_i16, _bit_i32, _bit_i64, _bit_i128, _bit_isize.
    • _bit_u8, _bit_u16, _bit_u32, _bit_u64, _bit_u128, _bit_usize.

They also set the corresponding flag: _bit··.

Enable specific implementations of data collections Destaque, Stack:

  • _collections_all:
    • _destaque_all:
      • _destaque_u8, _destaque_u16, _destaque_u32, _destaque_usize. _stack_all: _stack_u8, _stack_u16, _stack_u32, _stack_usize.

They also set the corresponding flags: _destaque··, _graph··, _node··, _stack··.

Enable specific implementations for Sort. _sort_all: _sort_u8, _sort_u16, _sort_u32, _sort_u64, _sort_u128, _sort_usize, _sort_i8, _sort_i16, _sort_i32, _sort_i64, _sort_i128, _sort_isize, _sort_f32, _sort_f64.

They also set the corresponding flags: _sort··, _sort_int··, _sort_float··.

Implement the Tuple trait for some maximum arity (12 by default).

  • _tuple[_24|_36|_48|_72].
§num capabilities

Enable specific implementations for Compare:

  • _cmp_all:
    • _cmp_f32, _cmp_f64.
    • _cmp_f16, _cmp_f128. ←(needs nightly_float)
    • _cmp_i8, _cmp_i16, _cmp_i32, _cmp_i64, _cmp_i128, _cmp_isize.
    • _cmp_u8, _cmp_u16, _cmp_u32, _cmp_u64, _cmp_u128,

They also set the corresponding flag: _cmp··.

Enable specific implementations for Int, Float, Frac, Divisor, Vector:

  • _num_all:
    • _float_all:
      • _float_f32, _float_f64.
      • _float_f16, _float_f128. ←(needs nightly_float)
    • _int_all:
      • _int_iall:
        • _int_i8, _int_i16, _int_i32, _int_i64, _int_i128, _int_isize.
      • _int_uall:
        • _int_u8, _int_u16, _int_u32, _int_u64, _int_u128, _int_usize.

They also set the corresponding flags: _nums··, _float··, _int··, _int_i··, _int_u··.

§text capabilities

Enable specific implementations for char*:

  • _char7, _char8, _char16.

Enable specific implementations for StringU**, StringNonul:

  • _str_all:
    • _str_uall:
      • _str_u8, _str_u16, _str_u32, _str_usize.
    • _str_nonul.

They also set the corresponding flags: _char··, _str··, _str_u··.

§Dependency features

  • Optional dependencies are re-exported from the _dep root module.

  • Can be enabled with the dep_crate_name feature in snake_case.

  • Enabling any of them sets the _dep·· flag.

  • dep_all: enables all the optional dependencies.

There are also the following groups of dependencies:

  • alloc_deps: enables: alloc, dep_allocator_api2.
  • linux_deps: enables: linux, dep_atomic, dep_bytemuck, dep_nc, dep_rustix.
  • text_deps: enables: text, dep_const_str, dep_memchr, dep_regex_lite, dep_stringzilla, dep_unicode_segmentation, dep_unicode_width.
  • work_deps: enables work, dep_atomic, dep_portable_atomic, dep_rayon, dep_tokio.