Conversation
b96c07a to
16aa7e2
Compare
|
Thanks for the PR @djugei! I think we can get away without the pub trait GlobalLog: Log + Any {}
impl<T: Log + Any> GlobalLog for T {}I did look at a few alternative designs that try to fully hide the downcasting support, but they all had unsatisfying trade-offs since we accept a |
|
just makes user code a bit uglier is this feature in general something the project would like to add? |
16aa7e2 to
01dc02c
Compare
|
I'd be in favour of this approach with the |
|
I think this a breaking change. We didn't the |
|
@Thomasdezeeuw Yeh I checked this as well, and couldn’t actually trigger a compile error by flipping from Adding an |
|
Not 100% accurate, but I think https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=7e1712bc6dbdeb86780c85de4b0a7e6c shows it's a problem. |
|
i tried doing i think any concrete type that implements Log will also implement Any, but if you have a function that bounds only on Log then the compiler is ignorant of that fact, so yeah i guess this is a breaking change after all, though one that can be fixed with minimal changes/no structural changes. |
|
Ah yes I see. If you explicitly already have a That would mean we’d have to introduce a new set of APIs for this if we wanted to do it and deprecate the old ones. I’m not sure that level of churn is worth it. |
it is even worse than that: since we need to store the logger we have to decide on a concrete type, so those would be 2 completely separate apis, which does not make a lot of sense to me, as it would essentially be keeping two versions. in that case i would just keep one version in the library and let cargo do its job for versioning. alternatively we can try to think about &'static Log always being Any a bit harder and maybe do an unsafe cast if we can convince ourselves that it is always safe? i sadly do not know a ton about trait objects. then again this functionality is achievable without using Any at all (see issue) but uses unsafe to do so in the first place. i was hoping for an elegant solution with Any. |
This approach of comparing vtables is unfortunately generally unsound. Probably the cleanest solution would be to introduce the If we could smuggle a type id in the |
i think the cleanest solution would be to just introduce the |
|
I don't think have another trait to do logging is a great idea, especially if it's not compatible with the existing logger. |
|
I think we’ve found ourselves a bit limited in options here, so until/unless we consider a breaking change to the library, this is probably not going to be possible to support directly in |
fixes #666.
i do not expect this to be merged as is, this is more of a discussion helper. Names are up for bikeshedding.
technically this is not a breaking change i think, as anything that implements log automatically implements LogAny though i agree that it looks weird.
can't just have a method on Log sadly as that would introduce a
Sizedrequirement (for some reason). Can't add the Any bound to Log itself as it would need to be 'statici have tested this with indicatif-log-bridge and env_logger and it works