-
Notifications
You must be signed in to change notification settings - Fork 640
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
Consider not deriving serde
impls from units
types
#2612
Comments
serde
feature/dependency from units
serde
impls from units
types
I don't understand. Right now we have e.g. the For the locktime types things are less clear (should we have serde on |
You were too quick. I've updated the issue |
Having an implementation is definitely valuable for auto-derive users. I can imagine something like struct GetTransactionInfo {
pub reciever: Address,
pub fee: Amount,
pub sent_amount: Amount,
} requiring an auto-derive. |
We have that usecase covered already, one can do: struct GetTransactionInfo {
...
#[serde(with = "bitcoin::amount::serde::as_sat")]
pub fee: Amount,
...
} I haven't thought it through for other unit types but we want to provide some way to be able to derive them too. |
I just had a play and if we remove the serde imples it is annoying to not be able to do #[derive(Debug, Serialize, Deserialize)]
struct Foo {
height: absolute::Height,
time: absolute::Time,
} And it is surprising that #[derive(Debug, Serialize, Deserialize)]
struct Bar {
lt: absolute::LockTime
} is fine but using Do we gain anything by not allowing |
Amount is probably the most important one. If we have that covered, I am okay dropping the serde requirement from units. Users dealing with Height and Time are advanced users that can do their own serde. |
Agreed. I do not think we should change Meanwhile I'm fine keeping them, but they are a weird bit of API surface that if we commit to, we're stuck with forever.
It still seems to imply that we should get rid of |
But It is possible that some users can just use |
serde
impls from units
typesserde
impls from units
types
I re-edited the description, third time lucky. |
I agree, |
Closing, this does not seem to be going anywhere. We can re-visit this at a later time if needed. |
Note at this stage we do have |
Types in
units
are thin wrappers around integer values. If users of these types want to put them in structs they can, and possibly should, stipulate how they want them serialized (eg, amount could be as sats or as BTC).Shall we remove
serde::Deserialize
andserde::Serialize
impls fromunits
types? Note this does not mean remove theserde
module fromAmount
, just remove#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
fromAmount
(and from all otherunits
types).The text was updated successfully, but these errors were encountered: