pub struct ConverterBuilder<F>{ /* private fields */ }Expand description
Builder that turns a closure into a Converter.
use daedalus_data::convert::{ConverterBuilder, ConverterGraph};
use daedalus_data::errors::{DataError, DataErrorCode};
use daedalus_data::model::{TypeExpr, Value, ValueType};
let conv = ConverterBuilder::new(
"int_to_string",
TypeExpr::Scalar(ValueType::Int),
TypeExpr::Scalar(ValueType::String),
|v| match v {
Value::Int(i) => Ok(Value::String(i.to_string().into())),
_ => Err(DataError::new(DataErrorCode::InvalidType, "expected int")),
},
)
.cost(2u64)
.feature_flag("fmt")
.build_boxed();
let mut graph = ConverterGraph::new();
graph.register(conv);
let res = graph
.resolve_with_context(
&TypeExpr::Scalar(ValueType::Int),
&TypeExpr::Scalar(ValueType::String),
&["fmt".into()],
true,
)
.expect("resolution");
assert_eq!(res.provenance.steps.len(), 1);Implementations§
Source§impl<F> ConverterBuilder<F>
impl<F> ConverterBuilder<F>
pub fn new( id: impl Into<String>, input: TypeExpr, output: TypeExpr, func: F, ) -> Self
pub fn cost(self, cost: u64) -> Self
pub fn feature_flag(self, flag: impl Into<String>) -> Self
pub fn requires_gpu(self, requires: bool) -> Self
pub fn build(self) -> FnConverter<F>
pub fn build_boxed(self) -> Box<dyn Converter>
Auto Trait Implementations§
impl<F> Freeze for ConverterBuilder<F>where
F: Freeze,
impl<F> RefUnwindSafe for ConverterBuilder<F>where
F: RefUnwindSafe,
impl<F> Send for ConverterBuilder<F>
impl<F> Sync for ConverterBuilder<F>
impl<F> Unpin for ConverterBuilder<F>where
F: Unpin,
impl<F> UnwindSafe for ConverterBuilder<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more