xxxxxxxxxx
import std.stdio;
struct TcpSocket
{
int send(ubyte[] data, int len) { writeln("TcpSocket send"); return len; }
int recv(ubyte[] buff, int len) { writeln("TcpSocket recv"); return len; }
}
struct UdpSocket
{
int send(ubyte[] data, int len) { writeln("UdpSocket send"); return len; }
int recv(ubyte[] buff, int len) { writeln("UdpSocket recv"); return len; }
}
struct UnixSocket
{
int send(ubyte[] data, int len) { writeln("UdpSocket send"); return len; }
int recv(ubyte[] buff, int len) { writeln("UdpSocket recv"); return len; }
}
struct NotASocket { }
void Use(T)(T socket)
{
socket.send([], 0);
socket.recv([], 0);
}
void main()
{
TcpSocket socket;
socket.Use(); // Works out of the box without any interface boilerplate
NotASocket noSocket;
//noSocket.Use(); // Error: no property `send`/`recv` for type `NotASocket`
}