Skip to content

Commit

Permalink
formating
Browse files Browse the repository at this point in the history
  • Loading branch information
rambip committed Sep 27, 2023
1 parent 24623b3 commit 7cc4917
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
23 changes: 8 additions & 15 deletions leptos/src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ pub trait Callable<In, Out = ()> {
fn call(&self, input: In) -> Out;
}



/// The most basic leptos callback type.
/// For how to use callbacks, see [here][crate::callback]
///
Expand Down Expand Up @@ -132,31 +130,29 @@ impl<In, Out> Callable<In, Out> for Callback<In, Out> {
impl<F, In, T, Out> From<F> for Callback<In, Out>
where
F: Fn(In) -> T + 'static,
T: Into<Out> + 'static
T: Into<Out> + 'static,
{
fn from(f: F) -> Callback<In, Out> {
Callback::new(move |x| f(x).into())
}
}


// will allow to implement `Fn` for Callback in the future if needed.
#[cfg(feature = "nightly")]
auto trait NotRawCallback {}
#[cfg(feature = "nightly")]
impl<A,B> !NotRawCallback for Callback<A,B> { }
impl<A, B> !NotRawCallback for Callback<A, B> {}
#[cfg(feature = "nightly")]
impl<F, In, T, Out> From<F> for Callback<In, Out>
where
F: Fn(In) -> T + NotRawCallback + 'static,
T: Into<Out> + 'static
T: Into<Out> + 'static,
{
fn from(f: F) -> Callback<In, Out> {
Callback::new(move |x| f(x).into())
}
}


/// A callback type that implements `Copy`.
/// `StoredCallback<In,Out>` is an alias for `StoredValue<Callback<In, Out>>`.
///
Expand Down Expand Up @@ -211,7 +207,6 @@ impl<In, Out> Callable<In, Out> for SyncCallback<In, Out> {
}
}


impl<In, Out> Clone for SyncCallback<In, Out> {
fn clone(&self) -> Self {
Self(self.0.clone())
Expand All @@ -228,8 +223,6 @@ impl<In: 'static, Out: 'static> SyncCallback<In, Out> {
}
}



#[cfg(test)]
mod tests {
use crate::callback::{Callback, SyncCallback};
Expand All @@ -250,16 +243,16 @@ mod tests {

#[test]
fn callback_from() {
let _callback : Callback<(), String> = (|()| "test").into();
let _callback: Callback<(), String> = (|()| "test").into();
}

#[test]
fn callback_from_html() {
use leptos_macro::view;
use crate::html::{AnyElement, HtmlElement};
use leptos_dom::IntoView;
use crate::html::{HtmlElement, AnyElement};
use leptos_macro::view;

let _callback : Callback<String, HtmlElement<AnyElement>>
= (|x: String| view!{<h1>{x}</h1>}).into();
let _callback: Callback<String, HtmlElement<AnyElement>> =
(|x: String| view! {<h1>{x}</h1>}).into();
}
}
4 changes: 2 additions & 2 deletions leptos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ pub use serde;
pub use serde_json;
pub use show::*;
pub use suspense_component::*;
mod callback;
mod suspense_component;
mod text_prop;
mod transition;
mod callback;

pub use text_prop::TextProp;
pub use callback::*;
pub use text_prop::TextProp;
#[cfg(any(debug_assertions, feature = "ssr"))]
#[doc(hidden)]
pub use tracing;
Expand Down

0 comments on commit 7cc4917

Please sign in to comment.