Skip to content
Open
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
62 changes: 61 additions & 1 deletion cot/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::utils::chrono::DateTimeWithOffsetAdapter;
///
/// This is all the project-specific configuration data that can (and makes
/// sense to) be expressed in a TOML configuration file.
#[derive(Debug, Clone, PartialEq, Eq, Builder, Serialize, Deserialize)]
#[derive(Debug, Clone, Builder, Serialize, Deserialize)]
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing PartialEq/Eq from ProjectConfig is a breaking public API change (downstream code may rely on equality comparisons). If toml::Table prevents deriving Eq, consider restoring at least PartialEq (either via derive if supported, or via a manual impl PartialEq), or document this as a breaking change requiring a major version bump.

Suggested change
#[derive(Debug, Clone, Builder, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Builder, Serialize, Deserialize)]

Copilot uses AI. Check for mistakes.
#[builder(build_fn(skip, error = std::convert::Infallible))]
#[serde(default)]
#[non_exhaustive]
Expand Down Expand Up @@ -271,6 +271,40 @@ pub struct ProjectConfig {
/// ```
#[cfg(feature = "email")]
pub email: EmailConfig,
/// All the config that was not recognized.
///
/// This is useful for parsing project-specific config that is not part of
/// any of the predefined fields in `ProjectConfig`.
///
/// # Examples
///
/// ```
/// use cot::config::ProjectConfig;
/// use serde::Deserialize;
///
/// let config = ProjectConfig::from_toml(
/// r#"
/// [my_cot_project]
/// foo = "bar"
/// "#,
/// )?;
///
/// #[derive(Deserialize)]
/// struct MyCotProjectConfig {
/// foo: String,
/// }
///
/// let my_config: MyCotProjectConfig = config
/// .extra
/// .get("my_cot_project")
/// .ok_or("could not find the project config")?
/// .clone()
/// .try_into()?;
/// assert_eq!(my_config.foo, "bar");
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[serde(flatten)]
pub extra: toml::Table,
}

const fn default_debug() -> bool {
Expand Down Expand Up @@ -381,6 +415,7 @@ impl ProjectConfigBuilder {
middlewares: self.middlewares.clone().unwrap_or_default(),
#[cfg(feature = "email")]
email: self.email.clone().unwrap_or_default(),
extra: Default::default(),
}
}
}
Expand Down Expand Up @@ -3116,4 +3151,29 @@ mod tests {
assert_eq!(u1, u2);
assert_eq!(u1.as_str(), s);
}

#[test]
fn config_extra_can_be_accessed() {
#[derive(Deserialize)]
struct CustomConfig {
foo: String,
}

let config = ProjectConfig::from_toml(
r#"
[custom_config]
foo = "bar"
"#,
)
.unwrap();

let my_config: CustomConfig = config
.extra
.get("custom_config")
.unwrap()
.clone()
.try_into()
.unwrap();
assert_eq!(my_config.foo, "bar");
}
}
1 change: 1 addition & 0 deletions cot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub use cot_macros::test;
pub use http;
#[cfg(feature = "openapi")]
pub use schemars;
pub use toml;
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-exporting the entire toml crate expands your public surface area and tightly couples your semver to toml’s API (any toml breaking change can become your breaking change). Prefer re-exporting only the needed items (e.g., toml::Table / toml::Value) or exposing them through your own types to keep the public API smaller and more stable.

Suggested change
pub use toml;
pub use toml::{Table, Value};

Copilot uses AI. Check for mistakes.

pub use crate::__private::askama::{Template, filter_fn};
pub use crate::project::{
Expand Down
Loading