Skip to main content

NixExternal

Trait NixExternal 

Source
pub trait NixExternal:
    Send
    + Sync
    + 'static {
    // Required methods
    fn display(&self) -> String;
    fn type_name(&self) -> &'static str;

    // Provided methods
    fn coerce_to_string(&self) -> Option<String> { ... }
    fn equal(&self, _other: &Self) -> bool { ... }
}
Expand description

A Rust type that can be embedded as an external value in the Nix evaluator.

Implementing this trait is the only requirement for storing your type inside Nix values via EvalState::make_external. All methods except display and type_name have default no-op implementations.

Required Methods§

Source

fn display(&self) -> String

Return a human-readable representation of the value.

This is called when Nix prints the value (e.g. in the REPL).

Source

fn type_name(&self) -> &'static str

Return the type name shown by :t in the Nix REPL.

Provided Methods§

Source

fn coerce_to_string(&self) -> Option<String>

Try to coerce the value to a string.

Return Some(s) to allow coercion; return None (the default) to have Nix throw an error when coercion is attempted.

Source

fn equal(&self, _other: &Self) -> bool

Test equality with another external value of the same Rust type.

The default implementation returns false (values are never equal).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§