This is accomplished by simply delegating to the Rust implementations of (Partial)Ord and (Partial)Eq, which are implemented for Value and underlying wrapper types to behave like they do in Nix. To ease the implementation overhead, a new comparison operator macro has been added to the VM module. Incomparable types will raise a new error variant when a comparison is attempted, containing both supplied types. This mimics the information carried in the error thrown by C++ Nix. Change-Id: Ia19634d69119d40722f3ca672387bc3a80096998 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6143 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
30 lines
522 B
Rust
30 lines
522 B
Rust
use std::fmt::Display;
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
DuplicateAttrsKey {
|
|
key: String,
|
|
},
|
|
|
|
InvalidKeyType {
|
|
given: &'static str,
|
|
},
|
|
|
|
TypeError {
|
|
expected: &'static str,
|
|
actual: &'static str,
|
|
},
|
|
|
|
Incomparable {
|
|
lhs: &'static str,
|
|
rhs: &'static str,
|
|
},
|
|
}
|
|
|
|
impl Display for Error {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
writeln!(f, "{:?}", self)
|
|
}
|
|
}
|
|
|
|
pub type EvalResult<T> = Result<T, Error>;
|