mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 09:54:41 -05:00
chore: rename MaybeSendWrapperOption to SendOption
This commit is contained in:
@@ -8,7 +8,7 @@ use reactive_graph::{
|
||||
ToAnySource, ToAnySubscriber,
|
||||
},
|
||||
owner::use_context,
|
||||
send_wrapper_ext::MaybeSendWrapperOption,
|
||||
send_wrapper_ext::SendOption,
|
||||
signal::{
|
||||
guards::{AsyncPlain, Mapped, ReadGuard},
|
||||
ArcRwSignal, RwSignal,
|
||||
@@ -163,7 +163,7 @@ where
|
||||
{
|
||||
type Value = ReadGuard<
|
||||
Option<T>,
|
||||
Mapped<AsyncPlain<MaybeSendWrapperOption<T>>, Option<T>>,
|
||||
Mapped<AsyncPlain<SendOption<T>>, Option<T>>,
|
||||
>;
|
||||
|
||||
fn try_read_untracked(&self) -> Option<Self::Value> {
|
||||
@@ -344,7 +344,7 @@ where
|
||||
{
|
||||
type Value = ReadGuard<
|
||||
Option<T>,
|
||||
Mapped<AsyncPlain<MaybeSendWrapperOption<T>>, Option<T>>,
|
||||
Mapped<AsyncPlain<SendOption<T>>, Option<T>>,
|
||||
>;
|
||||
|
||||
fn try_read_untracked(&self) -> Option<Self::Value> {
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
computed::{ArcMemo, Memo},
|
||||
diagnostics::is_suppressing_resource_load,
|
||||
owner::{ArcStoredValue, ArenaItem, FromLocal, LocalStorage},
|
||||
send_wrapper_ext::MaybeSendWrapperOption,
|
||||
send_wrapper_ext::SendOption,
|
||||
signal::{ArcRwSignal, RwSignal},
|
||||
traits::{DefinedAt, Dispose, Get, GetUntracked, GetValue, Update, Write},
|
||||
unwrap_signal,
|
||||
@@ -91,8 +91,8 @@ use std::{future::Future, panic::Location, pin::Pin, sync::Arc};
|
||||
/// ```
|
||||
pub struct ArcAction<I, O> {
|
||||
in_flight: ArcRwSignal<usize>,
|
||||
input: ArcRwSignal<MaybeSendWrapperOption<I>>,
|
||||
value: ArcRwSignal<MaybeSendWrapperOption<O>>,
|
||||
input: ArcRwSignal<SendOption<I>>,
|
||||
value: ArcRwSignal<SendOption<O>>,
|
||||
version: ArcRwSignal<usize>,
|
||||
dispatched: ArcStoredValue<usize>,
|
||||
#[allow(clippy::complexity)]
|
||||
@@ -195,8 +195,8 @@ where
|
||||
{
|
||||
ArcAction {
|
||||
in_flight: ArcRwSignal::new(0),
|
||||
input: ArcRwSignal::new(MaybeSendWrapperOption::new(None)),
|
||||
value: ArcRwSignal::new(MaybeSendWrapperOption::new(value)),
|
||||
input: ArcRwSignal::new(SendOption::new(None)),
|
||||
value: ArcRwSignal::new(SendOption::new(value)),
|
||||
version: Default::default(),
|
||||
dispatched: Default::default(),
|
||||
action_fn: Arc::new(move |input| Box::pin(action_fn(input))),
|
||||
@@ -367,8 +367,8 @@ where
|
||||
let action_fn = SendWrapper::new(action_fn);
|
||||
ArcAction {
|
||||
in_flight: ArcRwSignal::new(0),
|
||||
input: ArcRwSignal::new(MaybeSendWrapperOption::new_local(None)),
|
||||
value: ArcRwSignal::new(MaybeSendWrapperOption::new_local(value)),
|
||||
input: ArcRwSignal::new(SendOption::new_local(None)),
|
||||
value: ArcRwSignal::new(SendOption::new_local(value)),
|
||||
version: Default::default(),
|
||||
dispatched: Default::default(),
|
||||
action_fn: Arc::new(move |input| {
|
||||
@@ -433,7 +433,7 @@ impl<I, O> ArcAction<I, O> {
|
||||
/// # });
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn input(&self) -> ArcRwSignal<MaybeSendWrapperOption<I>> {
|
||||
pub fn input(&self) -> ArcRwSignal<SendOption<I>> {
|
||||
self.input.clone()
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ impl<I, O> ArcAction<I, O> {
|
||||
/// # });
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn value(&self) -> ArcRwSignal<MaybeSendWrapperOption<O>> {
|
||||
pub fn value(&self) -> ArcRwSignal<SendOption<O>> {
|
||||
self.value.clone()
|
||||
}
|
||||
|
||||
@@ -845,7 +845,7 @@ where
|
||||
/// # });
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn input(&self) -> RwSignal<MaybeSendWrapperOption<I>> {
|
||||
pub fn input(&self) -> RwSignal<SendOption<I>> {
|
||||
let inner = self
|
||||
.inner
|
||||
.try_with_value(|inner| inner.input())
|
||||
@@ -860,9 +860,7 @@ where
|
||||
#[track_caller]
|
||||
#[deprecated = "You can now use .input() for any value, whether it's \
|
||||
thread-safe or not."]
|
||||
pub fn input_local(
|
||||
&self,
|
||||
) -> RwSignal<MaybeSendWrapperOption<I>, LocalStorage> {
|
||||
pub fn input_local(&self) -> RwSignal<SendOption<I>, LocalStorage> {
|
||||
let inner = self
|
||||
.inner
|
||||
.try_with_value(|inner| inner.input())
|
||||
@@ -905,7 +903,7 @@ where
|
||||
/// # });
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn value(&self) -> RwSignal<MaybeSendWrapperOption<O>> {
|
||||
pub fn value(&self) -> RwSignal<SendOption<O>> {
|
||||
let inner = self
|
||||
.inner
|
||||
.try_with_value(|inner| inner.value())
|
||||
@@ -921,9 +919,7 @@ where
|
||||
#[deprecated = "You can now use .value() for any value, whether it's \
|
||||
thread-safe or not."]
|
||||
#[track_caller]
|
||||
pub fn value_local(
|
||||
&self,
|
||||
) -> RwSignal<MaybeSendWrapperOption<O>, LocalStorage>
|
||||
pub fn value_local(&self) -> RwSignal<SendOption<O>, LocalStorage>
|
||||
where
|
||||
O: Send + Sync,
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::{
|
||||
SubscriberSet, ToAnySource, ToAnySubscriber, WithObserver,
|
||||
},
|
||||
owner::{use_context, Owner},
|
||||
send_wrapper_ext::MaybeSendWrapperOption,
|
||||
send_wrapper_ext::SendOption,
|
||||
signal::{
|
||||
guards::{AsyncPlain, Mapped, MappedMut, ReadGuard, WriteGuard},
|
||||
ArcTrigger,
|
||||
@@ -110,7 +110,7 @@ pub struct ArcAsyncDerived<T> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
// the current state of this signal
|
||||
pub(crate) value: Arc<AsyncRwLock<MaybeSendWrapperOption<T>>>,
|
||||
pub(crate) value: Arc<AsyncRwLock<SendOption<T>>>,
|
||||
// holds wakers generated when you .await this
|
||||
pub(crate) wakers: Arc<RwLock<Vec<Waker>>>,
|
||||
pub(crate) inner: Arc<RwLock<ArcAsyncDerivedInner>>,
|
||||
@@ -405,8 +405,8 @@ macro_rules! spawn_derived {
|
||||
|
||||
impl<T: 'static> ArcAsyncDerived<T> {
|
||||
async fn set_inner_value(
|
||||
new_value: MaybeSendWrapperOption<T>,
|
||||
value: Arc<AsyncRwLock<MaybeSendWrapperOption<T>>>,
|
||||
new_value: SendOption<T>,
|
||||
value: Arc<AsyncRwLock<SendOption<T>>>,
|
||||
wakers: Arc<RwLock<Vec<Waker>>>,
|
||||
inner: Arc<RwLock<ArcAsyncDerivedInner>>,
|
||||
loading: Arc<AtomicBool>,
|
||||
@@ -481,9 +481,9 @@ impl<T: 'static> ArcAsyncDerived<T> {
|
||||
{
|
||||
let fun = move || {
|
||||
let fut = fun();
|
||||
async move { MaybeSendWrapperOption::new(Some(fut.await)) }
|
||||
async move { SendOption::new(Some(fut.await)) }
|
||||
};
|
||||
let initial_value = MaybeSendWrapperOption::new(initial_value);
|
||||
let initial_value = SendOption::new(initial_value);
|
||||
let (this, _) = spawn_derived!(
|
||||
Executor::spawn,
|
||||
initial_value,
|
||||
@@ -515,9 +515,9 @@ impl<T: 'static> ArcAsyncDerived<T> {
|
||||
{
|
||||
let fun = move || {
|
||||
let fut = fun();
|
||||
async move { MaybeSendWrapperOption::new(Some(fut.await)) }
|
||||
async move { SendOption::new(Some(fut.await)) }
|
||||
};
|
||||
let initial_value = MaybeSendWrapperOption::new(initial_value);
|
||||
let initial_value = SendOption::new(initial_value);
|
||||
let (this, _) = spawn_derived!(
|
||||
Executor::spawn,
|
||||
initial_value,
|
||||
@@ -557,9 +557,9 @@ impl<T: 'static> ArcAsyncDerived<T> {
|
||||
{
|
||||
let fun = move || {
|
||||
let fut = fun();
|
||||
async move { MaybeSendWrapperOption::new_local(Some(fut.await)) }
|
||||
async move { SendOption::new_local(Some(fut.await)) }
|
||||
};
|
||||
let initial_value = MaybeSendWrapperOption::new_local(initial_value);
|
||||
let initial_value = SendOption::new_local(initial_value);
|
||||
let (this, _) = spawn_derived!(
|
||||
Executor::spawn_local,
|
||||
initial_value,
|
||||
@@ -590,10 +590,10 @@ impl<T: 'static> ArcAsyncDerived<T> {
|
||||
T: 'static,
|
||||
Fut: Future<Output = T> + 'static,
|
||||
{
|
||||
let initial = MaybeSendWrapperOption::new_local(None::<T>);
|
||||
let initial = SendOption::new_local(None::<T>);
|
||||
let fun = move || {
|
||||
let fut = fun();
|
||||
async move { MaybeSendWrapperOption::new_local(Some(fut.await)) }
|
||||
async move { SendOption::new_local(Some(fut.await)) }
|
||||
};
|
||||
let (this, _) = spawn_derived!(
|
||||
Executor::spawn_local,
|
||||
@@ -609,10 +609,8 @@ impl<T: 'static> ArcAsyncDerived<T> {
|
||||
}
|
||||
|
||||
impl<T: 'static> ReadUntracked for ArcAsyncDerived<T> {
|
||||
type Value = ReadGuard<
|
||||
Option<T>,
|
||||
Mapped<AsyncPlain<MaybeSendWrapperOption<T>>, Option<T>>,
|
||||
>;
|
||||
type Value =
|
||||
ReadGuard<Option<T>, Mapped<AsyncPlain<SendOption<T>>, Option<T>>>;
|
||||
|
||||
fn try_read_untracked(&self) -> Option<Self::Value> {
|
||||
if let Some(suspense_context) = use_context::<SuspenseContext>() {
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
ToAnySource, ToAnySubscriber,
|
||||
},
|
||||
owner::{ArenaItem, FromLocal, LocalStorage, Storage, SyncStorage},
|
||||
send_wrapper_ext::MaybeSendWrapperOption,
|
||||
send_wrapper_ext::SendOption,
|
||||
signal::guards::{AsyncPlain, Mapped, MappedMut, ReadGuard, WriteGuard},
|
||||
traits::{
|
||||
DefinedAt, Dispose, IsDisposed, Notify, ReadUntracked,
|
||||
@@ -318,10 +318,8 @@ where
|
||||
T: 'static,
|
||||
S: Storage<ArcAsyncDerived<T>>,
|
||||
{
|
||||
type Value = ReadGuard<
|
||||
Option<T>,
|
||||
Mapped<AsyncPlain<MaybeSendWrapperOption<T>>, Option<T>>,
|
||||
>;
|
||||
type Value =
|
||||
ReadGuard<Option<T>, Mapped<AsyncPlain<SendOption<T>>, Option<T>>>;
|
||||
|
||||
fn try_read_untracked(&self) -> Option<Self::Value> {
|
||||
self.inner
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{
|
||||
diagnostics::SpecialNonReactiveZone,
|
||||
graph::{AnySource, ToAnySource},
|
||||
owner::{use_context, Storage},
|
||||
send_wrapper_ext::MaybeSendWrapperOption,
|
||||
send_wrapper_ext::SendOption,
|
||||
signal::guards::{AsyncPlain, Mapped, ReadGuard},
|
||||
traits::{DefinedAt, Track},
|
||||
unwrap_signal,
|
||||
@@ -26,7 +26,7 @@ use std::{
|
||||
/// Implements [`Deref`](std::ops::Deref) to access the inner value. This should not be held longer
|
||||
/// than it is needed, as it prevents updates to the inner value.
|
||||
pub type AsyncDerivedGuard<T> =
|
||||
ReadGuard<T, Mapped<AsyncPlain<MaybeSendWrapperOption<T>>, T>>;
|
||||
ReadGuard<T, Mapped<AsyncPlain<SendOption<T>>, T>>;
|
||||
|
||||
/// A [`Future`] that is ready when an [`ArcAsyncDerived`] is finished loading or reloading,
|
||||
/// but does not contain its value.
|
||||
@@ -108,7 +108,7 @@ where
|
||||
/// and contains its value. `.await`ing this clones the value `T`.
|
||||
pub struct AsyncDerivedFuture<T> {
|
||||
source: AnySource,
|
||||
value: Arc<async_lock::RwLock<MaybeSendWrapperOption<T>>>,
|
||||
value: Arc<async_lock::RwLock<SendOption<T>>>,
|
||||
loading: Arc<AtomicBool>,
|
||||
wakers: Arc<RwLock<Vec<Waker>>>,
|
||||
inner: Arc<RwLock<ArcAsyncDerivedInner>>,
|
||||
@@ -185,7 +185,7 @@ where
|
||||
/// and yields an [`AsyncDerivedGuard`] that dereferences to its value.
|
||||
pub struct AsyncDerivedRefFuture<T> {
|
||||
source: AnySource,
|
||||
value: Arc<async_lock::RwLock<MaybeSendWrapperOption<T>>>,
|
||||
value: Arc<async_lock::RwLock<SendOption<T>>>,
|
||||
loading: Arc<AtomicBool>,
|
||||
wakers: Arc<RwLock<Vec<Waker>>>,
|
||||
}
|
||||
|
||||
@@ -6,26 +6,25 @@ use std::{
|
||||
hash,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
/// An optional value that might be wrapped in [`SendWrapper`].
|
||||
///
|
||||
/// This struct is useful because:
|
||||
/// - Can be dereffed to &Option<T>, even when T is wrapped in a SendWrapper.
|
||||
/// - Until [`DerefMut`] is called, the None case will not construct a SendWrapper, so no panics if initialised when None and dropped on a different thread. Any access other than [`DerefMut`] will not construct a SendWrapper.
|
||||
pub struct MaybeSendWrapperOption<T> {
|
||||
pub struct SendOption<T> {
|
||||
inner: Inner<T>,
|
||||
}
|
||||
|
||||
// SAFETY: `MaybeSendWrapperOption` can *only* be given a T in four ways
|
||||
// SAFETY: `SendOption` can *only* be given a T in four ways
|
||||
// 1) via new(), which requires T: Send + Sync
|
||||
// 2) via new_local(), which wraps T in a SendWrapper if given Some(T)
|
||||
// 3) via deref_mut(), which creates a SendWrapper<Option<T>> as needed
|
||||
// 4) via update(), which either dereferences an existing SendWrapper
|
||||
// or creates a new SendWrapper as needed
|
||||
unsafe impl<T> Send for MaybeSendWrapperOption<T> {}
|
||||
unsafe impl<T> Sync for MaybeSendWrapperOption<T> {}
|
||||
unsafe impl<T> Send for SendOption<T> {}
|
||||
unsafe impl<T> Sync for SendOption<T> {}
|
||||
|
||||
impl<T> PartialEq for MaybeSendWrapperOption<T>
|
||||
impl<T> PartialEq for SendOption<T>
|
||||
where
|
||||
T: PartialEq,
|
||||
{
|
||||
@@ -34,9 +33,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for MaybeSendWrapperOption<T> where T: Eq {}
|
||||
impl<T> Eq for SendOption<T> where T: Eq {}
|
||||
|
||||
impl<T> PartialOrd for MaybeSendWrapperOption<T>
|
||||
impl<T> PartialOrd for SendOption<T>
|
||||
where
|
||||
T: PartialOrd,
|
||||
{
|
||||
@@ -45,7 +44,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> hash::Hash for MaybeSendWrapperOption<T>
|
||||
impl<T> hash::Hash for SendOption<T>
|
||||
where
|
||||
T: hash::Hash,
|
||||
{
|
||||
@@ -61,7 +60,7 @@ enum Inner<T> {
|
||||
Local(Option<SendWrapper<Option<T>>>),
|
||||
}
|
||||
|
||||
impl<T> MaybeSendWrapperOption<T>
|
||||
impl<T> SendOption<T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
@@ -73,7 +72,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for MaybeSendWrapperOption<T>
|
||||
impl<T> From<Option<T>> for SendOption<T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
@@ -82,7 +81,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> MaybeSendWrapperOption<T> {
|
||||
impl<T> From<Option<T>> for SendOption<T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
fn from(value: Option<T>) -> Self {
|
||||
Self::new(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SendOption<T> {
|
||||
/// Create a new non-threadsafe value.
|
||||
pub fn new_local(value: Option<T>) -> Self {
|
||||
Self {
|
||||
@@ -131,7 +139,7 @@ impl<T> MaybeSendWrapperOption<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for MaybeSendWrapperOption<T> {
|
||||
impl<T> Deref for SendOption<T> {
|
||||
type Target = Option<T>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@@ -145,7 +153,7 @@ impl<T> Deref for MaybeSendWrapperOption<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DerefMut for MaybeSendWrapperOption<T> {
|
||||
impl<T> DerefMut for SendOption<T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
match &mut self.inner {
|
||||
Inner::Threadsafe(value) => value,
|
||||
@@ -160,20 +168,20 @@ impl<T> DerefMut for MaybeSendWrapperOption<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Debug> Debug for MaybeSendWrapperOption<T> {
|
||||
impl<T: Debug> Debug for SendOption<T> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match &self.inner {
|
||||
Inner::Threadsafe(value) => {
|
||||
write!(f, "MaybeSendWrapperOption::Threadsafe({:?})", value)
|
||||
write!(f, "SendOption::Threadsafe({:?})", value)
|
||||
}
|
||||
Inner::Local(value) => {
|
||||
write!(f, "MaybeSendWrapperOption::Local({:?})", value)
|
||||
write!(f, "SendOption::Local({:?})", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone> Clone for MaybeSendWrapperOption<T> {
|
||||
impl<T: Clone> Clone for SendOption<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
inner: match &self.inner {
|
||||
|
||||
Reference in New Issue
Block a user