This commit is contained in:
Tim 'Piepmatz' Hesse 2024-06-03 00:50:31 +02:00
parent d7fc6339a2
commit 628382283e
2 changed files with 15 additions and 15 deletions

View File

@ -13,15 +13,15 @@ use std::{
};
/// A trait for loading a value from a [`Value`].
///
///
/// # Derivable
/// This trait can be used with `#[derive]`.
/// When derived on structs with named fields, it expects a [`Value::Record`]
/// where each field of the struct maps to a corresponding field in the record.
/// For structs with unnamed fields, it expects a [`Value::List`], and the
/// fields are populated in the order they appear in the list.
/// Unit structs expect a [`Value::Nothing`], as they contain no data.
/// Attempting to convert from a non-matching `Value` type will result in an
/// This trait can be used with `#[derive]`.
/// When derived on structs with named fields, it expects a [`Value::Record`]
/// where each field of the struct maps to a corresponding field in the record.
/// For structs with unnamed fields, it expects a [`Value::List`], and the
/// fields are populated in the order they appear in the list.
/// Unit structs expect a [`Value::Nothing`], as they contain no data.
/// Attempting to convert from a non-matching `Value` type will result in an
/// error.
// TODO: explain derive for enums
pub trait FromValue: Sized {

View File

@ -5,15 +5,15 @@ use crate::{Record, ShellError, Span, Value};
/// A trait for converting a value into a [`Value`].
///
/// This conversion is infallible, for fallible conversions use [`TryIntoValue`].
///
///
/// # Derivable
/// This trait can be used with `#[derive]`.
/// When derived on structs with named fields, the resulting value
/// representation will use [`Value::Record`], where each field of the record
/// corresponds to a field of the struct.
/// For structs with unnamed fields, the value representation will be
/// This trait can be used with `#[derive]`.
/// When derived on structs with named fields, the resulting value
/// representation will use [`Value::Record`], where each field of the record
/// corresponds to a field of the struct.
/// For structs with unnamed fields, the value representation will be
/// [`Value::List`], with all fields inserted into a list.
/// Unit structs will be represented as [`Value::Nothing`] since they contain
/// Unit structs will be represented as [`Value::Nothing`] since they contain
/// no data.
// TODO: explain derive for enums
pub trait IntoValue: Sized {