[WIP] feat(std): add time module to standard library#779
[WIP] feat(std): add time module to standard library#779Etherian wants to merge 26 commits intogluon-lang:masterfrom
Conversation
|
Here's my rough draft of a For now, I'm stuck on an error that occurs when I attempt to import Any suggestions? |
👍 |
I don't think a feature is warranted for modules mirroring rusts std library. If we end up seeing that gluon's standard library is to large at some point it could be investigated then. |
|
Adding error[E0053]: method `deep_clone` has an incompatible type for trait
--> src\std_lib\time.rs:16:24
|
16 | #[derive(Clone, Debug, Userdata, Trace, VmType)]
| ^^^^^^^^ expected struct `vm::gc::Borrow`, found struct `vm::gc::GcPtr`
|
= note: expected type `fn(&std_lib::time::Duration, &'gc mut vm::api::Cloner<'_>) -> std::result::Result<vm::gc::Borrow<'gc, vm::gc::GcPtr<std::boxed::Box<(dyn vm::api::Userdata + 'static)>>>, vm::Error>`
found type `fn(&std_lib::time::Duration, &mut vm::api::Cloner<'_>) -> std::result::Result<vm::gc::GcPtr<std::boxed::Box<(dyn vm::api::Userdata + 'static)>>, vm::Error>`
error[E0308]: mismatched types
--> src\std_lib\time.rs:16:24
|
16 | #[derive(Clone, Debug, Userdata, Trace, VmType)]
| ^^^^^^^^
| |
| expected struct `vm::gc::GcPtr`, found struct `vm::gc::Borrow`
| expected `std::result::Result<vm::gc::GcPtr<std::boxed::Box<(dyn vm::api::Userdata + 'static)>>, vm::Error>` because of return type
|
= note: expected type `std::result::Result<vm::gc::GcPtr<std::boxed::Box<(dyn vm::api::Userdata + 'static)>>, _>`
found type `std::result::Result<vm::gc::Borrow<'_, vm::gc::GcPtr<std::boxed::Box<dyn vm::api::Userdata>>, >, _>` |
|
Could you mentor me regarding tests for this module? I don't have much experience writing tests and I am not confident I can write them correctly and thoroughly. Maybe you could give me examples or an outline of what properties to test and how to test those properties? Also, how do I include documentation for external types and values? |
|
Since this is mostly just exposing functions defined and tested by rust itself I don't think the testing needs to be so thorough. Having some examples like in https://doc.rust-lang.org/std/time/struct.Duration.html would be good though. There isn't a way to define documentation in rust code so you will need to define it in the gluon module Doc tests require some unfortunate boilerplate atm, but you can look at the json module for how they are done Lines 67 to 77 in a507ed0 |
…reak referential transparency
|
I finally got around to finishing the doc comments for |
|
|
|
It looks like doc comments are not currently recognized on record entries, which is where I have placed my docs for the time modules. Could this behavior be added, and/or should I restructure my gluon files so doc comments are all attached to let bindings? |
|
I'm running into a few errors while testing the examples. This line in some examples seems to cause the following error: Replacing the lambdas with Various other errors occur unpredictably. In fact, one time all the tests passed without any of these errors. I don't have any guesses as to why they are occurring. Full output of a test run |
|
@Marwes Have you had a chance to look at this? |
|
Sorry, no. Haven't had that much motivation to code outside of work lately. Won't have time over the weekend either but I will try to look at it next week. |
|
Sure. No rush. 🙂 |
|
The good news is no conflicts have cropped up. The bad news is that it's still throwing errors I don't know how to solve. Do you have time to take a look, @Marwes? |
Description
Adds a
timemodule to the standard library which exposes the functionality of Rust'sstd::time.Status
In Development
Outstanding design questions
How should(std.timebe structured --std.time.Instant.now,std.time.instant_now,std.instant.now, or something else?std.time.Instant.now)Should(not behind feature)std.timebe behind a feature? Should that feature be default?To Do
std::timeEqandOrd)In Rust code?(no need)Add tests(no need)Future Directions
duration.from_secs_float,duration.as_secs_float,duration.mul_float, andduration.div_float