feat(log): add bounded diagnostic transport

This commit is contained in:
Onur Özkan committed 2026-08-09 22:04:06 +03:00
1 parent 632bf9f01b
commit 0a75860841
46 files changed
+2758 -60

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
#[test]
fn kaptan_error_expands_for_enum_shapes_only() {
let tests = trybuild::TestCases::new();
tests.pass("tests/ui/enum.rs");
tests.compile_fail("tests/ui/struct.rs");
tests.compile_fail("tests/ui/union.rs");
}
+47
View File
@@ -0,0 +1,47 @@
extern crate self as kaptan_log;
use kaptan_log_derive::KaptanError;
pub struct StaticErrorMessage(&'static str);
impl StaticErrorMessage {
pub const fn new(text: &'static str) -> Self {
Self(text)
}
pub const fn as_str(&self) -> &'static str {
self.0
}
}
pub trait ErrorReport {
fn error_message(&self) -> &'static StaticErrorMessage;
}
#[derive(Debug, KaptanError)]
enum Generic<'a, T>
where
T: Copy,
{
Unit,
Tuple(T, u8),
Named { label: &'a str },
}
fn main() {
fn assert_error<T: core::error::Error>() {}
assert_error::<Generic<'_, u8>>();
assert_eq!(
Generic::<u8>::Unit.error_message().as_str(),
concat!(module_path!(), "::Generic::Unit"),
);
assert_eq!(
Generic::Tuple(1_u8, 2).error_message().as_str(),
concat!(module_path!(), "::Generic::Tuple"),
);
let named: Generic<'_, u8> = Generic::Named { label: "test" };
assert_eq!(
named.to_string(),
concat!(module_path!(), "::Generic::Named"),
);
}
@@ -0,0 +1,8 @@
use kaptan_log_derive::KaptanError;
#[derive(KaptanError)]
struct NotAnError {
code: u8,
}
fn main() {}
@@ -0,0 +1,5 @@
error: KaptanError can only be derived for enums, not structs
--> tests/ui/struct.rs:4:8
|
4 | struct NotAnError {
| ^^^^^^^^^^
+8
View File
@@ -0,0 +1,8 @@
use kaptan_log_derive::KaptanError;
#[derive(KaptanError)]
union NotAnError {
code: u8,
}
fn main() {}
@@ -0,0 +1,5 @@
error: KaptanError can only be derived for enums, not unions
--> tests/ui/union.rs:4:7
|
4 | union NotAnError {
| ^^^^^^^^^^