Skip to content

Commit 454a34b

Browse files
authored
Reorganize crate exports (#53)
* Slight refactoring in cgp-field * Move cgp_error::impls to new cgp_error_extra crate * Add feature flags for alloc in cgp-error-extra * Reorganize exports and make them explicit * Add changelog * Reformat exports
1 parent 3dc5190 commit 454a34b

File tree

69 files changed

+214
-144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+214
-144
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## v0.3.0 (pre-release)
44

5+
- Reorganize crate exports - [#53](https://github.com/contextgeneric/cgp/pull/53)
6+
- Move generic error providers to the `cgp-error-extra` crate.
7+
- Add an `alloc` feature to `cgp-error-extra` to enable use of `alloc` in providers.
8+
- Make private the sub-modules inside CGP crates.
9+
- Explicitly export module items instead of using `*`.
10+
511
- Move `cgp-inner` to `cgp-extra` - [#51](https://github.com/contextgeneric/cgp/pull/51)
612
- Remove re-export of `cgp-inner` from `cgp-core`.
713
- Re-export `cgp-inner` and `cgp-runtime` from `cgp-extra`.

Cargo.lock

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ members = [
1717
"crates/cgp-field-macro",
1818
"crates/cgp-field-macro-lib",
1919
"crates/cgp-error",
20+
"crates/cgp-error-extra",
2021
"crates/cgp-error-anyhow",
2122
"crates/cgp-error-eyre",
2223
"crates/cgp-error-std",
@@ -48,6 +49,7 @@ cgp-field = { path = "./crates/cgp-field" }
4849
cgp-field-macro = { path = "./crates/cgp-field-macro" }
4950
cgp-field-macro-lib = { path = "./crates/cgp-field-macro-lib" }
5051
cgp-error = { path = "./crates/cgp-error" }
52+
cgp-error-extra = { path = "./crates/cgp-error-extra" }
5153
cgp-run = { path = "./crates/cgp-run" }
5254
cgp-runtime = { path = "./crates/cgp-runtime" }
5355
cgp-inner = { path = "./crates/cgp-inner" }

crates/cgp-async-macro/src/strip_async.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::vec::Vec;
2+
23
use proc_macro2::{Group, TokenStream, TokenTree};
34
use syn::parse::{Parse, ParseStream};
45
use syn::token::{Async, Await, Dot, Fn};

crates/cgp-async/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
pub mod traits;
44

5-
pub use traits::{Async, MaybeSend, MaybeStatic, MaybeSync};
6-
75
#[cfg(feature = "async")]
86
pub use cgp_async_macro::native_async as async_trait;
9-
107
#[cfg(not(feature = "async"))]
118
pub use cgp_sync::async_trait;
9+
pub use traits::{Async, MaybeSend, MaybeStatic, MaybeSync};

crates/cgp-component-macro-lib/src/delegate_components/impl_delegate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use alloc::boxed::Box;
22
use alloc::vec;
33
use alloc::vec::Vec;
4+
45
use syn::{parse_quote, Generics, ImplItem, ImplItemType, ItemImpl, Path, Type};
56

67
use crate::delegate_components::ast::{ComponentAst, DelegateEntriesAst};

crates/cgp-component-macro-lib/src/derive_component/component_spec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::format;
2+
23
use proc_macro2::Span;
34
use quote::ToTokens;
45
use syn::parse::{Parse, ParseStream};

crates/cgp-component-macro-lib/src/derive_component/consumer_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloc::boxed::Box;
22
use alloc::vec::Vec;
3+
34
use syn::punctuated::Punctuated;
45
use syn::token::{Brace, Comma, For, Impl, Plus};
56
use syn::{

crates/cgp-component-macro-lib/src/derive_component/delegate_fn.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::vec::Vec;
2+
23
use proc_macro2::TokenStream;
34
use quote::quote;
45
use syn::{parse_quote, ImplItemFn, Signature, TypePath, Visibility};

crates/cgp-component-macro-lib/src/derive_component/provider_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloc::boxed::Box;
22
use alloc::vec::Vec;
3+
34
use proc_macro2::Span;
45
use syn::punctuated::Punctuated;
56
use syn::token::{Brace, Comma, For, Impl, Plus};

crates/cgp-component-macro-lib/src/derive_component/provider_trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::vec::Vec;
2+
23
use syn::punctuated::Punctuated;
34
use syn::{parse_quote, Ident, ItemTrait, TraitItem};
45

crates/cgp-component-macro-lib/src/derive_component/replace_self_type.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::vec::Vec;
2+
23
use itertools::Itertools;
34
use proc_macro2::{Group, Ident, TokenStream, TokenTree};
45
use quote::{format_ident, ToTokens};

crates/cgp-component-macro-lib/src/derive_component/snake_case.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::string::{String, ToString};
2+
23
use proc_macro2::Span;
34
use syn::Ident;
45

crates/cgp-component-macro-lib/src/for_each_replace.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::vec::Vec;
2+
23
use proc_macro2::{Group, TokenStream, TokenTree};
34
use quote::{quote, ToTokens};
45
use syn::__private::parse_brackets;

crates/cgp-component-macro-lib/src/preset/define_preset.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloc::format;
22
use alloc::string::ToString;
3+
34
use proc_macro2::{Span, TokenStream};
45
use quote::ToTokens;
56
use syn::{parse_quote, Ident, ItemTrait};

crates/cgp-component-macro-lib/src/preset/impl_is_preset.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::vec::Vec;
2+
23
use syn::{parse_quote, Generics, Ident, ItemImpl, Type};
34

45
use crate::delegate_components::ast::{ComponentAst, DelegateEntriesAst};

crates/cgp-component-macro-lib/src/tests/helper/format.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::string::{String, ToString};
2+
23
use prettyplease::unparse;
34
use proc_macro2::TokenStream;
45
use syn::parse_file;

crates/cgp-component/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
This crate defines the core CGP traits, [`DelegateComponent`] and [`HasComponents`].
55
*/
66

7-
pub mod traits;
8-
pub mod types;
7+
mod traits;
8+
mod types;
99

1010
pub use traits::{DelegateComponent, HasComponents};
1111
pub use types::{UseContext, UseDelegate, WithContext, WithProvider};
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pub mod delegate_component;
2-
pub mod has_components;
1+
mod delegate_component;
2+
mod has_components;
33

44
pub use delegate_component::DelegateComponent;
55
pub use has_components::HasComponents;

crates/cgp-component/src/types/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
pub mod use_context;
2-
pub mod use_delegate;
3-
pub mod with_provider;
1+
mod use_context;
2+
mod use_delegate;
3+
mod with_provider;
44

55
pub use use_context::{UseContext, WithContext};
66
pub use use_delegate::UseDelegate;

crates/cgp-core/src/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ pub use cgp_component::{DelegateComponent, HasComponents};
33
pub use cgp_component_macro::{
44
cgp_component, cgp_preset, delegate_components, for_each_replace, replace_with,
55
};
6-
pub use cgp_error::traits::{CanRaiseError, CanWrapError, HasErrorType};
6+
pub use cgp_error::{CanRaiseError, CanWrapError, HasErrorType};
77
pub use cgp_field::{Char, Cons, Either, HasField, HasFieldMut, Nil, Void};
88
pub use cgp_field_macro::{product, symbol, HasField, Product, Sum};
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
pub mod debug_error;
2-
pub mod display_error;
3-
pub mod raise_anyhow_error;
4-
pub mod use_anyhow_error;
1+
mod debug_error;
2+
mod display_error;
3+
mod raise_anyhow_error;
4+
mod use_anyhow_error;
55

6-
pub use debug_error::*;
7-
pub use display_error::*;
8-
pub use raise_anyhow_error::*;
9-
pub use use_anyhow_error::*;
6+
pub use debug_error::DebugAnyhowError;
7+
pub use display_error::DisplayAnyhowError;
8+
pub use raise_anyhow_error::RaiseAnyhowError;
9+
pub use use_anyhow_error::UseAnyhowError;

crates/cgp-error-anyhow/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![no_std]
22

3-
pub mod impls;
3+
mod impls;
44

5-
pub use impls::*;
5+
pub use impls::{DebugAnyhowError, DisplayAnyhowError, RaiseAnyhowError, UseAnyhowError};

crates/cgp-error-extra/Cargo.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "cgp-error-extra"
3+
version = "0.2.0"
4+
edition = { workspace = true }
5+
license = { workspace = true }
6+
repository = { workspace = true }
7+
authors = { workspace = true }
8+
rust-version = { workspace = true }
9+
keywords = { workspace = true }
10+
description = """
11+
Context-generic programming error components
12+
"""
13+
14+
[features]
15+
default = [ "alloc" ]
16+
alloc = []
17+
18+
[dependencies]
19+
cgp-error = { version = "0.2.0" }

crates/cgp-error/src/impls/debug_error.rs crates/cgp-error-extra/src/impls/alloc/debug_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloc::format;
22
use alloc::string::String;
33
use core::fmt::Debug;
44

5-
use crate::traits::{CanRaiseError, ErrorRaiser};
5+
use cgp_error::{CanRaiseError, ErrorRaiser};
66

77
pub struct DebugError;
88

crates/cgp-error/src/impls/display_error.rs crates/cgp-error-extra/src/impls/alloc/display_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloc::format;
22
use alloc::string::String;
33
use core::fmt::Display;
44

5-
use crate::traits::{CanRaiseError, ErrorRaiser};
5+
use cgp_error::{CanRaiseError, ErrorRaiser};
66

77
pub struct DisplayError;
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod debug_error;
2+
mod display_error;
3+
4+
pub use debug_error::DebugError;
5+
pub use display_error::DisplayError;

crates/cgp-error/src/impls/discard_detail.rs crates/cgp-error-extra/src/impls/discard_detail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::traits::{ErrorWrapper, HasErrorType};
1+
use cgp_error::{ErrorWrapper, HasErrorType};
22

33
pub struct DiscardDetail;
44

crates/cgp-error/src/impls/infallible.rs crates/cgp-error-extra/src/impls/infallible.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::convert::Infallible;
22

3-
use crate::traits::{ErrorRaiser, HasErrorType};
3+
use cgp_error::{ErrorRaiser, HasErrorType};
44

55
pub struct RaiseInfallible;
66

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#[cfg(feature = "alloc")]
2+
mod alloc;
3+
4+
mod discard_detail;
5+
mod infallible;
6+
mod panic_error;
7+
mod raise_from;
8+
mod return_error;
9+
10+
#[cfg(feature = "alloc")]
11+
pub use alloc::{DebugError, DisplayError};
12+
13+
pub use discard_detail::DiscardDetail;
14+
pub use infallible::RaiseInfallible;
15+
pub use panic_error::PanicOnError;
16+
pub use raise_from::RaiseFrom;
17+
pub use return_error::ReturnError;

crates/cgp-error/src/impls/panic_error.rs crates/cgp-error-extra/src/impls/panic_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::fmt::Debug;
22

3-
use crate::traits::{ErrorRaiser, HasErrorType};
3+
use cgp_error::{ErrorRaiser, HasErrorType};
44

55
pub struct PanicOnError;
66

crates/cgp-error/src/impls/raise_from.rs crates/cgp-error-extra/src/impls/raise_from.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::traits::{ErrorRaiser, HasErrorType};
1+
use cgp_error::{ErrorRaiser, HasErrorType};
22

33
pub struct RaiseFrom;
44

crates/cgp-error/src/impls/return_error.rs crates/cgp-error-extra/src/impls/return_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::traits::{ErrorRaiser, HasErrorType};
1+
use cgp_error::{ErrorRaiser, HasErrorType};
22

33
pub struct ReturnError;
44

crates/cgp-error-extra/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![no_std]
2+
3+
#[cfg(feature = "alloc")]
4+
extern crate alloc;
5+
6+
mod impls;
7+
8+
#[cfg(feature = "alloc")]
9+
pub use impls::{DebugError, DisplayError};
10+
pub use impls::{DiscardDetail, PanicOnError, RaiseFrom, RaiseInfallible, ReturnError};
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
pub mod debug_error;
2-
pub mod display_error;
3-
pub mod raise_eyre_error;
4-
pub mod use_eyre_error;
1+
mod debug_error;
2+
mod display_error;
3+
mod raise_eyre_error;
4+
mod use_eyre_error;
55

6-
pub use debug_error::*;
7-
pub use display_error::*;
8-
pub use raise_eyre_error::*;
9-
pub use use_eyre_error::*;
6+
pub use debug_error::DebugEyreError;
7+
pub use display_error::DisplayEyreError;
8+
pub use raise_eyre_error::RaiseEyreError;
9+
pub use use_eyre_error::UseEyreError;

crates/cgp-error-eyre/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![no_std]
22

3-
pub mod impls;
3+
mod impls;
44

5-
pub use impls::*;
5+
pub use impls::{DebugEyreError, DisplayEyreError, RaiseEyreError, UseEyreError};

crates/cgp-error-std/src/impls/debug_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use core::fmt::Debug;
2-
31
use alloc::boxed::Box;
42
use alloc::format;
3+
use core::fmt::Debug;
4+
55
use cgp_core::error::{ErrorRaiser, HasErrorType};
66

77
use crate::types::{Error, StringError};

crates/cgp-error-std/src/impls/display_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use core::fmt::Display;
2-
31
use alloc::boxed::Box;
42
use alloc::format;
3+
use core::fmt::Display;
4+
55
use cgp_core::error::{ErrorRaiser, HasErrorType};
66

77
use crate::types::{Error, StringError};

crates/cgp-error-std/src/impls/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
pub mod debug_error;
2-
pub mod display_error;
3-
pub mod raise_boxed;
4-
pub mod use_boxed;
1+
mod debug_error;
2+
mod display_error;
3+
mod raise_boxed;
4+
mod use_boxed;
55

6-
pub use debug_error::*;
7-
pub use display_error::*;
8-
pub use raise_boxed::*;
9-
pub use use_boxed::*;
6+
pub use debug_error::DebugBoxedStdError;
7+
pub use display_error::DisplayBoxedStdError;
8+
pub use raise_boxed::RaiseBoxedStdError;
9+
pub use use_boxed::UseBoxedStdError;

crates/cgp-error-std/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
extern crate alloc;
44

5-
pub mod impls;
6-
pub mod types;
5+
mod impls;
6+
mod types;
77

8-
pub use impls::*;
9-
pub use types::*;
8+
pub use impls::{DebugBoxedStdError, DisplayBoxedStdError, RaiseBoxedStdError, UseBoxedStdError};
9+
pub use types::{Error, StringError};

0 commit comments

Comments
 (0)