context is now a Rc

This commit is contained in:
Mitchell Marino 2024-06-18 13:10:49 -05:00
parent da84bdbb27
commit bbde4d6331
3 changed files with 5 additions and 5 deletions

View File

@ -33,7 +33,7 @@ impl<FD: FormToolData> Clone for ButtonData<FD> {
impl<FD: FormToolData> FormBuilder<FD> { impl<FD: FormToolData> FormBuilder<FD> {
pub fn button(mut self, builder: impl BuilderFn<ButtonBuilder<FD>, FD::Context>) -> Self { pub fn button(mut self, builder: impl BuilderFn<ButtonBuilder<FD>, FD::Context>) -> Self {
let button_builder = ButtonBuilder::new(); let button_builder = ButtonBuilder::new();
let control = builder(button_builder, &self.cx); let control = builder(button_builder, self.cx.clone());
let render_data = ControlRenderData { let render_data = ControlRenderData {
data: control.data, data: control.data,

View File

@ -18,7 +18,7 @@ pub mod submit;
pub mod text_area; pub mod text_area;
pub mod text_input; pub mod text_input;
pub trait BuilderFn<B, CX>: Fn(B, &CX) -> B {} pub trait BuilderFn<B, CX>: Fn(B, Rc<CX>) -> B {}
pub trait ValidationFn<FDT: ?Sized>: Fn(&FDT) -> Result<(), String> + 'static {} pub trait ValidationFn<FDT: ?Sized>: Fn(&FDT) -> Result<(), String> + 'static {}
pub trait ValidationCb: Fn() -> bool + 'static {} pub trait ValidationCb: Fn() -> bool + 'static {}
pub trait ParseFn<CR, FDT>: Fn(CR) -> Result<FDT, String> + 'static {} pub trait ParseFn<CR, FDT>: Fn(CR) -> Result<FDT, String> + 'static {}
@ -32,7 +32,7 @@ pub trait RenderFn<FS, FD: 'static>:
} }
// implement the traits for all valid types // implement the traits for all valid types
impl<B, CX, T> BuilderFn<B, CX> for T where T: Fn(B, &CX) -> B {} impl<B, CX, T> BuilderFn<B, CX> for T where T: Fn(B, Rc<CX>) -> B {}
impl<FDT, T> ValidationFn<FDT> for T where T: Fn(&FDT) -> Result<(), String> + 'static {} impl<FDT, T> ValidationFn<FDT> for T where T: Fn(&FDT) -> Result<(), String> + 'static {}
impl<T> ValidationCb for T where T: Fn() -> bool + 'static {} impl<T> ValidationCb for T where T: Fn() -> bool + 'static {}
impl<CR, FDT, F> ParseFn<CR, FDT> for F where F: Fn(CR) -> Result<FDT, String> + 'static {} impl<CR, FDT, F> ParseFn<CR, FDT> for F where F: Fn(CR) -> Result<FDT, String> + 'static {}

View File

@ -66,7 +66,7 @@ impl<FD: FormToolData> FormBuilder<FD> {
builder: impl BuilderFn<VanityControlBuilder<FD, C>, FD::Context>, builder: impl BuilderFn<VanityControlBuilder<FD, C>, FD::Context>,
) -> Self { ) -> Self {
let vanity_builder = VanityControlBuilder::new(C::default()); let vanity_builder = VanityControlBuilder::new(C::default());
let control = builder(vanity_builder, &self.cx); let control = builder(vanity_builder, self.cx.clone());
self.add_vanity(control); self.add_vanity(control);
self self
} }
@ -76,7 +76,7 @@ impl<FD: FormToolData> FormBuilder<FD> {
builder: impl BuilderFn<ControlBuilder<FD, C, FDT>, FD::Context>, builder: impl BuilderFn<ControlBuilder<FD, C, FDT>, FD::Context>,
) -> Self { ) -> Self {
let control_builder = ControlBuilder::new(C::default()); let control_builder = ControlBuilder::new(C::default());
let control = builder(control_builder, &self.cx); let control = builder(control_builder, self.cx.clone());
self.add_control(control); self.add_control(control);
self self
} }