Summary
The README and multiple inline doc comments reference a build() constructor method on Date, Time, and DateTime:
// From the README:
let mut time = Time::build("T23:17:12Z.000")?;
let mut datetime = DateTime::build("2024-10-31 06:32:28")?;
// From date.rs doc comments:
let date = Date::build("2023-10-09")?;
// From time.rs doc comments:
let time = Time::build("12:21:46")?;
// From datetime.rs doc comments:
let datetime = DateTime::build("2023-05-17 09:05:12")?;
None of these compile. No build method exists on any of the three types. The nearest equivalent is TryFrom<&str>:
let date = Date::try_from("2023-10-09")?;
This is a documentation correctness bug that directly misleads new users, causes the README code examples to fail if copied, and degrades trust in the library.
Root Cause
The build naming was used in early design sketches or a previous API version and was referenced in documentation without being implemented. The Span trait's new(y, m, d) constructor is for component-based construction; string-based construction was left only as TryFrom<&str> with no named method alias.
Proposed Fix
Option A — Add build() as a named constructor (recommended)
Add a build inherent method to each type that delegates to TryFrom<&str>:
impl Date {
/// Parse a `Date` from a string using the active `BASE_DATE_FORMAT`.
///
/// # Example
/// ```rust
/// let date = Date::build("2024-10-31")?;
/// assert_eq!(date.to_string(), "2024-10-31");
/// ```
pub fn build(s: &str) -> Result<Self, SpanError> {
Self::try_from(s)
}
}
Identical additions for Time::build(s: &str) and DateTime::build(s: &str).
This approach:
Option B — Update all docs to use TryFrom
Replace every Type::build("...") reference in the README and doc comments with Type::try_from("...") or "...".parse::<Type>(). Lower effort, but makes the README less readable and requires updating every example.
Option A is strongly preferred — the method name build is already established in the library's mental model and documentation.
Affected Locations
| File |
Reference |
README.md |
Lines referencing Time::build, DateTime::build |
date.rs |
Doc comment on clear_unit |
time.rs |
Doc comment on clear_unit |
datetime.rs |
Doc comment on clear_unit |
Acceptance Criteria
Summary
The README and multiple inline doc comments reference a
build()constructor method onDate,Time, andDateTime:None of these compile. No
buildmethod exists on any of the three types. The nearest equivalent isTryFrom<&str>:This is a documentation correctness bug that directly misleads new users, causes the README code examples to fail if copied, and degrades trust in the library.
Root Cause
The
buildnaming was used in early design sketches or a previous API version and was referenced in documentation without being implemented. TheSpantrait'snew(y, m, d)constructor is for component-based construction; string-based construction was left only asTryFrom<&str>with no named method alias.Proposed Fix
Option A — Add
build()as a named constructor (recommended)Add a
buildinherent method to each type that delegates toTryFrom<&str>:Identical additions for
Time::build(s: &str)andDateTime::build(s: &str).This approach:
SpanBuilder::builder())FromStrimplementation proposed in issue feat: implement std::str::FromStr for Date, Time and DateTime #54Option B — Update all docs to use
TryFromReplace every
Type::build("...")reference in the README and doc comments withType::try_from("...")or"...".parse::<Type>(). Lower effort, but makes the README less readable and requires updating every example.Option A is strongly preferred — the method name
buildis already established in the library's mental model and documentation.Affected Locations
README.mdTime::build,DateTime::builddate.rsclear_unittime.rsclear_unitdatetime.rsclear_unitAcceptance Criteria
Date::build(s: &str) -> Result<Self, SpanError>addedTime::build(s: &str) -> Result<Self, SpanError>addedDateTime::build(s: &str) -> Result<Self, SpanError>addedTryFrom<&str>and useBASE_*_FORMATcargo test --docpasses)cargo test --docpasses)buildmethods are exported frompreludevia the type re-exports (inherent methods, so this is automatic)Spantrait updated or doc-commented to referencebuildas the string-parsing entry point