Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type inference regression due to From<T> for Signal<T> impl (closes #3200) #3255

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/errors_axum/src/landing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn App() -> impl IntoView {
<Routes fallback=|| {
let mut errors = Errors::default();
errors.insert_with_default_key(AppError::NotFound);
let errors = Signal::stored(errors);
view! {
<ErrorTemplate errors/>
}
Expand Down
2 changes: 1 addition & 1 deletion examples/timer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn TimerDemo() -> impl IntoView {
pub fn use_interval<T, F>(interval_millis: T, f: F)
where
F: Fn() + Clone + 'static,
T: Into<Signal<u64>> + 'static,
T: Into<MaybeSignal<u64>> + 'static,
{
let interval_millis = interval_millis.into();
Effect::new(move |prev_handle: Option<IntervalHandle>| {
Expand Down
25 changes: 25 additions & 0 deletions leptos/tests/generic_component.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[test]
fn generic_component_signal_inference() {
use leptos::prelude::*;

#[component]
pub fn SimpleCounter<T>(#[prop(into)] step: Signal<T>) -> impl IntoView
where
T: Send + Sync + 'static,
{
_ = step;
view! {
<div>
</div>
}
}

let a = RwSignal::new(1);
let (b, _) = signal(1);

view! {
<SimpleCounter step=a/>
<SimpleCounter step=b/>
<SimpleCounter step=Signal::stored(1)/>
};
}
97 changes: 1 addition & 96 deletions reactive_graph/src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,33 +606,6 @@ pub mod read {
}
}

impl<T: Send + Sync + 'static> From<T> for ArcSignal<T, SyncStorage> {
#[track_caller]
fn from(value: T) -> Self {
ArcSignal::stored(value)
}
}

impl<T> From<T> for Signal<T>
where
T: Send + Sync + 'static,
{
#[track_caller]
fn from(value: T) -> Self {
Self::stored(value)
}
}

impl<T> From<T> for Signal<T, LocalStorage>
where
T: 'static,
{
#[track_caller]
fn from(value: T) -> Self {
Self::stored_local(value)
}
}

impl<T> From<ArcSignal<T, SyncStorage>> for Signal<T>
where
T: Send + Sync + 'static,
Expand Down Expand Up @@ -856,36 +829,6 @@ pub mod read {
}
}

impl<T> From<T> for Signal<Option<T>>
where
T: Send + Sync + 'static,
{
#[track_caller]
fn from(value: T) -> Self {
Signal::stored(Some(value))
}
}

impl<T> From<T> for Signal<Option<T>, LocalStorage>
where
T: 'static,
{
#[track_caller]
fn from(value: T) -> Self {
Signal::stored_local(Some(value))
}
}

impl<T> From<Signal<T>> for Signal<Option<T>>
where
T: Clone + Send + Sync + 'static,
{
#[track_caller]
fn from(value: Signal<T>) -> Self {
Signal::derive(move || Some(value.get()))
}
}

impl<T> From<Signal<T, LocalStorage>> for Signal<Option<T>, LocalStorage>
where
T: Clone + 'static,
Expand Down Expand Up @@ -968,7 +911,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<MaybeSignal<T>> for Signal<T>
where
T: Send + Sync + 'static,
Expand All @@ -982,7 +924,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<MaybeSignal<T, LocalStorage>> for Signal<T, LocalStorage>
where
T: Send + Sync + 'static,
Expand All @@ -996,7 +937,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<MaybeSignal<T>> for Signal<Option<T>>
where
T: Clone + Send + Sync + 'static,
Expand All @@ -1012,7 +952,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<MaybeSignal<T, LocalStorage>> for Signal<Option<T>, LocalStorage>
where
T: Clone + Send + Sync + 'static,
Expand Down Expand Up @@ -1077,12 +1016,6 @@ pub mod read {
/// assert_eq!(above_3(&memoized_double_count.into()), true);
/// ```
#[derive(Debug, PartialEq, Eq)]
#[deprecated(
since = "0.7.0-rc1",
note = "`MaybeSignal<T>` is deprecated in favour of `Signal<T>` which \
is `Copy`, now has a more efficient From<T> implementation \
and other benefits in 0.7."
)]
pub enum MaybeSignal<T, S = SyncStorage>
where
T: 'static,
Expand All @@ -1094,7 +1027,6 @@ pub mod read {
Dynamic(Signal<T, S>),
}

#[allow(deprecated)]
impl<T: Clone, S> Clone for MaybeSignal<T, S>
where
S: Storage<T>,
Expand All @@ -1107,10 +1039,8 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T: Copy, S> Copy for MaybeSignal<T, S> where S: Storage<T> {}

#[allow(deprecated)]
impl<T: Default, S> Default for MaybeSignal<T, S>
where
S: Storage<T>,
Expand All @@ -1120,7 +1050,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T, S> DefinedAt for MaybeSignal<T, S>
where
S: Storage<T>,
Expand All @@ -1132,7 +1061,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T, S> Track for MaybeSignal<T, S>
where
S: Storage<T> + Storage<SignalTypes<T, S>>,
Expand All @@ -1145,7 +1073,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T, S> ReadUntracked for MaybeSignal<T, S>
where
T: Clone,
Expand All @@ -1170,7 +1097,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> MaybeSignal<T>
where
T: Send + Sync,
Expand All @@ -1184,7 +1110,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> MaybeSignal<T, LocalStorage> {
/// Wraps a derived signal, i.e., any computation that accesses one or more
/// reactive signals.
Expand All @@ -1193,7 +1118,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<T> for MaybeSignal<T, SyncStorage>
where
SyncStorage: Storage<T>,
Expand All @@ -1203,7 +1127,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> FromLocal<T> for MaybeSignal<T, LocalStorage>
where
LocalStorage: Storage<T>,
Expand All @@ -1213,7 +1136,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<ReadSignal<T>> for MaybeSignal<T>
where
T: Send + Sync,
Expand All @@ -1223,14 +1145,12 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<ReadSignal<T, LocalStorage>> for MaybeSignal<T, LocalStorage> {
fn from(value: ReadSignal<T, LocalStorage>) -> Self {
Self::Dynamic(value.into())
}
}

#[allow(deprecated)]
impl<T> From<RwSignal<T>> for MaybeSignal<T>
where
T: Send + Sync,
Expand All @@ -1240,14 +1160,12 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<RwSignal<T, LocalStorage>> for MaybeSignal<T, LocalStorage> {
fn from(value: RwSignal<T, LocalStorage>) -> Self {
Self::Dynamic(value.into())
}
}

#[allow(deprecated)]
impl<T> From<Memo<T>> for MaybeSignal<T>
where
T: Send + Sync,
Expand All @@ -1257,14 +1175,12 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<Memo<T, LocalStorage>> for MaybeSignal<T, LocalStorage> {
fn from(value: Memo<T, LocalStorage>) -> Self {
Self::Dynamic(value.into())
}
}

#[allow(deprecated)]
impl<T> From<ArcReadSignal<T>> for MaybeSignal<T>
where
T: Send + Sync,
Expand All @@ -1274,14 +1190,12 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> FromLocal<ArcReadSignal<T>> for MaybeSignal<T, LocalStorage> {
fn from_local(value: ArcReadSignal<T>) -> Self {
ReadSignal::from_local(value).into()
}
}

#[allow(deprecated)]
impl<T> From<ArcRwSignal<T>> for MaybeSignal<T>
where
T: Send + Sync + 'static,
Expand All @@ -1291,7 +1205,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> FromLocal<ArcRwSignal<T>> for MaybeSignal<T, LocalStorage>
where
T: 'static,
Expand All @@ -1301,7 +1214,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<ArcMemo<T>> for MaybeSignal<T>
where
T: Send + Sync,
Expand All @@ -1311,14 +1223,12 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> FromLocal<ArcMemo<T, LocalStorage>> for MaybeSignal<T, LocalStorage> {
fn from_local(value: ArcMemo<T, LocalStorage>) -> Self {
Memo::from_local(value).into()
}
}

#[allow(deprecated)]
impl<T, S> From<Signal<T, S>> for MaybeSignal<T, S>
where
S: Storage<T>,
Expand All @@ -1328,7 +1238,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<S> From<&str> for MaybeSignal<String, S>
where
S: Storage<String> + Storage<Arc<RwLock<String>>>,
Expand Down Expand Up @@ -1477,7 +1386,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<MaybeSignal<Option<T>>> for MaybeProp<T>
where
T: Send + Sync,
Expand All @@ -1488,7 +1396,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<Option<MaybeSignal<Option<T>>>> for MaybeProp<T>
where
T: Send + Sync,
Expand Down Expand Up @@ -1574,7 +1481,7 @@ pub mod read {

impl From<&str> for MaybeProp<String> {
fn from(value: &str) -> Self {
Self(Some(Signal::from(Some(value.to_string()))))
Self(Some(Signal::stored(Some(value.to_string()))))
}
}

Expand All @@ -1600,7 +1507,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<MaybeSignal<Option<T>, LocalStorage>>
for MaybeProp<T, LocalStorage>
where
Expand All @@ -1611,7 +1517,6 @@ pub mod read {
}
}

#[allow(deprecated)]
impl<T> From<Option<MaybeSignal<Option<T>, LocalStorage>>>
for MaybeProp<T, LocalStorage>
where
Expand Down
Loading