pub trait Function: Sync {
// Required methods
fn resolve<'a>(
&self,
cx: &FnContext<'_>,
operand: Option<&Value<'a>>,
options: &Options<'_, 'a>,
errs: &mut dyn ErrorSink,
) -> Option<Value<'a>>;
fn format(&self, cx: &FnContext<'_>, value: &Value<'_>, out: &mut dyn Sink);
// Provided methods
fn formattable(
&self,
cx: &FnContext<'_>,
value: &Value<'_>,
) -> Result<(), FormatError> { ... }
fn format_parts(
&self,
cx: &FnContext<'_>,
value: &Value<'_>,
out: &mut dyn SubPartSink,
) { ... }
fn part_kind(&self) -> &'static str { ... }
fn dir(&self, cx: &FnContext<'_>, value: &Value<'_>) -> Dir { ... }
fn selectable(&self, value: &Value<'_>) -> bool { ... }
fn matches(
&self,
cx: &FnContext<'_>,
value: &Value<'_>,
key: &str,
errs: &mut dyn ErrorSink,
) -> bool { ... }
fn better_than(
&self,
cx: &FnContext<'_>,
value: &Value<'_>,
key1: &str,
key2: &str,
) -> bool { ... }
}Expand description
A function handler. :string, :number, :integer, :offset are in
crate::functions; custom functions implement the same trait (the
suite’s :test:* functions are written against it).
A handler first resolves an expression to a Value; the runtime then
asks the same handler, for that value, whether and how it formats, its
direction, and whether and how it selects.
Required Methods§
Sourcefn resolve<'a>(
&self,
cx: &FnContext<'_>,
operand: Option<&Value<'a>>,
options: &Options<'_, 'a>,
errs: &mut dyn ErrorSink,
) -> Option<Value<'a>>
fn resolve<'a>( &self, cx: &FnContext<'_>, operand: Option<&Value<'a>>, options: &Options<'_, 'a>, errs: &mut dyn ErrorSink, ) -> Option<Value<'a>>
Function resolution (formatting.md): operand resolved — a
Value::Fallback when it failed to resolve, so the handler decides
(plans/03-runtime.md §2.6) — and options resolved with
u:id/u:dir removed. None makes the expression a fallback value;
the handler has reported why.
Provided Methods§
Sourcefn formattable(
&self,
cx: &FnContext<'_>,
value: &Value<'_>,
) -> Result<(), FormatError>
fn formattable( &self, cx: &FnContext<'_>, value: &Value<'_>, ) -> Result<(), FormatError>
Whether value can be formatted. Err(e): the placeholder is a
fallback value and e is reported.
Sourcefn format_parts(
&self,
cx: &FnContext<'_>,
value: &Value<'_>,
out: &mut dyn SubPartSink,
)
fn format_parts( &self, cx: &FnContext<'_>, value: &Value<'_>, out: &mut dyn SubPartSink, )
Writes value’s formatted sub-parts (none by default).
Sourcefn dir(&self, cx: &FnContext<'_>, value: &Value<'_>) -> Dir
fn dir(&self, cx: &FnContext<'_>, value: &Value<'_>) -> Dir
The direction of value’s formatted text (Default Bidi Strategy);
Auto = unknown.
Sourcefn selectable(&self, value: &Value<'_>) -> bool
fn selectable(&self, value: &Value<'_>) -> bool
Whether value supports selection (formatting.md, “Resolve
Selectors”). A value that does not matches only *, with Bad
Selector.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".