I'm creating a function to authenticate user login. I want to determine login failure (Boolean) and error message (will be sent to frontend) but D does have multiple return type (IMO could use struct but will make code dirty with too much custom types).

struct Result
{
    bool success = false
    string message;
}
Result authen(){}
auto r = authen()
if (r.success) writeln(r.message);



In such use case, would you use a callback delegates function or will use a string (str == "ok", str == "no") or go with a struct?

string authen(){}
string r = authen();
//check if string contains success message to take action.


Or
void authen(void delegate callback(bool success, string message) )
{
    //authenticate
    callback (resultBoolean, message);
}

//use
authen( (success, msg) {
   req.writeBody(msg); // to frontend
});

Reply via email to