Simplify types, mitigate expansion; eliminate unnecessary move.

Further simplify future::BoolExt toward type expansion mitigation.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-10-21 02:00:57 +00:00
parent 2a662445b6
commit aa4486dfdf
7 changed files with 78 additions and 74 deletions

View File

@@ -22,7 +22,7 @@ use ruma::{
};
use tokio::sync::{Mutex, MutexGuard};
use tuwunel_core::{
Err, Error, Event, PduEvent, Result, implement,
Err, Error, Event, Result, implement,
utils::{
IterStream,
future::{BoolExt, TryExtExt},
@@ -513,12 +513,12 @@ async fn cache_insert(
fn get_space_child_events<'a>(
&'a self,
room_id: &'a RoomId,
) -> impl Stream<Item = PduEvent> + Send + 'a {
) -> impl Stream<Item = impl Event> + Send + 'a {
self.services
.state_accessor
.room_state_keys_with_ids(room_id, &StateEventType::SpaceChild)
.ready_filter_map(Result::ok)
.broad_filter_map(async move |(state_key, event_id): (_, OwnedEventId)| {
.broad_filter_map(async |(state_key, event_id): (_, OwnedEventId)| {
self.services
.timeline
.get_pdu(&event_id)
@@ -526,7 +526,7 @@ fn get_space_child_events<'a>(
.ok()
.await
})
.ready_filter_map(move |(state_key, pdu)| {
.ready_filter_map(|(state_key, pdu)| {
if let Ok(content) = pdu.get_content::<SpaceChildEventContent>() {
if content.via.is_empty() {
return None;

View File

@@ -1,7 +1,5 @@
use std::borrow::Borrow;
use futures::{Stream, StreamExt, TryFutureExt};
use ruma::{EventId, RoomId, events::StateEventType};
use ruma::{OwnedEventId, RoomId, events::StateEventType};
use serde::Deserialize;
use tuwunel_core::{
Result, err, implement,
@@ -82,16 +80,12 @@ pub fn room_state_full_pdus<'a>(
/// `state_key`).
#[implement(super::Service)]
#[tracing::instrument(skip(self), level = "debug")]
pub async fn room_state_get_id<Id>(
pub async fn room_state_get_id(
&self,
room_id: &RoomId,
event_type: &StateEventType,
state_key: &str,
) -> Result<Id>
where
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned,
<Id as ToOwned>::Owned: Borrow<EventId>,
{
) -> Result<OwnedEventId> {
self.services
.state
.get_room_shortstatehash(room_id)
@@ -103,15 +97,11 @@ where
/// `event_id` from the current state.
#[implement(super::Service)]
#[tracing::instrument(skip(self), level = "debug")]
pub fn room_state_keys_with_ids<'a, Id>(
pub fn room_state_keys_with_ids<'a>(
&'a self,
room_id: &'a RoomId,
event_type: &'a StateEventType,
) -> impl Stream<Item = Result<(StateKey, Id)>> + Send + 'a
where
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a,
<Id as ToOwned>::Owned: Borrow<EventId>,
{
) -> impl Stream<Item = Result<(StateKey, OwnedEventId)>> + Send + 'a {
self.services
.state
.get_room_shortstatehash(room_id)

View File

@@ -1,8 +1,8 @@
use std::{borrow::Borrow, ops::Deref, sync::Arc};
use std::{ops::Deref, sync::Arc};
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, future::try_join, pin_mut};
use ruma::{
EventId, OwnedEventId, UserId,
OwnedEventId, UserId,
events::{
StateEventType,
room::member::{MembershipState, RoomMemberEventContent},
@@ -138,16 +138,12 @@ pub async fn state_get(
/// Returns a single EventId from `room_id` with key (`event_type`,
/// `state_key`).
#[implement(super::Service)]
pub async fn state_get_id<Id>(
pub async fn state_get_id(
&self,
shortstatehash: ShortStateHash,
event_type: &StateEventType,
state_key: &str,
) -> Result<Id>
where
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned,
<Id as ToOwned>::Owned: Borrow<EventId>,
{
) -> Result<OwnedEventId> {
let shorteventid = self
.state_get_shortid(shortstatehash, event_type, state_key)
.await?;
@@ -209,15 +205,11 @@ pub fn state_type_pdus<'a>(
/// Iterates the state_keys for an event_type in the state; current state
/// event_id included.
#[implement(super::Service)]
pub fn state_keys_with_ids<'a, Id>(
pub fn state_keys_with_ids<'a>(
&'a self,
shortstatehash: ShortStateHash,
event_type: &'a StateEventType,
) -> impl Stream<Item = (StateKey, Id)> + Send + 'a
where
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a,
<Id as ToOwned>::Owned: Borrow<EventId>,
{
) -> impl Stream<Item = (StateKey, OwnedEventId)> + Send + 'a {
let state_keys_with_short_ids = self
.state_keys_with_shortids(shortstatehash, event_type)
.unzip()
@@ -371,14 +363,10 @@ pub fn state_full_pdus(
/// Builds a StateMap by iterating over all keys that start
/// with state_hash, this gives the full state for the given state_hash.
#[implement(super::Service)]
pub fn state_full_ids<'a, Id>(
&'a self,
pub fn state_full_ids(
&self,
shortstatehash: ShortStateHash,
) -> impl Stream<Item = (ShortStateKey, Id)> + Send + 'a
where
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a,
<Id as ToOwned>::Owned: Borrow<EventId>,
{
) -> impl Stream<Item = (ShortStateKey, OwnedEventId)> + Send + '_ {
let shortids = self
.state_full_shortids(shortstatehash)
.ignore_err()