Skip to content
Merged
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
14 changes: 7 additions & 7 deletions macros/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn impl_joined_value(input_struct: &ItemStruct) -> Result<TokenStream
let impl_joined = impl_joined(&buffer_struct, &input_struct, &field_ident)?;

let gen = quote! {
impl #impl_generics ::bevy_impulse::JoinedValue for #struct_ident #ty_generics #where_clause {
impl #impl_generics ::bevy_impulse::Joined for #struct_ident #ty_generics #where_clause {
type Buffers = #buffer_struct_ident #ty_generics;
}

Expand Down Expand Up @@ -122,7 +122,7 @@ pub(crate) fn impl_buffer_key_map(input_struct: &ItemStruct) -> Result<TokenStre
let impl_accessed = impl_accessed(&buffer_struct, &input_struct, &field_ident, &field_type)?;

let gen = quote! {
impl #impl_generics ::bevy_impulse::BufferKeyMap for #struct_ident #ty_generics #where_clause {
impl #impl_generics ::bevy_impulse::Accessor for #struct_ident #ty_generics #where_clause {
type Buffers = #buffer_struct_ident #ty_generics;
}

Expand Down Expand Up @@ -413,8 +413,8 @@ fn impl_buffer_map_layout(
}

/// Params:
/// joined_struct: The struct to implement `Joined`.
/// item_struct: The associated `Item` type to use for the `Joined` implementation.
/// joined_struct: The struct to implement `Joining`.
/// item_struct: The associated `Item` type to use for the `Joining` implementation.
fn impl_joined(
joined_struct: &ItemStruct,
item_struct: &ItemStruct,
Expand All @@ -425,7 +425,7 @@ fn impl_joined(
let (impl_generics, ty_generics, where_clause) = item_struct.generics.split_for_impl();

Ok(quote! {
impl #impl_generics ::bevy_impulse::Joined for #struct_ident #ty_generics #where_clause {
impl #impl_generics ::bevy_impulse::Joining for #struct_ident #ty_generics #where_clause {
type Item = #item_struct_ident #ty_generics;

fn pull(&self, session: ::bevy_impulse::re_exports::Entity, world: &mut ::bevy_impulse::re_exports::World) -> Result<Self::Item, ::bevy_impulse::OperationError> {
Expand All @@ -452,7 +452,7 @@ fn impl_accessed(
let (impl_generics, ty_generics, where_clause) = key_struct.generics.split_for_impl();

Ok(quote! {
impl #impl_generics ::bevy_impulse::Accessed for #struct_ident #ty_generics #where_clause {
impl #impl_generics ::bevy_impulse::Accessing for #struct_ident #ty_generics #where_clause {
type Key = #key_struct_ident #ty_generics;

fn add_accessor(
Expand All @@ -461,7 +461,7 @@ fn impl_accessed(
world: &mut ::bevy_impulse::re_exports::World,
) -> ::bevy_impulse::OperationResult {
#(
::bevy_impulse::Accessed::add_accessor(&self.#field_ident, accessor, world)?;
::bevy_impulse::Accessing::add_accessor(&self.#field_ident, accessor, world)?;
)*
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn delivery_label_macro(item: TokenStream) -> TokenStream {
/// The result error is the compiler error message to be displayed.
type Result<T> = std::result::Result<T, String>;

#[proc_macro_derive(JoinedValue, attributes(joined))]
#[proc_macro_derive(Joined, attributes(joined))]
pub fn derive_joined_value(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as ItemStruct);
match impl_joined_value(&input) {
Expand All @@ -77,7 +77,7 @@ pub fn derive_joined_value(input: TokenStream) -> TokenStream {
}
}

#[proc_macro_derive(BufferKeyMap, attributes(key))]
#[proc_macro_derive(Accessor, attributes(key))]
pub fn derive_buffer_key_map(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as ItemStruct);
match impl_buffer_key_map(&input) {
Expand Down
4 changes: 2 additions & 2 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub use buffer_map::*;
mod buffer_storage;
pub(crate) use buffer_storage::*;

mod buffered;
pub use buffered::*;
mod buffering;
pub use buffering::*;

mod bufferable;
pub use bufferable::*;
Expand Down
10 changes: 5 additions & 5 deletions src/buffer/any_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use thiserror::Error as ThisError;
use smallvec::SmallVec;

use crate::{
add_listener_to_source, Accessed, Buffer, BufferAccessMut, BufferAccessors, BufferError,
add_listener_to_source, Accessing, Buffer, BufferAccessMut, BufferAccessors, BufferError,
BufferKey, BufferKeyBuilder, BufferKeyLifecycle, BufferKeyTag, BufferLocation, BufferStorage,
Bufferable, Buffered, Builder, DrainBuffer, Gate, GateState, InspectBuffer, Joined,
Bufferable, Buffering, Builder, DrainBuffer, Gate, GateState, InspectBuffer, Joining,
ManageBuffer, NotifyBufferUpdate, OperationError, OperationResult, OperationRoster, OrBroken,
};

Expand Down Expand Up @@ -1035,7 +1035,7 @@ impl Bufferable for AnyBuffer {
}
}

impl Buffered for AnyBuffer {
impl Buffering for AnyBuffer {
fn verify_scope(&self, scope: Entity) {
assert_eq!(scope, self.scope());
}
Expand Down Expand Up @@ -1069,15 +1069,15 @@ impl Buffered for AnyBuffer {
}
}

impl Joined for AnyBuffer {
impl Joining for AnyBuffer {
type Item = AnyMessageBox;
fn pull(&self, session: Entity, world: &mut World) -> Result<Self::Item, OperationError> {
let mut buffer_mut = world.get_entity_mut(self.id()).or_broken()?;
self.interface.pull(&mut buffer_mut, session)
}
}

impl Accessed for AnyBuffer {
impl Accessing for AnyBuffer {
type Key = AnyBufferKey;
fn add_accessor(&self, accessor: Entity, world: &mut World) -> OperationResult {
world
Expand Down
66 changes: 33 additions & 33 deletions src/buffer/buffer_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use smallvec::SmallVec;
use bevy_ecs::prelude::{Entity, World};

use crate::{
add_listener_to_source, Accessed, AnyBuffer, AnyBufferKey, AnyMessageBox, AsAnyBuffer, Buffer,
BufferKeyBuilder, BufferKeyLifecycle, Bufferable, Buffered, Builder, Chain, Gate, GateState,
Joined, Node, OperationError, OperationResult, OperationRoster,
add_listener_to_source, Accessing, AnyBuffer, AnyBufferKey, AnyMessageBox, AsAnyBuffer, Buffer,
BufferKeyBuilder, BufferKeyLifecycle, Bufferable, Buffering, Builder, Chain, Gate, GateState,
Joining, Node, OperationError, OperationResult, OperationRoster,
};

pub use bevy_impulse_derive::{BufferKeyMap, JoinedValue};
pub use bevy_impulse_derive::{Accessor, Joined};

/// Uniquely identify a buffer within a buffer map, either by name or by an
/// index value.
Expand Down Expand Up @@ -199,18 +199,18 @@ pub struct BufferIncompatibility {

/// This trait can be implemented on structs that represent a layout of buffers.
/// You do not normally have to implement this yourself. Instead you should
/// `#[derive(JoinedValue)]` on a struct that you want a join operation to
/// `#[derive(Joined)]` on a struct that you want a join operation to
/// produce.
pub trait BufferMapLayout: Sized + Clone + 'static + Send + Sync {
/// Try to convert a generic [`BufferMap`] into this specific layout.
fn try_from_buffer_map(buffers: &BufferMap) -> Result<Self, IncompatibleLayout>;
}

/// This trait helps auto-generated buffer map structs to implement the Buffered
/// This trait helps auto-generated buffer map structs to implement the Buffering
/// trait.
pub trait BufferMapStruct: Sized + Clone + 'static + Send + Sync {
/// Produce a list of the buffers that exist in this layout. Implementing
/// this function alone is sufficient to implement the entire [`Buffered`] trait.
/// this function alone is sufficient to implement the entire [`Buffering`] trait.
fn buffer_list(&self) -> SmallVec<[AnyBuffer; 8]>;
}

Expand All @@ -222,7 +222,7 @@ impl<T: BufferMapStruct> Bufferable for T {
}
}

impl<T: BufferMapStruct> Buffered for T {
impl<T: BufferMapStruct> Buffering for T {
fn verify_scope(&self, scope: Entity) {
for buffer in self.buffer_list() {
assert_eq!(buffer.scope(), scope);
Expand Down Expand Up @@ -288,12 +288,12 @@ impl<T: BufferMapStruct> Buffered for T {
/// Each field in this struct needs to have the trait bounds `'static + Send + Sync`.
///
/// This does not generally need to be implemented explicitly. Instead you should
/// use `#[derive(JoinedValue)]`:
/// use `#[derive(Joined)]`:
///
/// ```
/// use bevy_impulse::prelude::*;
///
/// #[derive(JoinedValue)]
/// #[derive(Joined)]
/// struct SomeValues {
/// integer: i64,
/// string: String,
Expand All @@ -312,7 +312,7 @@ impl<T: BufferMapStruct> Buffered for T {
/// ```
/// # use bevy_impulse::prelude::*;
///
/// #[derive(JoinedValue)]
/// #[derive(Joined)]
/// #[joined(buffers_struct_name = SomeBuffers)]
/// struct SomeValues {
/// integer: i64,
Expand All @@ -322,14 +322,14 @@ impl<T: BufferMapStruct> Buffered for T {
///
/// By default each field of the generated buffers struct will have a type of
/// [`Buffer<T>`], but you can override this using `#[joined(buffer = ...)]`
/// to specify a special buffer type. For example if your `JoinedValue` struct
/// to specify a special buffer type. For example if your `Joined` struct
/// contains an [`AnyMessageBox`] then by default the macro will use `Buffer<AnyMessageBox>`,
/// but you probably really want it to have an [`AnyBuffer`]:
///
/// ```
/// # use bevy_impulse::prelude::*;
///
/// #[derive(JoinedValue)]
/// #[derive(Joined)]
/// struct SomeValues {
/// integer: i64,
/// string: String,
Expand All @@ -342,11 +342,11 @@ impl<T: BufferMapStruct> Buffered for T {
///
/// [1]: crate::Builder::join
/// [2]: crate::Builder::try_join
pub trait JoinedValue: 'static + Send + Sync + Sized {
pub trait Joined: 'static + Send + Sync + Sized {
/// This associated type must represent a buffer map layout that implements
/// the [`Joined`] trait. The message type yielded by [`Joined`] for this
/// associated type must match the [`JoinedValue`] type.
type Buffers: 'static + BufferMapLayout + Joined<Item = Self> + Send + Sync;
/// the [`Joining`] trait. The message type yielded by [`Joining`] for this
/// associated type must match the [`Joined`] type.
type Buffers: 'static + BufferMapLayout + Joining<Item = Self> + Send + Sync;

/// Used by [`Builder::try_join`]
fn try_join_from<'w, 's, 'a, 'b>(
Expand All @@ -366,12 +366,12 @@ pub trait JoinedValue: 'static + Send + Sync + Sized {
///
/// This does not generally need to be implemented explicitly. Instead you should
/// define a struct where all fields are buffer keys and then apply
/// `#[derive(BufferKeyMap)]` to it, e.g.:
/// `#[derive(Accessor)]` to it, e.g.:
///
/// ```
/// use bevy_impulse::prelude::*;
///
/// #[derive(Clone, BufferKeyMap)]
/// #[derive(Clone, Accessor)]
/// struct SomeKeys {
/// integer: BufferKey<i64>,
/// string: BufferKey<String>,
Expand All @@ -386,7 +386,7 @@ pub trait JoinedValue: 'static + Send + Sync + Sized {
/// ```
/// # use bevy_impulse::prelude::*;
///
/// #[derive(Clone, BufferKeyMap)]
/// #[derive(Clone, Accessor)]
/// #[key(buffers_struct_name = SomeBuffers)]
/// struct SomeKeys {
/// integer: BufferKey<i64>,
Expand All @@ -399,8 +399,8 @@ pub trait JoinedValue: 'static + Send + Sync + Sized {
/// [2]: crate::Builder::create_buffer_access
/// [3]: crate::Builder::try_listen
/// [4]: crate::Builder::try_create_buffer_access
pub trait BufferKeyMap: 'static + Send + Sync + Sized + Clone {
type Buffers: 'static + BufferMapLayout + Accessed<Key = Self> + Send + Sync;
pub trait Accessor: 'static + Send + Sync + Sized + Clone {
type Buffers: 'static + BufferMapLayout + Accessing<Key = Self> + Send + Sync;

fn try_listen_from<'w, 's, 'a, 'b>(
buffers: &BufferMap,
Expand Down Expand Up @@ -431,7 +431,7 @@ impl BufferMapStruct for BufferMap {
}
}

impl Joined for BufferMap {
impl Joining for BufferMap {
type Item = HashMap<BufferIdentifier<'static>, AnyMessageBox>;

fn pull(&self, session: Entity, world: &mut World) -> Result<Self::Item, OperationError> {
Expand All @@ -444,11 +444,11 @@ impl Joined for BufferMap {
}
}

impl JoinedValue for HashMap<BufferIdentifier<'static>, AnyMessageBox> {
impl Joined for HashMap<BufferIdentifier<'static>, AnyMessageBox> {
type Buffers = BufferMap;
}

impl Accessed for BufferMap {
impl Accessing for BufferMap {
type Key = HashMap<BufferIdentifier<'static>, AnyBufferKey>;

fn create_key(&self, builder: &BufferKeyBuilder) -> Self::Key {
Expand Down Expand Up @@ -489,7 +489,7 @@ impl Accessed for BufferMap {
}
}

impl<T: 'static + Send + Sync> JoinedValue for Vec<T> {
impl<T: 'static + Send + Sync> Joined for Vec<T> {
type Buffers = Vec<Buffer<T>>;
}

Expand All @@ -508,7 +508,7 @@ impl<B: 'static + Send + Sync + AsAnyBuffer + Clone> BufferMapLayout for Vec<B>
}
}

impl<T: 'static + Send + Sync, const N: usize> JoinedValue for SmallVec<[T; N]> {
impl<T: 'static + Send + Sync, const N: usize> Joined for SmallVec<[T; N]> {
type Buffers = SmallVec<[Buffer<T>; N]>;
}

Expand All @@ -533,7 +533,7 @@ impl<B: 'static + Send + Sync + AsAnyBuffer + Clone, const N: usize> BufferMapLa
mod tests {
use crate::{prelude::*, testing::*, AddBufferToMap, BufferMap};

#[derive(JoinedValue)]
#[derive(Joined)]
struct TestJoinedValue<T: Send + Sync + 'static + Clone> {
integer: i64,
float: f64,
Expand Down Expand Up @@ -640,7 +640,7 @@ mod tests {
assert!(context.no_unhandled_errors());
}

#[derive(Clone, JoinedValue)]
#[derive(Clone, Joined)]
#[joined(buffers_struct_name = FooBuffers)]
struct TestDeriveWithConfig {}

Expand All @@ -655,7 +655,7 @@ mod tests {
u: U,
}

#[derive(JoinedValue)]
#[derive(Joined)]
#[joined(buffers_struct_name = MultiGenericBuffers)]
struct JoinedMultiGenericValue<T: 'static + Send + Sync, U: 'static + Send + Sync> {
#[joined(buffer = Buffer<MultiGenericValue<T, U>>)]
Expand Down Expand Up @@ -714,15 +714,15 @@ mod tests {

/// We create this struct just to verify that it is able to compile despite
/// NonCopyBuffer not being copyable.
#[derive(JoinedValue)]
#[derive(Joined)]
#[allow(unused)]
struct JoinedValueForNonCopyBuffer {
#[joined(buffer = NonCopyBuffer<String>, noncopy_buffer)]
_a: String,
_b: u32,
}

#[derive(Clone, BufferKeyMap)]
#[derive(Clone, Accessor)]
#[key(buffers_struct_name = TestKeysBuffers)]
struct TestKeys<T: 'static + Send + Sync + Clone> {
integer: BufferKey<i64>,
Expand Down Expand Up @@ -836,7 +836,7 @@ mod tests {
/// This macro is a manual implementation of the join operation that uses
/// the buffer listening mechanism. There isn't any reason to reimplement
/// join here except so we can test that listening is working correctly for
/// BufferKeyMap.
/// Accessor.
fn join_via_listen(
In(keys): In<TestKeys<&'static str>>,
world: &mut World,
Expand Down
Loading