Skip to main content

MappedQueryResource

Struct MappedQueryResource 

Source
pub struct MappedQueryResource<T, U, E> { /* private fields */ }
Available on crate feature core only.
Expand description

A mapped view over a QueryResource that applies a SelectTransform.

This implements the “select” pattern: multiple consumers can derive different views from the same underlying cached data, each with their own MappedQueryResource holding a different transform function. The source data is shared, so there is no duplication.

§Type parameters

  • T: The source data type (the cached query result).
  • U: The projected output type (the derived view).
  • E: The error type (carried through for API consistency).

§Storage

Source data is held as Option<Arc<T>> (audit #20) so that cloning a MappedQueryResource (e.g. for derived views) is a cheap Arc::clone rather than a full copy of T. Arc<T> is Send + Sync exactly when T is, so the existing bounds are preserved.

Implementations§

Source§

impl<T, U, E> MappedQueryResource<T, U, E>

Source

pub fn new( source_data: Option<Arc<T>>, transform: SelectTransform<T, U>, ) -> Self

Create a new mapped resource.

Takes ownership of the source data as Option<Arc<T>> (audit #20). For the common case of constructing from a plain T, wrap it with Some(Arc::new(t)).

Source

pub fn data(&self) -> Option<U>

Apply the transform to get the selected data.

Note (audit #3): This re-applies the transform closure on every call. MappedQueryResource is a derived view with no separate output cache — it stores only the source data and the transform function. If the transform is expensive and you need the result multiple times in a single render pass (e.g., once for display and once for an equality check), cache the result in a local variable:

use gpui_query::core::{MappedQueryResource, SelectTransform};

let transform = SelectTransform::new(|v: &Vec<i32>| v.len());
let mapped = MappedQueryResource::<_, usize, ()>::new(Some(std::sync::Arc::new(vec![1, 2, 3])), transform);
let data = mapped.data(); // transform runs once
assert_eq!(data, Some(3));
// use `data` freely below

For lightweight transforms (field access, counting, simple projections) the cost is negligible and no caching is needed.

Source

pub fn has_data(&self) -> bool

Whether source data exists.

Source

pub fn source_data(&self) -> Option<&T>

Read-only access to the source data.

Returns Option<&T> by dereferencing the stored Arc<T> (audit #20). Keeping the &T return type (rather than &Arc<T>) is the least disruptive choice: existing callers compare the pointed-to T and do not need to change. Used by the hook layer to detect when the source has changed before re-storing.

Source

pub fn source_arc(&self) -> Option<Arc<T>>

Cheaply hand out the cached source Arc<T> as an owned value.

Returns Option<Arc<T>> via a refcount bump (Arc::clone) — no T clone. Audit H1: the hook layer uses this to compare the cached source against a fresh read WITHOUT cloning T on unchanged notifications. Because the returned Arc<T> is owned, the mapped borrow ends with this call, so a subsequent entity.read_with does not create the nested borrow that audit #115 removed.

Source

pub fn update_source(&mut self, data: Option<Arc<T>>)

Update the source data from the underlying query resource.

Call this when the source QueryResource changes (fetch completes, cache invalidation, etc.) to keep the mapped view in sync. The transform is not applied here — it is applied lazily when data() is called. Takes Option<Arc<T>> so callers can hand over a cheap Arc::clone instead of cloning the full T (audit #20).

Trait Implementations§

Source§

impl<T: Clone, U: Clone, E: Clone> Clone for MappedQueryResource<T, U, E>

Source§

fn clone(&self) -> MappedQueryResource<T, U, E>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, U: Debug, E: Debug> Debug for MappedQueryResource<T, U, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Eq, U: Eq, E: Eq> Eq for MappedQueryResource<T, U, E>

Source§

impl<T: PartialEq, U: PartialEq, E: PartialEq> PartialEq for MappedQueryResource<T, U, E>

Source§

fn eq(&self, other: &MappedQueryResource<T, U, E>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq, U: PartialEq, E: PartialEq> StructuralPartialEq for MappedQueryResource<T, U, E>

Auto Trait Implementations§

§

impl<T, U, E> !RefUnwindSafe for MappedQueryResource<T, U, E>

§

impl<T, U, E> !UnwindSafe for MappedQueryResource<T, U, E>

§

impl<T, U, E> Freeze for MappedQueryResource<T, U, E>

§

impl<T, U, E> Send for MappedQueryResource<T, U, E>

§

impl<T, U, E> Sync for MappedQueryResource<T, U, E>

§

impl<T, U, E> Unpin for MappedQueryResource<T, U, E>

§

impl<T, U, E> UnsafeUnpin for MappedQueryResource<T, U, E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more