-
Notifications
You must be signed in to change notification settings - Fork 40
Restructure project to separate core provider APIs from non-provider APIs #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9df66e5
Progress on structural changes to support the new layout
nekevss 4e904fa
Complete initial work on project restructure
nekevss 5a5d2b9
Merge branch 'main' into lib-restructure-concept
nekevss 11196eb
Post merge cleanup and add string methods to native Duration
nekevss ca74ec2
Fix lints + display impls
nekevss cb9137a
cargo fmt
nekevss 93fd1d8
Core should always be public
nekevss a8abb5b
Add an lib architercture doc
nekevss 56b385f
Fix typos
nekevss 325bad1
Merge branch 'main' into lib-restructure-concept
nekevss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # Library Architecture | ||
|
|
||
| TODO: FFI docs | ||
|
|
||
| This doc provides an overview of the layout of `temporal_rs`. | ||
|
|
||
| We will go over the Temporal Date/Time builtins, general primitives, and | ||
| utiltity crates. | ||
|
|
||
| ## `temporal_rs` design considerations | ||
|
|
||
| `temporal_rs` is first and foremost designed to be a fully spec | ||
| compliant implementation of ECMAScript's Temporal date/time builtins. | ||
|
|
||
| As such, the main design consideration of `temporal_rs` is that it needs | ||
| to be able to service language interpreters / engines. | ||
|
|
||
| Thus, `temporal_rs` aims to provide an API along with tools to implement | ||
| Temporal while minimizing issue with integrating Temporal into engines. | ||
|
|
||
| ## Date/Time builtins | ||
|
|
||
| The primary date & time builtins/components are located in the | ||
| `builtins` directory. | ||
|
|
||
| These builtins are then reexported from `lib.rs` to be available from | ||
| `temporal_rs`'s root module. | ||
|
|
||
| ### Core vs. Native | ||
|
|
||
| `temporal_rs`'s builtins are split in two distinct directories `core` | ||
| and `native`. The core implementation contains the core implementation | ||
| of the Temporal builtins; meanwhile, the `native` implementation is a | ||
| Rust wrapper around the `core` implementation that simplifies some | ||
| "lower" level date/time API that may not be necessary for a general use | ||
| case. | ||
|
|
||
| ### Core implementation | ||
|
|
||
| The core implementation is always publicly available, but may not be | ||
| available to import from the `temporal_rs`'s root. | ||
|
|
||
| The core implementation can be made available from the root by providing | ||
| the `--no-default-feautres` flag. | ||
|
|
||
| The core implementation exposes the Provider API that allows the user to | ||
| supply a "provider", or any type that implements the `TimeZoneProvider` | ||
| trait, for time zone data that the library can use to complete it's | ||
| calculations. This is useful from an engine / implementor perspective | ||
| because it allows the engine to source time zone data in their preferred | ||
| manner without locking them into a library specific implementation that | ||
| may or may not have side affects. | ||
|
|
||
| A `TimeZoneProvider` API on a core builtin will look like the below. | ||
|
|
||
| ```rust | ||
| impl ZonedDateTime { | ||
| pub fn day_with_provider(&self, provider: &impl TimeZoneProvider) -> TemporalResult<u8> { | ||
| // Code goes here. | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Native implementation | ||
|
|
||
| The native implementation is only available via the "full" default | ||
| feature flag. | ||
|
|
||
| For the same reason that the Provider API is useful for language | ||
| implementors, it is a deterent from a general use case perspective. Most | ||
| people using a datetime library, outside of the self-proclaimed time | ||
| zone nerds, probably won't care from where their time zone data is being | ||
| sourced. | ||
|
|
||
| The native Rust wrapper of the core implementation provides a default | ||
| provider implementation to remove the need of the user to think or deal | ||
| with `TimeZoneProvider`. | ||
|
|
||
| ```rust | ||
| impl ZonedDateTime { | ||
| pub fn day(&self) -> TemporalResult<u8> { | ||
| // Code goes here. | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| This greatly simplifies the API for general use cases. | ||
|
|
||
| ## Primitives | ||
|
|
||
| <!-- Should IsoDate, IsoTime, and IsoDateTime be considered primitives? --> | ||
|
|
||
| `temporal_rs` has a primitive number implementation `FiniteF64` along | ||
| with a few date and time primitives: `IsoDate`, `IsoTime`, | ||
| `IsoDateTime`, and `EpochNanoseconds`. | ||
|
|
||
| `FiniteF64` allows an interface to translate between ECMAScript's number | ||
| type vs. `temporal_rs`'s strictly typed API. | ||
|
|
||
| Meanwhile the Date and Time primitives allow certain invariants to be | ||
| enforced on their records. | ||
|
|
||
| ## Utiltiies | ||
|
|
||
| `temporal_rs` provides one implementation of the `TimeZoneProvider` | ||
| trait: `FsTzdbProvider`. | ||
|
|
||
| `FsTzdbProvider` reads from the file systems' tzdb and when not | ||
| available on the system, `FsTzdbProvider` relies on a prepackaged | ||
| `tzdb`. | ||
|
|
||
| <!-- TODO: add some more about parsers --> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.