Compare commits
No commits in common. "f19cccd2f8001942d1f2ef718f663e9bda90b2f8" and "c61c2dba379280adf79c329efe56730c0b36c065" have entirely different histories.
f19cccd2f8
...
c61c2dba37
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "newt"
|
name = "newt"
|
||||||
version = "0.3.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
31
src/lib.rs
31
src/lib.rs
|
|
@ -22,55 +22,34 @@ use internal::{
|
||||||
|
|
||||||
/// The primary trait exposed by this crate. Implement this trait if you would
|
/// The primary trait exposed by this crate. Implement this trait if you would
|
||||||
/// like to be able to render a type in a template.
|
/// like to be able to render a type in a template.
|
||||||
///
|
|
||||||
/// NOTE: There are defaults implemented for every method on this trait:
|
|
||||||
/// - print: prints nothing
|
|
||||||
/// - lookup: always returns None
|
|
||||||
/// - has: always returns None
|
|
||||||
/// - is_truthy: always returns true
|
|
||||||
/// - index: always returns None
|
|
||||||
///
|
|
||||||
/// You only need to implement the methods whose behaviors you want to change
|
|
||||||
pub trait Value: core::fmt::Debug {
|
pub trait Value: core::fmt::Debug {
|
||||||
/// Print this value to the given string.
|
/// Print this value to the given string.
|
||||||
///
|
///
|
||||||
/// See also [`internal::parse::Print`] and [`internal::vm::ops::Op::ValuePrint`]
|
/// See also [`internal::parse::Print`] and [`internal::vm::ops::Op::ValuePrint`]
|
||||||
fn print(&self, out: &mut String) {
|
fn print(&self, out: &mut String);
|
||||||
let _ = out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Lookup a field name in this value. The returned [`Value`] will be set as
|
/// Lookup a field name in this value. The returned [`Value`] will be set as
|
||||||
/// the current value inside the block.
|
/// the current value inside the block.
|
||||||
///
|
///
|
||||||
/// See also [internal::vm::ops::Op::ValueLookup]
|
/// See also [internal::vm::ops::Op::ValueLookup]
|
||||||
fn lookup(&self, name: &str) -> Option<&dyn Value> {
|
fn lookup(&self, name: &str) -> Option<&dyn Value>;
|
||||||
let _ = name;
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Like [`Option::map`], but for a value. The returned [`Value`] will be set
|
/// Like [`Option::map`], but for a value. The returned [`Value`] will be set
|
||||||
/// as the current value inside the block.
|
/// as the current value inside the block.
|
||||||
///
|
///
|
||||||
/// See also [`internal::parse::Has`] and [`internal::vm::ops::Op::ValueHas`]
|
/// See also [`internal::parse::Has`] and [`internal::vm::ops::Op::ValueHas`]
|
||||||
fn has(&self) -> Option<&dyn Value> {
|
fn has(&self) -> Option<&dyn Value>;
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if a value is truthy.
|
/// Check if a value is truthy.
|
||||||
///
|
///
|
||||||
/// See also [`internal::parse::If`] and [`internal::vm::ops::Op::ValueTruthy`]
|
/// See also [`internal::parse::If`] and [`internal::vm::ops::Op::ValueTruthy`]
|
||||||
fn is_truthy(&self) -> bool {
|
fn is_truthy(&self) -> bool;
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Lookup the current index in this value. The returned [`Value`] will be
|
/// Lookup the current index in this value. The returned [`Value`] will be
|
||||||
/// set as the current value inside the block.
|
/// set as the current value inside the block.
|
||||||
///
|
///
|
||||||
/// See also [`internal::parse::For`] and [`internal::vm::ops::Op::ValueIndex`]
|
/// See also [`internal::parse::For`] and [`internal::vm::ops::Op::ValueIndex`]
|
||||||
fn index(&self, index: usize) -> Option<&dyn Value> {
|
fn index(&self, index: usize) -> Option<&dyn Value>;
|
||||||
let _ = index;
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! value_for_int {
|
macro_rules! value_for_int {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue