Skip to content

feat: Implement From<DbFieldValue> for Non primitive types#562

Open
ElijahAhianyo wants to merge 16 commits intomasterfrom
elijah/limitedstring-option
Open

feat: Implement From<DbFieldValue> for Non primitive types#562
ElijahAhianyo wants to merge 16 commits intomasterfrom
elijah/limitedstring-option

Conversation

@ElijahAhianyo
Copy link
Copy Markdown
Contributor

@ElijahAhianyo ElijahAhianyo commented Apr 29, 2026

Description

Fixes the error below as a result of having an Option<LimitedString<u32>> in a model:

#[derive(Debug, Clone)
#[model]
Struct Foo {
    name: Option<LimitedString<255>>
}

Error:

error[E0277]: the trait bound `std::option::Option<LimitedString<255>>: FromDbValue` is not satisfied
   --> src/main.rs:16:18
    |
  7 | #[model]
    | -------- required by a bound introduced by this call
...
 16 |     name:  Option<LimitedString<255>>,
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromDbValue` is not implemented for `std::option::Option<LimitedString<512>>`
    |
    = help: the following other types implement trait `FromDbValue`:
              std::option::Option<ForeignKey<T>>
              std::option::Option<NaiveDate>
              std::option::Option<NaiveDateTime>
              std::option::Option<NaiveTime>
              std::option::Option<Vec<u8>>
              std::option::Option<WeekdaySet>
              std::option::Option<bool>
              std::option::Option<chrono::DateTime<FixedOffset>>
            and 14 others
note: required by a bound in `Row::get`
   --> /Users/eli/Documents/work/cot/cot/cot/src/db.rs:450:19
    |
450 |     pub fn get<T: FromDbValue>(&self, index: usize) -> Result<T> {
    |                   ^^^^^^^^^^^ required by this bound in `Row::get`

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / cleanup
  • Performance improvement
  • Other (describe above)

@github-actions github-actions Bot added the C-lib Crate: cot (main library crate) label Apr 29, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

🐰 Bencher Report

Branchelijah/limitedstring-option
Testbedgithub-ubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
empty_router/empty_router📈 view plot
🚷 view threshold
5,673.20 µs
(-6.77%)Baseline: 6,085.39 µs
7,606.56 µs
(74.58%)
json_api/json_api📈 view plot
🚷 view threshold
1,025.30 µs
(-4.16%)Baseline: 1,069.85 µs
1,305.48 µs
(78.54%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
979.27 µs
(-0.76%)Baseline: 986.72 µs
1,189.50 µs
(82.33%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
950.39 µs
(+0.13%)Baseline: 949.16 µs
1,153.43 µs
(82.40%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
17,387.00 µs
(-1.62%)Baseline: 17,672.83 µs
21,318.54 µs
(81.56%)
🐰 View full continuous benchmarking report in Bencher

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 89.18919% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot/src/common_types.rs 90.00% 0 Missing and 6 partials ⚠️
cot/src/auth.rs 90.00% 0 Missing and 3 partials ⚠️
cot/src/db/fields.rs 85.71% 0 Missing and 3 partials ⚠️
Flag Coverage Δ
rust 90.22% <89.18%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cot/src/auth.rs 91.05% <90.00%> (-0.06%) ⬇️
cot/src/db/fields.rs 87.71% <85.71%> (+1.71%) ⬆️
cot/src/common_types.rs 84.09% <90.00%> (+14.97%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ElijahAhianyo ElijahAhianyo marked this pull request as ready for review April 29, 2026 17:13
@ElijahAhianyo ElijahAhianyo marked this pull request as draft April 30, 2026 01:47
@ElijahAhianyo ElijahAhianyo marked this pull request as ready for review April 30, 2026 19:26
@ElijahAhianyo ElijahAhianyo changed the title Implement From<DbFieldValue> for Option<LimitedString<LIMIT>> Implement From<DbFieldValue> for Non primitive types May 3, 2026
@ElijahAhianyo
Copy link
Copy Markdown
Contributor Author

ElijahAhianyo commented May 3, 2026

This also applies to types like Email, PasswordHash, Url.

Comment thread cot/src/db/fields.rs
}
}

impl<const LIMIT: u32> FromDbValue for Option<LimitedString<LIMIT>> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's very arguable that duplication of impl code can be abstracted into the impl_db_field macro. I'm still accessing this. My main concern is prioritizing code readability and reducing the number of special cases when improving the macro to support most cases.

Comment thread cot/tests/db.rs Fixed
ElijahAhianyo and others added 3 commits May 5, 2026 02:00
…phic value'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ElijahAhianyo ElijahAhianyo changed the title Implement From<DbFieldValue> for Non primitive types feat: Implement From<DbFieldValue> for Non primitive types May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-lib Crate: cot (main library crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants