Find out whether a C++ object is callable

I think this trait does what you want. It detects operator() with any kind of signature even if it’s overloaded and also if it’s templatized: template<typename T> struct is_callable { private: typedef char(&yes)[1]; typedef char(&no)[2]; struct Fallback { void operator()(); }; struct Derived : T, Fallback { }; template<typename U, U> struct Check; template<typename> static … Read more

How do closures infer their type based on the trait they’re required to implement?

It seems to be a glitch. The Rust-analyzer LSP is able to infer what the type is supposed to be, but for whatever reason the compiler can’t. From what I can tell, this code doesn’t compile on any version of Rust, and cannot be automatically fixed with cargo fix. Interestingly, the compiler does seem to … Read more

How to read (std::io::Read) from a Vec or Slice?

While vectors don’t support std::io::Read, slices do. There is some confusion here caused by Rust being able to coerce a Vec into a slice in some situations but not others. In this case, an explicit coercion to a slice is needed because at the stage coercions are applied, the compiler doesn’t know that Vec<u8> doesn’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)