Skip to content

Commit

Permalink
Reorganize crate exports (#53)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
soareschen authored Jan 7, 2025
1 parent 3dc5190 commit 454a34b
Show file tree
Hide file tree
Showing 69 changed files with 214 additions and 144 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## v0.3.0 (pre-release)

- Reorganize crate exports - [#53](https://github.com/contextgeneric/cgp/pull/53)
- Move generic error providers to the `cgp-error-extra` crate.
- Add an `alloc` feature to `cgp-error-extra` to enable use of `alloc` in providers.
- Make private the sub-modules inside CGP crates.
- Explicitly export module items instead of using `*`.

- Move `cgp-inner` to `cgp-extra` - [#51](https://github.com/contextgeneric/cgp/pull/51)
- Remove re-export of `cgp-inner` from `cgp-core`.
- Re-export `cgp-inner` and `cgp-runtime` from `cgp-extra`.
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"crates/cgp-field-macro",
"crates/cgp-field-macro-lib",
"crates/cgp-error",
"crates/cgp-error-extra",
"crates/cgp-error-anyhow",
"crates/cgp-error-eyre",
"crates/cgp-error-std",
Expand Down Expand Up @@ -48,6 +49,7 @@ cgp-field = { path = "./crates/cgp-field" }
cgp-field-macro = { path = "./crates/cgp-field-macro" }
cgp-field-macro-lib = { path = "./crates/cgp-field-macro-lib" }
cgp-error = { path = "./crates/cgp-error" }
cgp-error-extra = { path = "./crates/cgp-error-extra" }
cgp-run = { path = "./crates/cgp-run" }
cgp-runtime = { path = "./crates/cgp-runtime" }
cgp-inner = { path = "./crates/cgp-inner" }
1 change: 1 addition & 0 deletions crates/cgp-async-macro/src/strip_async.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::vec::Vec;

use proc_macro2::{Group, TokenStream, TokenTree};
use syn::parse::{Parse, ParseStream};
use syn::token::{Async, Await, Dot, Fn};
Expand Down
4 changes: 1 addition & 3 deletions crates/cgp-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

pub mod traits;

pub use traits::{Async, MaybeSend, MaybeStatic, MaybeSync};

#[cfg(feature = "async")]
pub use cgp_async_macro::native_async as async_trait;

#[cfg(not(feature = "async"))]
pub use cgp_sync::async_trait;
pub use traits::{Async, MaybeSend, MaybeStatic, MaybeSync};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;

use syn::{parse_quote, Generics, ImplItem, ImplItemType, ItemImpl, Path, Type};

use crate::delegate_components::ast::{ComponentAst, DelegateEntriesAst};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::format;

use proc_macro2::Span;
use quote::ToTokens;
use syn::parse::{Parse, ParseStream};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::boxed::Box;
use alloc::vec::Vec;

use syn::punctuated::Punctuated;
use syn::token::{Brace, Comma, For, Impl, Plus};
use syn::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::vec::Vec;

use proc_macro2::TokenStream;
use quote::quote;
use syn::{parse_quote, ImplItemFn, Signature, TypePath, Visibility};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::boxed::Box;
use alloc::vec::Vec;

use proc_macro2::Span;
use syn::punctuated::Punctuated;
use syn::token::{Brace, Comma, For, Impl, Plus};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::vec::Vec;

use syn::punctuated::Punctuated;
use syn::{parse_quote, Ident, ItemTrait, TraitItem};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::vec::Vec;

use itertools::Itertools;
use proc_macro2::{Group, Ident, TokenStream, TokenTree};
use quote::{format_ident, ToTokens};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::string::{String, ToString};

use proc_macro2::Span;
use syn::Ident;

Expand Down
1 change: 1 addition & 0 deletions crates/cgp-component-macro-lib/src/for_each_replace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::vec::Vec;

use proc_macro2::{Group, TokenStream, TokenTree};
use quote::{quote, ToTokens};
use syn::__private::parse_brackets;
Expand Down
1 change: 1 addition & 0 deletions crates/cgp-component-macro-lib/src/preset/define_preset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::format;
use alloc::string::ToString;

use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use syn::{parse_quote, Ident, ItemTrait};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::vec::Vec;

use syn::{parse_quote, Generics, Ident, ItemImpl, Type};

use crate::delegate_components::ast::{ComponentAst, DelegateEntriesAst};
Expand Down
1 change: 1 addition & 0 deletions crates/cgp-component-macro-lib/src/tests/helper/format.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::string::{String, ToString};

use prettyplease::unparse;
use proc_macro2::TokenStream;
use syn::parse_file;
Expand Down
4 changes: 2 additions & 2 deletions crates/cgp-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
This crate defines the core CGP traits, [`DelegateComponent`] and [`HasComponents`].
*/

pub mod traits;
pub mod types;
mod traits;
mod types;

pub use traits::{DelegateComponent, HasComponents};
pub use types::{UseContext, UseDelegate, WithContext, WithProvider};
4 changes: 2 additions & 2 deletions crates/cgp-component/src/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod delegate_component;
pub mod has_components;
mod delegate_component;
mod has_components;

pub use delegate_component::DelegateComponent;
pub use has_components::HasComponents;
6 changes: 3 additions & 3 deletions crates/cgp-component/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod use_context;
pub mod use_delegate;
pub mod with_provider;
mod use_context;
mod use_delegate;
mod with_provider;

pub use use_context::{UseContext, WithContext};
pub use use_delegate::UseDelegate;
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-core/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pub use cgp_component::{DelegateComponent, HasComponents};
pub use cgp_component_macro::{
cgp_component, cgp_preset, delegate_components, for_each_replace, replace_with,
};
pub use cgp_error::traits::{CanRaiseError, CanWrapError, HasErrorType};
pub use cgp_error::{CanRaiseError, CanWrapError, HasErrorType};
pub use cgp_field::{Char, Cons, Either, HasField, HasFieldMut, Nil, Void};
pub use cgp_field_macro::{product, symbol, HasField, Product, Sum};
16 changes: 8 additions & 8 deletions crates/cgp-error-anyhow/src/impls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod debug_error;
pub mod display_error;
pub mod raise_anyhow_error;
pub mod use_anyhow_error;
mod debug_error;
mod display_error;
mod raise_anyhow_error;
mod use_anyhow_error;

pub use debug_error::*;
pub use display_error::*;
pub use raise_anyhow_error::*;
pub use use_anyhow_error::*;
pub use debug_error::DebugAnyhowError;
pub use display_error::DisplayAnyhowError;
pub use raise_anyhow_error::RaiseAnyhowError;
pub use use_anyhow_error::UseAnyhowError;
4 changes: 2 additions & 2 deletions crates/cgp-error-anyhow/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]

pub mod impls;
mod impls;

pub use impls::*;
pub use impls::{DebugAnyhowError, DisplayAnyhowError, RaiseAnyhowError, UseAnyhowError};
19 changes: 19 additions & 0 deletions crates/cgp-error-extra/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "cgp-error-extra"
version = "0.2.0"
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
authors = { workspace = true }
rust-version = { workspace = true }
keywords = { workspace = true }
description = """
Context-generic programming error components
"""

[features]
default = [ "alloc" ]
alloc = []

[dependencies]
cgp-error = { version = "0.2.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::format;
use alloc::string::String;
use core::fmt::Debug;

use crate::traits::{CanRaiseError, ErrorRaiser};
use cgp_error::{CanRaiseError, ErrorRaiser};

pub struct DebugError;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::format;
use alloc::string::String;
use core::fmt::Display;

use crate::traits::{CanRaiseError, ErrorRaiser};
use cgp_error::{CanRaiseError, ErrorRaiser};

pub struct DisplayError;

Expand Down
5 changes: 5 additions & 0 deletions crates/cgp-error-extra/src/impls/alloc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod debug_error;
mod display_error;

pub use debug_error::DebugError;
pub use display_error::DisplayError;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::traits::{ErrorWrapper, HasErrorType};
use cgp_error::{ErrorWrapper, HasErrorType};

pub struct DiscardDetail;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::convert::Infallible;

use crate::traits::{ErrorRaiser, HasErrorType};
use cgp_error::{ErrorRaiser, HasErrorType};

pub struct RaiseInfallible;

Expand Down
17 changes: 17 additions & 0 deletions crates/cgp-error-extra/src/impls/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[cfg(feature = "alloc")]
mod alloc;

mod discard_detail;
mod infallible;
mod panic_error;
mod raise_from;
mod return_error;

#[cfg(feature = "alloc")]
pub use alloc::{DebugError, DisplayError};

pub use discard_detail::DiscardDetail;
pub use infallible::RaiseInfallible;
pub use panic_error::PanicOnError;
pub use raise_from::RaiseFrom;
pub use return_error::ReturnError;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::fmt::Debug;

use crate::traits::{ErrorRaiser, HasErrorType};
use cgp_error::{ErrorRaiser, HasErrorType};

pub struct PanicOnError;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::traits::{ErrorRaiser, HasErrorType};
use cgp_error::{ErrorRaiser, HasErrorType};

pub struct RaiseFrom;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::traits::{ErrorRaiser, HasErrorType};
use cgp_error::{ErrorRaiser, HasErrorType};

pub struct ReturnError;

Expand Down
10 changes: 10 additions & 0 deletions crates/cgp-error-extra/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![no_std]

#[cfg(feature = "alloc")]
extern crate alloc;

mod impls;

#[cfg(feature = "alloc")]
pub use impls::{DebugError, DisplayError};
pub use impls::{DiscardDetail, PanicOnError, RaiseFrom, RaiseInfallible, ReturnError};
16 changes: 8 additions & 8 deletions crates/cgp-error-eyre/src/impls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod debug_error;
pub mod display_error;
pub mod raise_eyre_error;
pub mod use_eyre_error;
mod debug_error;
mod display_error;
mod raise_eyre_error;
mod use_eyre_error;

pub use debug_error::*;
pub use display_error::*;
pub use raise_eyre_error::*;
pub use use_eyre_error::*;
pub use debug_error::DebugEyreError;
pub use display_error::DisplayEyreError;
pub use raise_eyre_error::RaiseEyreError;
pub use use_eyre_error::UseEyreError;
4 changes: 2 additions & 2 deletions crates/cgp-error-eyre/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]

pub mod impls;
mod impls;

pub use impls::*;
pub use impls::{DebugEyreError, DisplayEyreError, RaiseEyreError, UseEyreError};
4 changes: 2 additions & 2 deletions crates/cgp-error-std/src/impls/debug_error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt::Debug;

use alloc::boxed::Box;
use alloc::format;
use core::fmt::Debug;

use cgp_core::error::{ErrorRaiser, HasErrorType};

use crate::types::{Error, StringError};
Expand Down
4 changes: 2 additions & 2 deletions crates/cgp-error-std/src/impls/display_error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt::Display;

use alloc::boxed::Box;
use alloc::format;
use core::fmt::Display;

use cgp_core::error::{ErrorRaiser, HasErrorType};

use crate::types::{Error, StringError};
Expand Down
16 changes: 8 additions & 8 deletions crates/cgp-error-std/src/impls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod debug_error;
pub mod display_error;
pub mod raise_boxed;
pub mod use_boxed;
mod debug_error;
mod display_error;
mod raise_boxed;
mod use_boxed;

pub use debug_error::*;
pub use display_error::*;
pub use raise_boxed::*;
pub use use_boxed::*;
pub use debug_error::DebugBoxedStdError;
pub use display_error::DisplayBoxedStdError;
pub use raise_boxed::RaiseBoxedStdError;
pub use use_boxed::UseBoxedStdError;
8 changes: 4 additions & 4 deletions crates/cgp-error-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

extern crate alloc;

pub mod impls;
pub mod types;
mod impls;
mod types;

pub use impls::*;
pub use types::*;
pub use impls::{DebugBoxedStdError, DisplayBoxedStdError, RaiseBoxedStdError, UseBoxedStdError};
pub use types::{Error, StringError};
Loading

0 comments on commit 454a34b

Please sign in to comment.