-
Notifications
You must be signed in to change notification settings - Fork 82
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
Allow flattening of a struct through derive(EncodeLabelSet) at any position #135
Comments
Thanks for debugging and the detailed issue.
Worth exploring passing Another alternative is to provide a better error message in the derive macro when the flattened property is not the last. |
My initial impression is that this would be a welcome API change. If we could |
@mxinden I see that you added the
I would be happy to work on this! I'd like to follow the former path, leaving us with these signatures: pub trait EncodeLabelSet {
/// Encode oneself into the given encoder.
fn encode(&self, encoder: &mut LabelSetEncoder) -> Result<(), std::fmt::Error>;
}
pub trait EncodeLabel {
/// Encode oneself into the given encoder.
fn encode(&self, encoder: &mut LabelEncoder) -> Result<(), std::fmt::Error>;
} This seems especially reasonable because today While we are doing this, we should also update |
To help reduce the churn of breaking changes, presuming the above change is welcome, would it also make sense to update the signature of the Lines 38 to 41 in ad05f0f
Lines 43 to 46 in ad05f0f
This would leave us with a consistent interface across the board, where |
That makes sense. Thank you. While a breaking change, I doubt it would break many people. Thus I think it is worth it. Of course in a semver compliant next version. @cratelyn thank you for the help! |
@mxinden of course! i'll open up a PR soon, likely some time early next week. i will try and open up a fix to #231 in parallel, likewise, thanks for being open to a change! the strongly-typed label sets in this library is a really lovely ergonomic improvement from the predecessor library. |
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
…eEncoder` see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
…eEncoder` see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
…eEncoder` see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
pardon my delay in getting to this, i've had a busy couple of weeks. i've opened #240 to adjust the signatures to encoding traits mentioned above. |
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
…eEncoder` see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
…eEncoder` see prometheus#135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin <[email protected]>
Currently when deriving
EncodeLabelSet
and flattening a struct the flattened struct must appear last, and there must be only one flattened struct, from the test:If you place
common
beforeunique
instruct Labels
like this:Compilation fails:
This occurs because ownership of
encoder
is given to the flattened structI think this would be a breaking change to fix, but fixing it would allow fields to appear in any order, or allow flattening of multiple structs without nesting them all one inside the other in tail position.
The text was updated successfully, but these errors were encountered: