Skip to content

Commit 83d6595

Browse files
committed
use full path
Signed-off-by: Teo Koon Peng <[email protected]>
1 parent 9bc7cfe commit 83d6595

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

macros/src/buffers.rs renamed to macros/src/buffer.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use syn::{DeriveInput, Ident, Type};
44

55
use crate::Result;
66

7-
pub(crate) fn impl_buffer_map_layout(ast: DeriveInput) -> Result<TokenStream> {
7+
pub(crate) fn impl_joined_value(ast: DeriveInput) -> Result<TokenStream> {
88
let struct_ident = ast.ident;
99
let (field_ident, field_type) = match ast.data {
1010
syn::Data::Struct(data) => get_fields_map(data.fields)?,
@@ -15,19 +15,21 @@ pub(crate) fn impl_buffer_map_layout(ast: DeriveInput) -> Result<TokenStream> {
1515

1616
let gen = quote! {
1717
impl BufferMapLayout for #struct_ident {
18-
fn is_compatible(buffers: &BufferMap) -> Result<(), IncompatibleLayout> {
19-
let mut compatibility = IncompatibleLayout::default();
18+
fn is_compatible(buffers: &BufferMap) -> Result<(), ::bevy_impulse::IncompatibleLayout> {
19+
let mut compatibility = ::bevy_impulse::IncompatibleLayout::default();
2020
#(
2121
compatibility.require_buffer::<#field_type>(#map_key, buffers);
2222
)*
2323
compatibility.into_result()
2424
}
2525

2626
fn buffered_count(
27-
buffers: &BufferMap,
28-
session: Entity,
29-
world: &World,
30-
) -> Result<usize, OperationError> {
27+
buffers: &::bevy_impulse::BufferMap,
28+
session: ::bevy_ecs::prelude::Entity,
29+
world: &::bevy_ecs::prelude::World,
30+
) -> Result<usize, ::bevy_impulse::OperationError> {
31+
use ::bevy_impulse::{InspectBuffer, OrBroken};
32+
3133
#(
3234
let #field_ident = world
3335
.get_entity(buffers.get(#map_key).or_broken()?.id())
@@ -43,10 +45,12 @@ pub(crate) fn impl_buffer_map_layout(ast: DeriveInput) -> Result<TokenStream> {
4345
}
4446

4547
fn ensure_active_session(
46-
buffers: &BufferMap,
47-
session: Entity,
48-
world: &mut World,
49-
) -> OperationResult {
48+
buffers: &::bevy_impulse::BufferMap,
49+
session: ::bevy_ecs::prelude::Entity,
50+
world: &mut ::bevy_ecs::prelude::World,
51+
) -> ::bevy_impulse::OperationResult {
52+
use ::bevy_impulse::{ManageBuffer, OrBroken};
53+
5054
#(
5155
world
5256
.get_entity_mut(buffers.get(#map_key).or_broken()?.id())
@@ -58,14 +62,16 @@ pub(crate) fn impl_buffer_map_layout(ast: DeriveInput) -> Result<TokenStream> {
5862
}
5963
}
6064

61-
impl JoinedValue for #struct_ident {
65+
impl ::bevy_impulse::JoinedValue for #struct_ident {
6266
type Buffers = #struct_buffer_ident;
6367

6468
fn pull(
65-
buffers: &BufferMap,
66-
session: Entity,
67-
world: &mut World,
68-
) -> Result<Self, OperationError> {
69+
buffers: &::bevy_impulse::BufferMap,
70+
session: ::bevy_ecs::prelude::Entity,
71+
world: &mut ::bevy_ecs::prelude::World,
72+
) -> Result<Self, ::bevy_impulse::OperationError> {
73+
use ::bevy_impulse::{ManageBuffer, OrBroken};
74+
6975
#(
7076
let #field_ident = world
7177
.get_entity_mut(buffers.get(#map_key).or_broken()?.id())
@@ -83,15 +89,15 @@ pub(crate) fn impl_buffer_map_layout(ast: DeriveInput) -> Result<TokenStream> {
8389

8490
struct #struct_buffer_ident {
8591
#(
86-
#field_ident: Buffer<#field_type>
92+
#field_ident: ::bevy_impulse::Buffer<#field_type>
8793
),*
8894
}
8995

90-
impl From<#struct_buffer_ident> for BufferMap {
96+
impl From<#struct_buffer_ident> for ::bevy_impulse::BufferMap {
9197
fn from(value: #struct_buffer_ident) -> Self {
92-
let mut buffers = BufferMap::default();
98+
let mut buffers = ::bevy_impulse::BufferMap::default();
9399
#(
94-
buffers.insert(Cow::Borrowed(#map_key), value.#field_ident);
100+
buffers.insert(std::borrow::Cow::Borrowed(#map_key), value.#field_ident);
95101
)*
96102
buffers
97103
}

macros/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*
1616
*/
1717

18-
mod buffers;
19-
use buffers::impl_buffer_map_layout;
18+
mod buffer;
19+
use buffer::impl_joined_value;
2020

2121
use proc_macro::TokenStream;
2222
use quote::quote;
@@ -65,10 +65,10 @@ pub fn delivery_label_macro(item: TokenStream) -> TokenStream {
6565
// The result error is the compiler error message to be displayed.
6666
type Result<T> = std::result::Result<T, String>;
6767

68-
#[proc_macro_derive(Joined)]
69-
pub fn derive_joined(input: TokenStream) -> TokenStream {
68+
#[proc_macro_derive(JoinedValue)]
69+
pub fn derive_joined_value(input: TokenStream) -> TokenStream {
7070
let input = parse_macro_input!(input as DeriveInput);
71-
match impl_buffer_map_layout(input) {
71+
match impl_joined_value(input) {
7272
Ok(tokens) => tokens,
7373
Err(msg) => quote! {
7474
compile_error!(#msg);

src/buffer/buffer_map.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use crate::{
2929
OperationRoster, Output, UnusedTarget,
3030
};
3131

32+
pub use bevy_impulse_derive::JoinedValue;
33+
3234
#[derive(Clone, Default)]
3335
pub struct BufferMap {
3436
inner: HashMap<Cow<'static, str>, AnyBuffer>,
@@ -359,15 +361,9 @@ impl BufferMapLayout for AnyBufferKeyMap {
359361
mod tests {
360362
use std::borrow::Cow;
361363

362-
use crate::{
363-
prelude::*, testing::*, BufferMap, InspectBuffer, ManageBuffer, OperationError,
364-
OperationResult, OrBroken,
365-
};
366-
367-
use bevy_ecs::prelude::World;
368-
use bevy_impulse_derive::Joined;
364+
use crate::{prelude::*, testing::*, BufferMap};
369365

370-
#[derive(Clone, Joined)]
366+
#[derive(Clone, JoinedValue)]
371367
struct TestJoinedValue {
372368
integer: i64,
373369
float: f64,
@@ -379,6 +375,7 @@ mod tests {
379375
let mut context = TestingContext::minimal_plugins();
380376

381377
let workflow = context.spawn_io_workflow(|scope, builder| {
378+
// ::bevy_impulse::OrBroken::or_broken(self)
382379
let buffer_i64 = builder.create_buffer(BufferSettings::default());
383380
let buffer_f64 = builder.create_buffer(BufferSettings::default());
384381
let buffer_string = builder.create_buffer(BufferSettings::default());

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ pub use trim::*;
148148
use bevy_app::prelude::{App, Plugin, Update};
149149
use bevy_ecs::prelude::{Entity, In};
150150

151+
extern crate self as bevy_impulse;
152+
151153
/// Use `BlockingService` to indicate that your system is a blocking [`Service`].
152154
///
153155
/// A blocking service will have exclusive world access while it runs, which

0 commit comments

Comments
 (0)