1 985
#prog #go линтер, который вообще-то должен быть частью компилятора.
github.com/GaijinEntertainment/go-exhaustruct
14 نوامبر 2022, 23:52
Блог со звёздочкой. Много репостов, немножко программирования. Небольшое прикольное комьюнити: @decltype_chat_ptr_t Автор: @insert_reference_here
نمایش بیشتر#[enum_delegate::register]
trait SayHello {
fn say_hello(&self, name: &str) -> String;
}
struct Arthur;
impl SayHello for Arthur {...}
struct Pablo;
impl SayHello for Pablo {...}
#[enum_delegate::implement(SayHello)]
enum People {
Arthur(Arthur),
Pablo(Pablo),
}
/* разворачивается во что-то вроде:
impl SayHello for People {
fn say_hello(&self, name: &str) {
match self {
Self::Arthur(x) => x.say_hello(name),
Self::Pablo(x) => x.say_hello(name),
}
}
}
а также
impl From<Arthur> for People { ... }
impl TryFrom<People> for Arthur { ... }
*/
Вы, вероятно, спросите, а зачем это, когда есть enum_dispatch. Как пишет автор:
Comparison with enum_dispatch
🟡 Performance: the same. This is expected, since they generate very similar code. (See benchmarks in the repo.)
✅ Works across crates. Due to technical limitations of how enum_dispatch is implemented, it can only be used if both the trait and enum are in the same crate. enum_delegate, however, allows you to put them in separate crates. (See cross_crate_example in the repo.)
✅ Better errors. Again due to technical limitations, in some cases enum_dispatch will quietly fail. With enum_delegate, your code will either succeed, or fail to compile. Admittedly, some of the error messages are not perfect, but at least you'll know something's up. (See tests_error in the repo.)
✅ Associated types. enum_delegate has some support for associated types, but enum_dispatch doesn't. (See examples in the repo.)Why? While travelling through South America network data on carriers is usually restricted to not many GBs but WhatsApp is usually unlimited, I tried to create this library since I didn't find any usable at the date.Tunneling Internet traffic over Whatsapp https://github.com/aleixrodriala/wa-tunnel