Module feed_schedule_entry

Source
Expand description

Contains the data definition for feed schedule entry Defines the application-level representation of a single feed schedule entry.

This module provides the FeedScheduleEntry struct, which is a clean, type-safe representation of a scheduled feeding event. Its primary role is to act as a “hydrated” data model, converting raw data retrieved from the database into a format that the application’s business logic can safely and easily work with.

§Key Components

  • FeedScheduleEntry Struct: The core data structure holding a NaiveDateTime, the associated feed profile ID and name, and a boolean repeat_daily flag.

  • new() Constructor: A fallible constructor that takes a raw SqlFeedScheduleEntry (as defined in sql_interface_feed) and performs the critical conversion of the string-based timestamp into a chrono::NaiveDateTime. It also converts the numeric repeat_daily flag into a proper boolean.

  • fmt::Display Implementation: Provides a simple, human-readable string format for the struct, which is useful for logging and debugging purposes.

§Design and Architecture

This module serves as a crucial boundary between the database layer and the application’s core logic.

  • Data Hydration and Type Safety: The main purpose of this struct is to “hydrate” data from the database. By parsing the timestamp string into a NaiveDateTime at the earliest opportunity, the rest of the application is protected from handling raw strings and can leverage the powerful, type-safe operations provided by the chrono crate. This prevents a whole class of potential bugs related to malformed date strings.

  • Robust Error Handling: The new() constructor returns a Result, explicitly handling the possibility that the timestamp data in the database might be corrupt or in an unexpected format. This forces the calling code to deal with potential data integrity issues gracefully.

  • Testability: The inclusion of a #[cfg(test)] constructor, new_for_test, allows unit tests to create instances of FeedScheduleEntry easily without needing to construct a raw SqlFeedScheduleEntry first.

Structs§

FeedScheduleEntry
Holds the data of a feed schedule entry derived from data read from the database.