Closed EthanJamesLew closed 7 months ago
Hmm, I don't think const_new
is something that common. This is just a variant which allows creation of struct
s in const contexts, which might be useful for some cases. The caveat here of course is that I can not perform regular error handling, so I don't really have any other choice than to panic on invalid/unsanitized input. The new
APIs should not panic however, do you have concrete examples?
About the subsec_millis
being greater than 999: It is assumed that the subsec_millis
only contain the millisecond part on top of the full UNIX seconds, so a value greater than 999 would be an additional second.
Big changes for everything you mentioned are coming in version 0.11.
I renamed the const_new
methods to new
and renamed the former new
methods to new_checked
. This is more in line with how it is done in the Rust ecosystem.
The new UnixTime
timestamp type now consists of a second part (i32
) and a nanoseconds part (i64
). The same rules still apply though: A nano second value larger or equal to 1_000_000_000
is considered invalid.
@robamu great to know, thanks!
Also, I will close this issue as my questions have been answered (a long time ago :) )
Hello!
I've been quite interested in a rust implementation of spacepackets and have enjoyed using your project.
I have been grokking the codebase of the Rust spacepacket implementation and noticed the use of panics in the builder methods, specifically in the
const_new
andnew
functions of various structs. While I understand that panics are a part of Rust's error handling mechanism and can be useful for catching exceptional cases, I have concerns regarding their usage in these particular scenarios.First, in the
UnixTimestamp
struct, theconst_new
function panics if thesubsec_millis
value exceeds 999. Similarly, in thePacketSequenceCtrl
struct, both theconst_new
and new functions panic if theseq_count
value exceeds MAX_SEQ_COUNT. Although panics can be appropriate for handling unexpected or invalid inputs, I'm unsure whether they are the best approach in these cases. I do understand for the latter example that these panic conditions are checked before calling, so they won't panic in those cases.const_new
andnew
, common for Rust 2021 projects? Would there be preferable ways to callconst_new
without requiring the caller to check the panic conditions?subsec_millis
greater than 999? Would there be cases where the value may be user-specified?Thank you,
Ethan